diff options
author | Claude Brisson <cbrisson@apache.org> | 2016-09-06 16:17:12 +0000 |
---|---|---|
committer | Claude Brisson <cbrisson@apache.org> | 2016-09-06 16:17:12 +0000 |
commit | 701d956e8a20853106c5bc284df70f0e441b0e43 (patch) | |
tree | 3dd3921101bc148dd4bcb016b3a027766d125833 /velocity-engine-core/src | |
parent | 28a5df1fd9329d8a635b1c9f7fff3566e2f6d670 (diff) | |
download | apache-velocity-engine-701d956e8a20853106c5bc284df70f0e441b0e43.tar.gz |
some more indentation bugfixes and testcases
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1759453 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src')
17 files changed, 222 insertions, 20 deletions
diff --git a/velocity-engine-core/src/main/parser/Parser.jjt b/velocity-engine-core/src/main/parser/Parser.jjt index 1ba8be8c..809e885e 100644 --- a/velocity-engine-core/src/main/parser/Parser.jjt +++ b/velocity-engine-core/src/main/parser/Parser.jjt @@ -679,7 +679,7 @@ TOKEN: * http://www.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq-ie.htm#tth_sEc3.12 * */ -<DEFAULT, REFERENCE, REFMODIFIER, REFMOD2> +<DEFAULT, PRE_REFERENCE, REFERENCE, REFMODIFIER, REFMOD2> TOKEN: { <SET_DIRECTIVE: ("#set" | "#{set}") (" "|"\t")* "("> @@ -725,11 +725,11 @@ MORE : if (! inComment) { /* - * if we find ourselves in REFERENCE, we need to pop down + * if we find ourselves in REFERENCE or PRE_REFERENCE, we need to pop down * to end the previous ref */ - if (curLexState == REFERENCE) + if (curLexState == REFERENCE || curLexState == PRE_REFERENCE) { inReference = false; stateStackPop(); @@ -738,10 +738,10 @@ MORE : inReference = true; if ( debugPrint ) - System.out.print( "$ : going to " + REFERENCE ); + System.out.print( "$ : going to " + PRE_REFERENCE ); stateStackPush(); - SwitchTo(REFERENCE); + SwitchTo(PRE_REFERENCE); } } @@ -750,11 +750,11 @@ MORE : if (! inComment) { /* - * if we find ourselves in REFERENCE, we need to pop down + * if we find ourselves in REFERENCE or PRE_REFERENCE, we need to pop down * to end the previous ref */ - if (curLexState == REFERENCE) + if (curLexState == REFERENCE || curLexState == PRE_REFERENCE) { inReference = false; stateStackPop(); @@ -763,10 +763,10 @@ MORE : inReference = true; if ( debugPrint ) - System.out.print( "$! : going to " + REFERENCE ); + System.out.print( "$! : going to " + PRE_REFERENCE ); stateStackPush(); - SwitchTo(REFERENCE); + SwitchTo(PRE_REFERENCE); } } @@ -812,7 +812,7 @@ MORE : * you are going into DIRECTIVE while in REFERENCE. -gmj */ - if (curLexState == REFERENCE || curLexState == REFMODIFIER ) + if (curLexState == REFERENCE || curLexState == PRE_REFERENCE || curLexState == REFMODIFIER ) { inReference = false; stateStackPop(); @@ -824,19 +824,19 @@ MORE : stateStackPush(); SwitchTo(PRE_DIRECTIVE); } - } + } } // treat the single line comment case separately // to avoid ##<EOF> errors -<DEFAULT,PRE_DIRECTIVE,DIRECTIVE,REFERENCE> +<DEFAULT,PRE_DIRECTIVE,DIRECTIVE,REFERENCE,PRE_REFERENCE> TOKEN : { <SINGLE_LINE_COMMENT_START: "##"> { if (!inComment) { - if (curLexState == REFERENCE) + if (curLexState == REFERENCE || curLexState == PRE_REFERENCE) { inReference = false; stateStackPop(); @@ -929,6 +929,19 @@ TOKEN: } } +/* needed for stuff like #foo() followed by ( '$' | '#' )* followed by ( <WHITESPACE> | <ENDLINE> ) + so that directive postfix doesn't eat the '$'s and '#'s +*/ +<PRE_DIRECTIVE, PRE_REFERENCE> +TOKEN: +{ + <SUFFIX: ([" ","\t"])* ("\n" | "\r" | "\r\n")> + { + inReference = false; + stateStackPop(); + } +} + <DIRECTIVE,REFMOD2,REFINDEX> TOKEN : { @@ -1105,9 +1118,11 @@ TOKEN: * for each state can be different. * * $foo.bar( "arg" ) - * ^ ^ ^ ^ - * | | | | - * |_________________ > REFERENCE : state initiated by the '$' character. Continues + * ^ ^ ^ ^ ^ + * | | | | | + * |_________________ > PRE_REFERENCE : state initiated by the '$' character. + * | | | | | + * |__________________> REFERENCE : state initiated by the identifier. Continues * | | | until end of the reference, or the . character. * |_____________ > REFMODIFIER : state switched to when the <DOT> is encountered. * | | note that this is a switch, not a push. See notes at bottom. @@ -1120,12 +1135,18 @@ TOKEN: * or $foo.bar[1], $foo.bar( "arg" )[1] * ---------------------------------------------------------------------------- */ -<REFERENCE,REFMODIFIER,REFMOD2> +<PRE_REFERENCE,REFMODIFIER,REFMOD2> TOKEN : { <#ALPHA_CHAR: ["a"-"z", "A"-"Z", "_"] > | <#IDENTIFIER_CHAR: [ "a"-"z", "A"-"Z", "0"-"9", "_" ] > | <IDENTIFIER: ( <ALPHA_CHAR> ) (<IDENTIFIER_CHAR>)* > + { + if (curLexState == PRE_REFERENCE) + { + SwitchTo(REFERENCE); + } + } } <REFERENCE,REFMODIFIER,REFMOD2,REFMOD3> @@ -1154,7 +1175,7 @@ TOKEN: } } -<REFERENCE,REFMODIFIER,REFMOD3> +<PRE_REFERENCE,REFERENCE,REFMODIFIER,REFMOD3> TOKEN : { <LCURLY: "{"> @@ -1164,7 +1185,7 @@ TOKEN : } } -<REFERENCE,REFMODIFIER,REFMOD,REFMOD3> +<PRE_REFERENCE,REFERENCE,REFMODIFIER,REFMOD,REFMOD3> SPECIAL_TOKEN : { <REFERENCE_TERMINATOR: ~[] > @@ -1251,6 +1272,7 @@ boolean Statement(boolean afterNewline) #void : | (<NEWLINE>) #Text { return true; } | (<INLINE_TEXT> ((<TEXT>)? { b = true; }) ) #Text { return b; } | (<WHITESPACE>) #Text { return false; } +| (<SUFFIX>) #Text { return true; } } /** @@ -1796,7 +1818,7 @@ void False() : {} * with the LOOKAHEAD in Reference, but I never found a way to resolve * it in a more fashionable way.. */ -<DEFAULT,REFERENCE> +<DEFAULT,PRE_REFERENCE> TOKEN : { <EMPTY_INDEX : ("$[" | "$![" | "$\\![" | "$.")> diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/foreach_smart.vtl.SMART b/velocity-engine-core/src/test/resources/gobbling/compare/foreach_smart.vtl.LINES index 4a1186bb..4a1186bb 100644 --- a/velocity-engine-core/src/test/resources/gobbling/compare/foreach_smart.vtl.SMART +++ b/velocity-engine-core/src/test/resources/gobbling/compare/foreach_smart.vtl.LINES diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/foreach_structured.vtl.SMART b/velocity-engine-core/src/test/resources/gobbling/compare/foreach_structured.vtl.LINES index d8acef9e..d8acef9e 100644 --- a/velocity-engine-core/src/test/resources/gobbling/compare/foreach_structured.vtl.SMART +++ b/velocity-engine-core/src/test/resources/gobbling/compare/foreach_structured.vtl.LINES diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/if.vtl.SMART b/velocity-engine-core/src/test/resources/gobbling/compare/if.vtl.LINES index 1c5d036e..1c5d036e 100644 --- a/velocity-engine-core/src/test/resources/gobbling/compare/if.vtl.SMART +++ b/velocity-engine-core/src/test/resources/gobbling/compare/if.vtl.LINES diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro.vtl.SMART b/velocity-engine-core/src/test/resources/gobbling/compare/macro.vtl.LINES index 611be323..611be323 100644 --- a/velocity-engine-core/src/test/resources/gobbling/compare/macro.vtl.SMART +++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro.vtl.LINES diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/set.vtl.SMART b/velocity-engine-core/src/test/resources/gobbling/compare/set.vtl.LINES index 76bd9ac7..76bd9ac7 100644 --- a/velocity-engine-core/src/test/resources/gobbling/compare/set.vtl.SMART +++ b/velocity-engine-core/src/test/resources/gobbling/compare/set.vtl.LINES diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/structured.vtl.SMART b/velocity-engine-core/src/test/resources/gobbling/compare/structured.vtl.LINES index 2fec8562..2fec8562 100644 --- a/velocity-engine-core/src/test/resources/gobbling/compare/structured.vtl.SMART +++ b/velocity-engine-core/src/test/resources/gobbling/compare/structured.vtl.LINES diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.BC b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.BC new file mode 100644 index 00000000..b4c2bd7c --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.BC @@ -0,0 +1,16 @@ +--- + $ + # + $$foo$ + $$foo# + $#foo + $#foo$ + $#foo# + $#foo + #$foo$ + #$foo# + #$foo + $#@foo()hop#end$ + $#@foo()hop#end# + $#@foo()hop#end +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.LINES b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.LINES new file mode 100644 index 00000000..b4c2bd7c --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.LINES @@ -0,0 +1,16 @@ +--- + $ + # + $$foo$ + $$foo# + $#foo + $#foo$ + $#foo# + $#foo + #$foo$ + #$foo# + #$foo + $#@foo()hop#end$ + $#@foo()hop#end# + $#@foo()hop#end +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.NONE b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.NONE new file mode 100644 index 00000000..b4c2bd7c --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.NONE @@ -0,0 +1,16 @@ +--- + $ + # + $$foo$ + $$foo# + $#foo + $#foo$ + $#foo# + $#foo + #$foo$ + #$foo# + #$foo + $#@foo()hop#end$ + $#@foo()hop#end# + $#@foo()hop#end +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.STRUCTURED b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.STRUCTURED new file mode 100644 index 00000000..b4c2bd7c --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly1.vtl.STRUCTURED @@ -0,0 +1,16 @@ +--- + $ + # + $$foo$ + $$foo# + $#foo + $#foo$ + $#foo# + $#foo + #$foo$ + #$foo# + #$foo + $#@foo()hop#end$ + $#@foo()hop#end# + $#@foo()hop#end +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.BC b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.BC new file mode 100644 index 00000000..43fd698f --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.BC @@ -0,0 +1,20 @@ +$$ +$$ +$true$$ +$true$$ +--- + $ + # + $bar$ + $bar# + $bar + $bar$ + $bar# + $bar + #bar$ + #bar# + #bar + $bar$ + $bar# + $bar +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.LINES b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.LINES new file mode 100644 index 00000000..43fd698f --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.LINES @@ -0,0 +1,20 @@ +$$ +$$ +$true$$ +$true$$ +--- + $ + # + $bar$ + $bar# + $bar + $bar$ + $bar# + $bar + #bar$ + #bar# + #bar + $bar$ + $bar# + $bar +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.NONE b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.NONE new file mode 100644 index 00000000..43fd698f --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.NONE @@ -0,0 +1,20 @@ +$$ +$$ +$true$$ +$true$$ +--- + $ + # + $bar$ + $bar# + $bar + $bar$ + $bar# + $bar + #bar$ + #bar# + #bar + $bar$ + $bar# + $bar +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.STRUCTURED b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.STRUCTURED new file mode 100644 index 00000000..43fd698f --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/ugly2.vtl.STRUCTURED @@ -0,0 +1,20 @@ +$$ +$$ +$true$$ +$true$$ +--- + $ + # + $bar$ + $bar# + $bar + $bar$ + $bar# + $bar + #bar$ + #bar# + #bar + $bar$ + $bar# + $bar +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/ugly1.vtl b/velocity-engine-core/src/test/resources/gobbling/ugly1.vtl new file mode 100644 index 00000000..b4c2bd7c --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/ugly1.vtl @@ -0,0 +1,16 @@ +--- + $ + # + $$foo$ + $$foo# + $#foo + $#foo$ + $#foo# + $#foo + #$foo$ + #$foo# + #$foo + $#@foo()hop#end$ + $#@foo()hop#end# + $#@foo()hop#end +--- diff --git a/velocity-engine-core/src/test/resources/gobbling/ugly2.vtl b/velocity-engine-core/src/test/resources/gobbling/ugly2.vtl new file mode 100644 index 00000000..062da10c --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/ugly2.vtl @@ -0,0 +1,20 @@ +$#macro(foo)bar#end$ +$#set($foo = 'bar')$ +$#if(true)true$#{else}false$#end$ +$#if(false)false$#{else}true$#end$ +--- + $ + # + $$foo$ + $$foo# + $#foo + $#foo$ + $#foo# + $#foo + #$foo$ + #$foo# + #$foo + $#@foo()hop#end$ + $#@foo()hop#end# + $#@foo()hop#end +--- |