1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

Shovel out comments in more places

This commit is contained in:
Kevin Glynn 2010-12-10 18:57:37 +01:00
parent 5a8a1c4974
commit b3472021d6
2 changed files with 35 additions and 19 deletions

View File

@ -1141,26 +1141,29 @@ embedded_statement returns [bool isSemi, bool isBraces, bool isIf]
StringTemplate someText = null;
$isBraces = false;
$isIf = false;
List<String> preComments = null;
}:
block { $isSemi = $block.isSemi; $isBraces = !$block.isSemi;} -> { $block.st }
| ^(IF boolean_expression SEP t=embedded_statement e=else_statement?) { $isIf = true; }
-> if(cond= { $boolean_expression.st },
| ^(IF boolean_expression { preComments = CollectedComments; } SEP t=embedded_statement e=else_statement?) { $isIf = true; }
-> if_template(comments = { preComments }, cond= { $boolean_expression.st },
then = { $t.st }, thensemi = { $t.isSemi }, thenbraces = { $t.isBraces },
else = { $e.st }, elsesemi = { $e.isSemi }, elsebraces = { $e.isBraces }, elseisif = { $e.isIf })
| ^('switch' expression s+=switch_section*) -> switch(scrutinee = { $expression.st }, sections = { $s })
| ^('switch' expression { preComments = CollectedComments; } s+=switch_section*) -> switch(comments = { preComments }, scrutinee = { $expression.st }, sections = { $s })
| iteration_statement -> { $iteration_statement.st } // while, do, for, foreach
| jump_statement -> { $jump_statement.st } // break, continue, goto, return, throw
| ^('try' b=block catch_clauses? finally_clause?) -> try(block = {$b.st}, blocksemi = {$b.isSemi}, blockbraces = { !$b.isSemi },
catches = { $catch_clauses.st }, fin = { $finally_clause.st } )
| ^('try' { preComments = CollectedComments; } b=block catch_clauses? finally_clause?)
-> try(comments = { preComments }, block = {$b.st}, blocksemi = {$b.isSemi}, blockbraces = { !$b.isSemi },
catches = { $catch_clauses.st }, fin = { $finally_clause.st } )
| checked_statement
| unchecked_statement
| lock_statement -> { $lock_statement.st }
| using_statement
| yield_statement
| ^('unsafe' block { someText = %op(); %{someText}.op="unsafe"; %{someText}.post = $block.st; })
-> unsupported(reason = {"unsafe blocks are not supported"}, text = { someText } )
| ^('unsafe' { preComments = CollectedComments; } block { someText = %op(); %{someText}.op="unsafe"; %{someText}.post = $block.st; })
-> unsupported(comments = { preComments }, reason = {"unsafe blocks are not supported"}, text = { someText } )
| fixed_statement
| expression_statement -> op( pre={ $expression_statement.st }, op={ ";" }) // make an expression a statement, need to terminate with semi
| expression_statement { preComments = CollectedComments; }
-> op(comments = { preComments }, pre={ $expression_statement.st }, op={ ";" }) // make an expression a statement, need to terminate with semi
;
fixed_statement:
'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ;
@ -1173,9 +1176,12 @@ fixed_pointer_initializer:
expression;
labeled_statement:
identifier ':' statement ;
declaration_statement:
(local_variable_declaration -> op(pre = { $local_variable_declaration.st }, op = { ";" })
| local_constant_declaration -> op(pre = { $local_constant_declaration.st }, op = { ";" }) ) ';' ;
declaration_statement
@init {
List<String> preComments = null;
}:
(local_variable_declaration { preComments = CollectedComments; } -> op(comments = { preComments }, pre = { $local_variable_declaration.st }, op = { ";" })
| local_constant_declaration { preComments = CollectedComments; } -> op(comments = { preComments }, pre = { $local_constant_declaration.st }, op = { ";" }) ) ';' ;
local_variable_declaration:
local_variable_type local_variable_declarators -> local_variable_declaration(type={ $local_variable_type.st }, decs = { $local_variable_declarators.st } );
local_variable_type:

View File

@ -121,7 +121,8 @@ extends(types) ::= "<if(types)>extends <types; separator=\",\"><endif>"
imps(types) ::= "<if(types)>implements <types; separator=\",\"><endif>"
// ******* STATEMENTS *******
if(cond,then,thensemi, thenbraces,else, elseisif, elsesemi,elsebraces) ::= <<
if_template(comments, cond,then,thensemi, thenbraces,else, elseisif, elsesemi,elsebraces) ::= <<
<comments; separator="\n">
if (<cond>)
<block(statements = then, issemi = thensemi, isbraces = thenbraces)>
<if(else)>
@ -132,22 +133,26 @@ else<if(elseisif)> <block(statements = else, issemi = elsesemi, isbraces = elseb
<endif>
>>
while(cond,block,blocksemi, blockbraces) ::= <<
while(comments,cond,block,blocksemi, blockbraces) ::= <<
<comments; separator="\n">
while (<cond>)
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
>>
for(init,cond,iter,block,blocksemi, blockbraces) ::= <<
for(comments,init,cond,iter,block,blocksemi, blockbraces) ::= <<
<comments; separator="\n">
for (<init>;<cond>;<iter>)
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
>>
foreach(type,loopid,fromexp,block,blocksemi, blockbraces) ::= <<
foreach(comments,type,loopid,fromexp,block,blocksemi, blockbraces) ::= <<
<comments; separator="\n">
for (<type> <loopid> : <fromexp>)
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
>>
try(block,blocksemi, blockbraces, catches, fin) ::= <<
try(comments,block,blocksemi, blockbraces, catches, fin) ::= <<
<comments; separator="\n">
try
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
<catches>
@ -165,7 +170,8 @@ finally
>>
switch(scrutinee, sections) ::= <<
switch(comments,scrutinee, sections) ::= <<
<comments; separator="\n">
switch(<scrutinee>)
<sections>
>>
@ -184,7 +190,8 @@ default_template() ::= <<
default:
>>
lock(exp,block,blocksemi, blockbraces) ::= <<
lock(comments,exp,block,blocksemi, blockbraces) ::= <<
<comments; separator="\n">
lock(<exp>)
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
>>
@ -221,7 +228,10 @@ void() ::= "void"
optparens(parens, e) ::= "<if(parens)>(<endif><e><if(parens)>)<endif>"
parens(e) ::= "(<e>)"
rank_specifiers(rs) ::= "<rs>"
op(pre,op,post,mkparen,space) ::= "<if(mkparen)>(<endif><if(pre)><pre><space><endif><op><if(post)><space><post><endif><if(mkparen)>)<endif>"
op(comments,pre,op,post,mkparen,space) ::= <<
<comments; separator="\n">
<if(mkparen)>(<endif><if(pre)><pre><space><endif><op><if(post)><space><post><endif><if(mkparen)>)<endif>
>>
assign(lhs,lhsparen,assign,rhs,rhsparen) ::= "<if(lhsparen)>(<endif><lhs><if(lhsparen)>)<endif> <assign> <if(rhsparen)>(<endif><rhs><if(rhsparen)>)<endif>"
generic_args(args) ::= "\<<args>\>"
parameter(annotation,param) ::= "/* <annotation> */ <param>"