Subtle whitespace changes in Java.stg reduces size of generated code without hurting legibility

This commit is contained in:
Sam Harwell 2012-10-28 17:16:37 -05:00
parent 25c5802ba4
commit 37425b70d0
1 changed files with 48 additions and 48 deletions

View File

@ -139,9 +139,9 @@ public class <parser.name> extends <superClass> {
<if(sempredFuncs)> <if(sempredFuncs)>
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch ( ruleIndex ) { switch (ruleIndex) {
<parser.sempredFuncs.values:{f| <parser.sempredFuncs.values:{f|
case <f.ruleIndex> : return <f.name>_sempred((<f.ctxType>)_localctx, predIndex);}; separator="\n"> case <f.ruleIndex>: return <f.name>_sempred((<f.ctxType>)_localctx, predIndex);}; separator="\n">
} }
return true; return true;
} }
@ -156,9 +156,9 @@ dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
<if(actionFuncs)> <if(actionFuncs)>
@Override @Override
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) { public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
switch ( ruleIndex ) { switch (ruleIndex) {
<recog.actionFuncs.values:{f| <recog.actionFuncs.values:{f|
case <f.ruleIndex> : <f.name>_action((<f.ctxType>)_localctx, actionIndex); break;}; separator="\n"> case <f.ruleIndex>: <f.name>_action((<f.ctxType>)_localctx, actionIndex); break;}; separator="\n">
} }
} }
<actionFuncs.values; separator="\n"> <actionFuncs.values; separator="\n">
@ -166,9 +166,9 @@ case <f.ruleIndex> : <f.name>_action((<f.ctxType>)_localctx, actionIndex); break
<if(sempredFuncs)> <if(sempredFuncs)>
@Override @Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch ( ruleIndex ) { switch (ruleIndex) {
<recog.sempredFuncs.values:{f| <recog.sempredFuncs.values:{f|
case <f.ruleIndex> : return <f.name>_sempred((<f.ctxType>)_localctx, predIndex);}; separator="\n"> case <f.ruleIndex>: return <f.name>_sempred((<f.ctxType>)_localctx, predIndex);}; separator="\n">
} }
return true; return true;
} }
@ -185,18 +185,18 @@ public <p.name>(TokenStream input) {
RuleActionFunction(r, actions) ::= << RuleActionFunction(r, actions) ::= <<
public void <r.name>_action(<r.ctxType> _localctx, int actionIndex) { public void <r.name>_action(<r.ctxType> _localctx, int actionIndex) {
switch ( actionIndex ) { switch (actionIndex) {
<actions:{index| <actions:{index|
case <index> : <actions.(index)> break;}; separator="\n"> case <index>: <actions.(index)> break;}; separator="\n">
} }
} }
>> >>
RuleSempredFunction(r, actions) ::= << RuleSempredFunction(r, actions) ::= <<
public boolean <r.name>_sempred(<r.ctxType> _localctx, int predIndex) { public boolean <r.name>_sempred(<r.ctxType> _localctx, int predIndex) {
switch ( predIndex ) { switch (predIndex) {
<actions:{index| <actions:{index|
case <index> : return <actions.(index)>;}; separator="\n"> case <index>: return <actions.(index)>;}; separator="\n">
} }
return true; return true;
} }
@ -290,35 +290,35 @@ CodeBlockForAlt(currentAltCodeBlock, locals, preamble, ops) ::= <<
LL1AltBlock(choice, preamble, alts, error) ::= << LL1AltBlock(choice, preamble, alts, error) ::= <<
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
//_errHandler.sync(this); <!_errHandler.sync(this);!>
<if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif> <if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif>
<preamble; separator="\n"> <preamble; separator="\n">
switch ( _input.LA(1) ) { switch (_input.LA(1)) {
<choice.altLook,alts:{look,alt| <cases(ttypes=look)> <choice.altLook,alts:{look,alt| <cases(ttypes=look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
default : default:
<error> <error>
} }
>> >>
LL1OptionalBlock(choice, alts, error) ::= << LL1OptionalBlock(choice, alts, error) ::= <<
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
//_errHandler.sync(this); <!_errHandler.sync(this);!>
switch ( _input.LA(1) ) { switch (_input.LA(1)) {
<choice.altLook,alts:{look,alt| <cases(ttypes=look)> <choice.altLook,alts:{look,alt| <cases(ttypes=look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
default : default:
<error> <error>
} }
>> >>
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= << LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= <<
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
//_errHandler.sync(this); <!_errHandler.sync(this);!>
<preamble; separator="\n"> <preamble; separator="\n">
if ( <expr> ) { if (<expr>) {
<alts; separator="\n"> <alts; separator="\n">
} }
<!else if ( !(<followExpr>) ) <error>!> <!else if ( !(<followExpr>) ) <error>!>
@ -329,12 +329,12 @@ setState(<choice.stateNumber>);
_errHandler.sync(this); _errHandler.sync(this);
<choice.loopLabel>: <choice.loopLabel>:
while (true) { while (true) {
switch ( _input.LA(1) ) { switch (_input.LA(1)) {
<choice.altLook,alts:{look,alt| <cases(look)> <choice.altLook,alts:{look,alt| <cases(look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
<cases(choice.exitLook)> <cases(choice.exitLook)>
break <choice.loopLabel>; break <choice.loopLabel>;
} }
setState(<choice.loopBackStateNumber>); setState(<choice.loopBackStateNumber>);
_errHandler.sync(this); _errHandler.sync(this);
@ -345,7 +345,7 @@ LL1StarBlockSingleAlt(choice, loopExpr, alts, preamble, iteration) ::= <<
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
_errHandler.sync(this); _errHandler.sync(this);
<preamble; separator="\n"> <preamble; separator="\n">
while ( <loopExpr> ) { while (<loopExpr>) {
<alts; separator="\n"> <alts; separator="\n">
setState(<choice.loopBackStateNumber>); setState(<choice.loopBackStateNumber>);
_errHandler.sync(this); _errHandler.sync(this);
@ -357,12 +357,12 @@ LL1PlusBlock(choice, alts, iteration, loopExpr, error) ::= <<
setState(<choice.blockStartStateNumber>); <! alt block decision !> setState(<choice.blockStartStateNumber>); <! alt block decision !>
_errHandler.sync(this); _errHandler.sync(this);
do { do {
switch ( _input.LA(1) ) { switch (_input.LA(1)) {
<choice.altLook,alts:{look,alt| <cases(look)> <choice.altLook,alts:{look,alt| <cases(look)>
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
default : default:
<error> <error>
} }
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
_errHandler.sync(this); _errHandler.sync(this);
@ -386,11 +386,11 @@ do {
AltBlock(choice, preamble, alts, error) ::= << AltBlock(choice, preamble, alts, error) ::= <<
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
//_errHandler.sync(this); <!_errHandler.sync(this);!>
<if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif> <if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif>
<preamble; separator="\n"> <preamble; separator="\n">
switch ( getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx) ) { switch ( getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx) ) {
<alts:{alt | <alts:{alt |
case <i>: case <i>:
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
@ -399,9 +399,9 @@ case <i>:
OptionalBlock(choice, alts, error) ::= << OptionalBlock(choice, alts, error) ::= <<
setState(<choice.stateNumber>); setState(<choice.stateNumber>);
//_errHandler.sync(this); <!_errHandler.sync(this);!>
switch ( getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx) ) { switch ( getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx) ) {
<alts:{alt | <alts:{alt |
case <i><if(!choice.ast.greedy)>+1<endif>: case <i><if(!choice.ast.greedy)>+1<endif>:
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
@ -428,13 +428,13 @@ setState(<choice.blockStartStateNumber>); <! alt block decision !>
_errHandler.sync(this); _errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx); _alt = getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx);
do { do {
switch ( _alt ) { switch (_alt) {
<alts:{alt| <alts:{alt|
case <i><if(!choice.ast.greedy)>+1<endif>: case <i><if(!choice.ast.greedy)>+1<endif>:
<alt> <alt>
break;}; separator="\n"> break;}; separator="\n">
default : default:
<error> <error>
} }
setState(<choice.loopBackStateNumber>); <! loopback/exit decision !> setState(<choice.loopBackStateNumber>); <! loopback/exit decision !>
_errHandler.sync(this); _errHandler.sync(this);
@ -760,9 +760,9 @@ public static final ATN _ATN =
ATNSimulator.deserialize(_serializedATN.toCharArray()); ATNSimulator.deserialize(_serializedATN.toCharArray());
static { static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
//org.antlr.v4.tool.DOTGenerator dot = new org.antlr.v4.tool.DOTGenerator(null); <! org.antlr.v4.tool.DOTGenerator dot = new org.antlr.v4.tool.DOTGenerator(null);!>
//System.out.println(dot.getDOT(_ATN.decisionToState.get(0), ruleNames, false)); <! System.out.println(dot.getDOT(_ATN.decisionToState.get(0), ruleNames, false));!>
//System.out.println(dot.getDOT(_ATN.ruleToStartState[2], ruleNames, false)); <! System.out.println(dot.getDOT(_ATN.ruleToStartState[2], ruleNames, false));!>
} }
>> >>