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:
parent
5a8a1c4974
commit
b3472021d6
@ -1141,26 +1141,29 @@ embedded_statement returns [bool isSemi, bool isBraces, bool isIf]
|
|||||||
StringTemplate someText = null;
|
StringTemplate someText = null;
|
||||||
$isBraces = false;
|
$isBraces = false;
|
||||||
$isIf = false;
|
$isIf = false;
|
||||||
|
List<String> preComments = null;
|
||||||
}:
|
}:
|
||||||
block { $isSemi = $block.isSemi; $isBraces = !$block.isSemi;} -> { $block.st }
|
block { $isSemi = $block.isSemi; $isBraces = !$block.isSemi;} -> { $block.st }
|
||||||
| ^(IF boolean_expression SEP t=embedded_statement e=else_statement?) { $isIf = true; }
|
| ^(IF boolean_expression { preComments = CollectedComments; } SEP t=embedded_statement e=else_statement?) { $isIf = true; }
|
||||||
-> if(cond= { $boolean_expression.st },
|
-> if_template(comments = { preComments }, cond= { $boolean_expression.st },
|
||||||
then = { $t.st }, thensemi = { $t.isSemi }, thenbraces = { $t.isBraces },
|
then = { $t.st }, thensemi = { $t.isSemi }, thenbraces = { $t.isBraces },
|
||||||
else = { $e.st }, elsesemi = { $e.isSemi }, elsebraces = { $e.isBraces }, elseisif = { $e.isIf })
|
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
|
| iteration_statement -> { $iteration_statement.st } // while, do, for, foreach
|
||||||
| jump_statement -> { $jump_statement.st } // break, continue, goto, return, throw
|
| 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 },
|
| ^('try' { preComments = CollectedComments; } b=block catch_clauses? finally_clause?)
|
||||||
catches = { $catch_clauses.st }, fin = { $finally_clause.st } )
|
-> try(comments = { preComments }, block = {$b.st}, blocksemi = {$b.isSemi}, blockbraces = { !$b.isSemi },
|
||||||
|
catches = { $catch_clauses.st }, fin = { $finally_clause.st } )
|
||||||
| checked_statement
|
| checked_statement
|
||||||
| unchecked_statement
|
| unchecked_statement
|
||||||
| lock_statement -> { $lock_statement.st }
|
| lock_statement -> { $lock_statement.st }
|
||||||
| using_statement
|
| using_statement
|
||||||
| yield_statement
|
| yield_statement
|
||||||
| ^('unsafe' block { someText = %op(); %{someText}.op="unsafe"; %{someText}.post = $block.st; })
|
| ^('unsafe' { preComments = CollectedComments; } block { someText = %op(); %{someText}.op="unsafe"; %{someText}.post = $block.st; })
|
||||||
-> unsupported(reason = {"unsafe blocks are not supported"}, text = { someText } )
|
-> unsupported(comments = { preComments }, reason = {"unsafe blocks are not supported"}, text = { someText } )
|
||||||
| fixed_statement
|
| 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_statement:
|
||||||
'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ;
|
'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ;
|
||||||
@ -1173,9 +1176,12 @@ fixed_pointer_initializer:
|
|||||||
expression;
|
expression;
|
||||||
labeled_statement:
|
labeled_statement:
|
||||||
identifier ':' statement ;
|
identifier ':' statement ;
|
||||||
declaration_statement:
|
declaration_statement
|
||||||
(local_variable_declaration -> op(pre = { $local_variable_declaration.st }, op = { ";" })
|
@init {
|
||||||
| local_constant_declaration -> op(pre = { $local_constant_declaration.st }, op = { ";" }) ) ';' ;
|
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_declaration:
|
||||||
local_variable_type local_variable_declarators -> local_variable_declaration(type={ $local_variable_type.st }, decs = { $local_variable_declarators.st } );
|
local_variable_type local_variable_declarators -> local_variable_declaration(type={ $local_variable_type.st }, decs = { $local_variable_declarators.st } );
|
||||||
local_variable_type:
|
local_variable_type:
|
||||||
|
@ -121,7 +121,8 @@ extends(types) ::= "<if(types)>extends <types; separator=\",\"><endif>"
|
|||||||
imps(types) ::= "<if(types)>implements <types; separator=\",\"><endif>"
|
imps(types) ::= "<if(types)>implements <types; separator=\",\"><endif>"
|
||||||
|
|
||||||
// ******* STATEMENTS *******
|
// ******* 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>)
|
if (<cond>)
|
||||||
<block(statements = then, issemi = thensemi, isbraces = thenbraces)>
|
<block(statements = then, issemi = thensemi, isbraces = thenbraces)>
|
||||||
<if(else)>
|
<if(else)>
|
||||||
@ -132,22 +133,26 @@ else<if(elseisif)> <block(statements = else, issemi = elsesemi, isbraces = elseb
|
|||||||
<endif>
|
<endif>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
while(cond,block,blocksemi, blockbraces) ::= <<
|
while(comments,cond,block,blocksemi, blockbraces) ::= <<
|
||||||
|
<comments; separator="\n">
|
||||||
while (<cond>)
|
while (<cond>)
|
||||||
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
<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>)
|
for (<init>;<cond>;<iter>)
|
||||||
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
<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>)
|
for (<type> <loopid> : <fromexp>)
|
||||||
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
try(block,blocksemi, blockbraces, catches, fin) ::= <<
|
try(comments,block,blocksemi, blockbraces, catches, fin) ::= <<
|
||||||
|
<comments; separator="\n">
|
||||||
try
|
try
|
||||||
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
||||||
<catches>
|
<catches>
|
||||||
@ -165,7 +170,8 @@ finally
|
|||||||
>>
|
>>
|
||||||
|
|
||||||
|
|
||||||
switch(scrutinee, sections) ::= <<
|
switch(comments,scrutinee, sections) ::= <<
|
||||||
|
<comments; separator="\n">
|
||||||
switch(<scrutinee>)
|
switch(<scrutinee>)
|
||||||
<sections>
|
<sections>
|
||||||
>>
|
>>
|
||||||
@ -184,7 +190,8 @@ default_template() ::= <<
|
|||||||
default:
|
default:
|
||||||
>>
|
>>
|
||||||
|
|
||||||
lock(exp,block,blocksemi, blockbraces) ::= <<
|
lock(comments,exp,block,blocksemi, blockbraces) ::= <<
|
||||||
|
<comments; separator="\n">
|
||||||
lock(<exp>)
|
lock(<exp>)
|
||||||
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
<block(statements = block, issemi = blocksemi, isbraces = blockbraces)>
|
||||||
>>
|
>>
|
||||||
@ -221,7 +228,10 @@ void() ::= "void"
|
|||||||
optparens(parens, e) ::= "<if(parens)>(<endif><e><if(parens)>)<endif>"
|
optparens(parens, e) ::= "<if(parens)>(<endif><e><if(parens)>)<endif>"
|
||||||
parens(e) ::= "(<e>)"
|
parens(e) ::= "(<e>)"
|
||||||
rank_specifiers(rs) ::= "<rs>"
|
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>"
|
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>\>"
|
generic_args(args) ::= "\<<args>\>"
|
||||||
parameter(annotation,param) ::= "/* <annotation> */ <param>"
|
parameter(annotation,param) ::= "/* <annotation> */ <param>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user