[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-indent] [PATCH] Patch to handle LPC data types.
From: |
Vallimar |
Subject: |
[Bug-indent] [PATCH] Patch to handle LPC data types. |
Date: |
Sat, 27 Apr 2002 03:20:33 -0400 (EDT) |
Hello!
I wasn't sure where to send this, and this is the only email address
I saw on the various websites relating to indent, so I'll try sending
my patch here.
Basically, LPC is the programming language used within LPMuds and they
have a couple different data types. The array and mapping data structures
are much different then they are in regular C or C++ so indent has a
horrible tendency to destroy them rather then beautify them. I believe
Pike uses the same structures for these internal data types as it was
evolved from LPC itself, although I haven't tested it on any Pike code.
From my tests, the patch seems to keep these structures intact and
doesn't appear to introduce any undesirable effects.
The options added are: -lpc, -nlpc, --lpc-types, --no-lpc-types. I have
also updated the indent.texinfo document to display the options and point
them to the Miscellaneous section with a brief explanation of what they
do. I realize this patch is of little use to the vast majority of users
of indent, but I figured I'd send it in anyhow just in case.
Sincerely,
Troy Edwards
===============================================================================
Patch is as follows, it has also been attached.
===============================================================================
diff -ru indent-2.2.8/doc/indent.info indent-2.2.8-lpc/doc/indent.info
--- indent-2.2.8/doc/indent.info Thu Mar 21 15:44:14 2002
+++ indent-2.2.8-lpc/doc/indent.info Sat Apr 27 02:31:12 2002
@@ -1,4 +1,4 @@
-This is indent.info, produced by makeinfo version 4.0 from
+This is indent.info, produced by makeinfo version 4.1 from
indent.texinfo.
INFO-DIR-SECTION Indent Code Formatter
@@ -906,6 +906,12 @@
project won't cause `make' to rebuild all targets. This option is only
available on Operating Systems that have the POSIX `utime(2)' function.
+ The `-lpc' option causes `indent' to handle the LPC array ({ }) and
+mapping ([ ]) data types to be handled differently. They won't be
+broken up as they would under C or C++ code. LPC is primarily used on
+LPMuds and their variants. It's possible this will work with Pike
+files (.pike) as well, but has not been tested.
+
File: indent.info, Node: Bugs, Next: Copyright, Prev: Miscellaneous
options, Up: Indent Program
@@ -1164,6 +1170,11 @@
Leave space between `#' and preprocessor directive.
*Note Indentation::.
+`-lpc'
+`--lpc-types'
+ Handle LPC array and mapping types more correctly.
+ *Note Miscellaneous options::.
+
`-nbad'
`--no-blank-lines-after-declarations'
Do not force blank lines after declarations.
@@ -1442,13 +1453,14 @@
--leave-preprocessor-space -lps
--line-comments-indentation -dN
--line-length -lN
+ --lpc-types -lpc
--no-blank-lines-after-commas -nbc
--no-blank-lines-after-declarations -nbad
--no-blank-lines-after-procedures -nbap
--no-blank-lines-before-block-comments -nbbb
--no-comment-delimiters-on-blank-lines -ncdb
- --no-space-after-casts -ncs
--no-parameter-indentation -nip
+ --no-space-after-casts -ncs
--no-space-after-for -nsaf
--no-space-after-function-call-names -npcs
--no-space-after-if -nsai
@@ -1527,11 +1539,13 @@
* --leave-preprocessor-space: Indentation.
* --line-comments-indentationN: Comments.
* --line-lengthN: Breaking long lines.
+* --lpc-types: Miscellaneous options.
* --no-blank-lines-after-commas: Declarations.
* --no-blank-lines-after-declarations: -bad.
* --no-blank-lines-after-procedures: -bap.
* --no-blank-lines-before-block-comments: Blank lines.
* --no-comment-delimiters-on-blank-lines: Comments.
+* --no-lpc-types: Miscellaneous options.
* --no-parameter-indentation: Indentation.
* --no-space-after-casts: Statements.
* --no-space-after-for: Statements.
@@ -1589,6 +1603,7 @@
* -kr: Common styles.
* -lN: Breaking long lines.
* -lp: Indentation.
+* -lpc: Miscellaneous options.
* -lps: Indentation.
* -nbad: -bad.
* -nbap: -bap.
@@ -1604,6 +1619,7 @@
* -nhnl: Breaking long lines.
* -nip: Indentation.
* -nlp: Indentation.
+* -nlpc: Miscellaneous options.
* -nlps: Indentation.
* -npcs: Statements.
* -npmt: Miscellaneous options.
@@ -1672,9 +1688,9 @@
Node: Breaking long lines26320
Node: Disabling Formatting28601
Node: Miscellaneous options30348
-Node: Bugs31241
-Node: Copyright32705
-Node: Option Summary34287
-Node: Index47886
+Node: Bugs31566
+Node: Copyright33030
+Node: Option Summary34612
+Node: Index48383
End Tag Table
diff -ru indent-2.2.8/doc/indent.texinfo indent-2.2.8-lpc/doc/indent.texinfo
--- indent-2.2.8/doc/indent.texinfo Thu Mar 21 15:25:11 2002
+++ indent-2.2.8-lpc/doc/indent.texinfo Sat Apr 27 02:31:08 2002
@@ -1350,6 +1350,16 @@
This option is only available on Operating Systems that have the
POSIX @code{utime(2)} function.
address@hidden -lpc
address@hidden --lpc-types
address@hidden -nlpc
address@hidden --no-lpc-types
+The @option{-lpc} option causes @command{indent} to handle the LPC
+array (@{ @}) and mapping ([ ]) data types to be handled differently.
+They won't be broken up as they would under C or C++ code. LPC is
+primarily used on LPMuds and their variants. It's possible this
+will work with Pike files (.pike) as well, but has not been tested.
+
@node Bugs, Copyright, Miscellaneous options, Indent Program
@comment node-name, next, previous, up
@section Bugs
@@ -1609,6 +1619,11 @@
Leave space between @samp{#} and preprocessor address@hidden
@xref{Indentation}.
address@hidden -lpc
address@hidden --lpc-types
+Handle LPC array and mapping types more address@hidden
address@hidden options}.
+
@item -nbad
@itemx --no-blank-lines-after-declarations
Do not force blank lines after address@hidden
@@ -1902,6 +1917,7 @@
\line{ --leave-optional-blank-lines \leaderfill -nsob}
\line{ --line-comments-indentation \leaderfill address@hidden \ }
\line{ --leave-preprocessor-space \leaderfill -lps\ }
+\line{ --lpc-types \leaderfill -lpc\ }
\line{ --line-length \leaderfill address@hidden \ }
\line{ --no-blank-lines-after-commas \leaderfill -nbc\ }
\line{ --no-blank-lines-after-declarations \leaderfill -nbad}
@@ -1985,13 +2001,14 @@
--leave-preprocessor-space -lps
--line-comments-indentation address@hidden
--line-length address@hidden
+--lpc-types -lpc
--no-blank-lines-after-commas -nbc
--no-blank-lines-after-declarations -nbad
--no-blank-lines-after-procedures -nbap
--no-blank-lines-before-block-comments -nbbb
--no-comment-delimiters-on-blank-lines -ncdb
---no-space-after-casts -ncs
--no-parameter-indentation -nip
+--no-space-after-casts -ncs
--no-space-after-for -nsaf
--no-space-after-function-call-names -npcs
--no-space-after-if -nsai
diff -ru indent-2.2.8/man/indent.1 indent-2.2.8-lpc/man/indent.1
--- indent-2.2.8/man/indent.1 Thu Mar 21 15:44:17 2002
+++ indent-2.2.8-lpc/man/indent.1 Sat Apr 27 02:37:52 2002
@@ -205,6 +205,11 @@
.br
See \fB\ INDENTATION\fR.
.TP
+.B -lpc\fR, \fB--lpc-types\fR
+Handle LPC array and mapping types more correctly.
+.br
+See \fB\ MISCELLANEOUS\ OPTIONS\fR.
+.TP
.B -nbad\fR, \fB--no-blank-lines-after-declarations\fR
Do not force blank lines after declarations.
.br
@@ -1492,6 +1497,12 @@
This option is only available on Operating Systems that have the
POSIX \fButime(2)\fR function.
+The \`-lpc\' option causes \fBindent\fR to handle the LPC
+array ({ }) and mapping ([ ]) data types to be handled differently.
+They won\'t be broken up as they would under C or C++ code. LPC is
+primarily used on LPMuds and their variants. It\'s possible this
+will work with Pike files (.pike) as well, but has not been tested.
+
.SH "BUGS"
Please report any bugs to address@hidden
@@ -1612,13 +1623,14 @@
--leave-preprocessor-space -lps
--line-comments-indentation -d\fIn\fR
--line-length -l\fIn\fR
+--lpc-types -lpc
--no-blank-lines-after-commas -nbc
--no-blank-lines-after-declarations -nbad
--no-blank-lines-after-procedures -nbap
--no-blank-lines-before-block-comments -nbbb
--no-comment-delimiters-on-blank-lines -ncdb
---no-space-after-casts -ncs
--no-parameter-indentation -nip
+--no-space-after-casts -ncs
--no-space-after-for -nsaf
--no-space-after-function-call-names -npcs
--no-space-after-if -nsai
diff -ru indent-2.2.8/src/args.c indent-2.2.8-lpc/src/args.c
--- indent-2.2.8/src/args.c Fri Mar 15 02:48:45 2002
+++ indent-2.2.8-lpc/src/args.c Sat Apr 27 00:54:25 2002
@@ -117,6 +117,7 @@
static int exp_l = 0;
static int exp_lc = 0;
static int exp_lp = 0;
+static int exp_lpc = 0;
static int exp_lps = 0;
static int exp_nip = 0;
static int exp_o = 0;
@@ -219,6 +220,7 @@
#endif
{"npcs", PRO_BOOL, false, OFF,
&settings.proc_calls_space, &exp_pcs},
{"nlps", PRO_BOOL, false, OFF,
&settings.leave_preproc_space, &exp_lps},
+ {"nlpc", PRO_BOOL, false, OFF,
&settings.lpc_types, &exp_lpc},
{"nlp", PRO_BOOL, true, OFF,
&settings.lineup_to_parens, &exp_lp},
{"nip", PRO_SETTINGS, 0, ONOFF_NA, (int *)
"-ip0", &exp_nip},
{"nhnl", PRO_BOOL, true, OFF,
&settings.honour_newlines, &exp_hnl},
@@ -240,6 +242,7 @@
{"nbad", PRO_BOOL, false, OFF,
&settings.blanklines_after_declarations, &exp_bad},
{"nbacc", PRO_BOOL, false, OFF,
&settings.blanklines_around_conditional_compilation, &exp_bacc},
{"lps", PRO_BOOL, false, ON,
&settings.leave_preproc_space, &exp_lps},
+ {"lpc", PRO_BOOL, false, ON,
&settings.lpc_types, &exp_lpc},
{"lp", PRO_BOOL, true, ON,
&settings.lineup_to_parens, &exp_lp},
{"lc", PRO_INT, DEFAULT_RIGHT_COMMENT_MARGIN, ONOFF_NA,
&settings.comment_max_col, &exp_lc},
{"l", PRO_INT, DEFAULT_RIGHT_MARGIN, ONOFF_NA,
&settings.max_col, &exp_l},
@@ -327,6 +330,7 @@
#endif
{"npcs", PRO_BOOL, true, OFF,
&settings.proc_calls_space, &exp_pcs},
{"nlps", PRO_BOOL, false, OFF,
&settings.leave_preproc_space, &exp_lps},
+ {"nlpc", PRO_BOOL, false, OFF,
&settings.lpc_types, &exp_lpc},
{"nlp", PRO_BOOL, true, OFF,
&settings.lineup_to_parens, &exp_lp},
{"nip", PRO_SETTINGS, 0, ONOFF_NA, (int *)
"-ip0\0", &exp_nip},
{"nhnl", PRO_BOOL, true, OFF,
&settings.honour_newlines, &exp_hnl},
@@ -348,6 +352,7 @@
{"nbad", PRO_BOOL, false, OFF,
&settings.blanklines_after_declarations, &exp_bad},
{"nbacc", PRO_BOOL, false, OFF,
&settings.blanklines_around_conditional_compilation, &exp_bacc},
{"lps", PRO_BOOL, false, ON,
&settings.leave_preproc_space, &exp_lps},
+ {"lpc", PRO_BOOL, false, ON,
&settings.lpc_types, &exp_lpc},
{"lp", PRO_BOOL, true, ON,
&settings.lineup_to_parens, &exp_lp},
{"lc", PRO_INT, DEFAULT_RIGHT_COMMENT_MARGIN, ONOFF_NA,
&settings.comment_max_col, &exp_lc},
{"l", PRO_INT, DEFAULT_RIGHT_MARGIN, ONOFF_NA,
&settings.max_col, &exp_l},
@@ -440,6 +445,7 @@
{"no-space-after-for", "nsaf"},
{"no-space-after-casts", "ncs"},
{"no-parameter-indentation", "nip"},
+ {"no-lpc-types", "nlpc"},
{"no-extra-expression-indentation", "neei"},
{"no-comment-delimiters-on-blank-lines", "ncdb"},
{"no-blank-lines-before-block-comments", "nbbb"},
@@ -450,6 +456,7 @@
{"no-blank-lines-after-commas", "nbc"},
{"no-blank-before-sizeof", "nbs"},
{"no-Bill-Shannon", "nbs"},
+ {"lpc-types", "lpc"},
{"line-length", "l"},
{"line-comments-indentation", "d"},
{"left-justify-declarations", "dj"},
diff -ru indent-2.2.8/src/indent.c indent-2.2.8-lpc/src/indent.c
--- indent-2.2.8/src/indent.c Fri Mar 15 02:48:45 2002
+++ indent-2.2.8-lpc/src/indent.c Sat Apr 27 02:12:12 2002
@@ -242,7 +242,9 @@
if (settings.decl_com_ind <= 0) /* if not specified by user, set this
*/
{
- settings.decl_com_ind = settings.ljust_decl ? (settings.com_ind <= 10
? 2 : settings.com_ind - 8) : settings.com_ind;
+ settings.decl_com_ind = settings.ljust_decl ?
+ (settings.com_ind <= 10 ? 2 : settings.com_ind - 8) :
+ settings.com_ind;
}
if (settings.continuation_indent == 0)
@@ -1075,11 +1077,13 @@
goto copy_id;
case colon: /* got a ':' */
- if (squest > 0)
+ if (squest > 0 || parser_state_tos->lpc_type)
{
/* it is part of the <c> ? <n> : <n> construct */
- --squest;
+ if (!parser_state_tos->lpc_type)
+ --squest;
+
if (parser_state_tos->want_blank)
{
set_buf_break (bb_colon);
@@ -1174,7 +1178,7 @@
force_nl = parser_state_tos->pcase = scase;
scase = false;
- parser_state_tos->want_blank = false;
+ parser_state_tos->want_blank = false;
break;
/* Deal with C++ Class::Method */
diff -ru indent-2.2.8/src/indent.h indent-2.2.8-lpc/src/indent.h
--- indent-2.2.8/src/indent.h Fri Mar 15 02:48:46 2002
+++ indent-2.2.8-lpc/src/indent.h Sat Apr 27 01:45:35 2002
@@ -246,6 +246,8 @@
int brace_indent; /* number of spaces to indent braces from the suround
if, while, etc. in -bl
* (bype_2 == 0) code */
int expect_output_file; /* Means "-o" was specified. */
+ int lpc_types; /* Break up LPC types differently
+ * ([ mappings ]), ({ arrays }) */
} user_options_ty;
extern user_options_ty settings;
@@ -404,6 +406,8 @@
int matching_brace_on_same_line; /* Set to a value >= 0 if the the
current '}' has a matching '{'
on the same input line */
+ int lpc_type; /* Check if we are in an lpc datatype
+ * currently only used to track mappings. */
} parser_state_ty;
/* All manipulations of the parser state occur at the top of stack (tos). A
diff -ru indent-2.2.8/src/lexi.c indent-2.2.8-lpc/src/lexi.c
--- indent-2.2.8/src/lexi.c Mon Mar 4 15:31:30 2002
+++ indent-2.2.8-lpc/src/lexi.c Sat Apr 27 01:54:41 2002
@@ -551,7 +551,8 @@
* the correct behaviour.
*/
- if (parser_state_tos->last_token == ident &&
parser_state_tos->last_saw_nl)
+ if (parser_state_tos->last_token == ident &&
+ parser_state_tos->last_saw_nl)
{
parser_state_tos->in_decl = 1;
}
@@ -783,6 +784,16 @@
break;
case ('('):
+ if ((*buf_ptr == '{' || *buf_ptr == '[') && settings.lpc_types)
+ {
+ if (*buf_ptr == '[')
+ parser_state_tos->lpc_type++;
+
+ buf_ptr++;
+ token_end = buf_ptr;
+ code = ident;
+ break;
+ }
l_enum = false;
unary_delim = true;
code = lparen;
@@ -801,6 +812,17 @@
break;
case (']'):
+ if (*buf_ptr == ')' &&
+ settings.lpc_types &&
+ parser_state_tos->lpc_type)
+ {
+ buf_ptr++;
+ token_end = buf_ptr;
+ parser_state_tos->lpc_type--;
+ code = ident;
+ break;
+ }
+
if (parser_state_tos->in_or_st > 1)
parser_state_tos->in_or_st--;
code = rparen;
@@ -829,6 +851,7 @@
break;
case (':'):
+
/* Deal with C++ class::method */
if (*buf_ptr == ':')
@@ -853,6 +876,10 @@
parser_state_tos->want_blank = true;
}
}
+
+ if (settings.lpc_types && parser_state_tos->lpc_type)
+ parser_state_tos->want_blank = true;
+
break;
case (';'):
@@ -893,6 +920,13 @@
break;
case ('}'):
+ if (*buf_ptr == ')' && settings.lpc_types)
+ {
+ buf_ptr++;
+ token_end = buf_ptr;
+ code = ident;
+ break;
+ }
parser_state_tos->matching_brace_on_same_line--;
l_enum = false;
unary_delim = true;
diff -ru indent-2.2.8/src/parse.c indent-2.2.8-lpc/src/parse.c
--- indent-2.2.8/src/parse.c Mon Mar 4 15:31:30 2002
+++ indent-2.2.8-lpc/src/parse.c Sat Apr 27 01:27:34 2002
@@ -102,6 +102,7 @@
parser_state_tos->dec_nest = 0;
parser_state_tos->can_break = bb_none;
parser_state_tos->saw_double_colon = false;
+ parser_state_tos->lpc_type = false;
parser_state_tos->il[0] = 0;
parser_state_tos->cstk[0] = 0;
indent-lpc.patch
Description: Text document
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-indent] [PATCH] Patch to handle LPC data types.,
Vallimar <=