com.google.clearsilver.jsilver.syntax
Class StructuralWhitespaceStripper
java.lang.Object
com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
com.google.clearsilver.jsilver.syntax.StructuralWhitespaceStripper
- All Implemented Interfaces:
- Analysis, Switch
public class StructuralWhitespaceStripper
- extends DepthFirstAdapter
Detects sequences of commands corresponding to a line in the template containing only structural
commands, comments or whitespace and rewrites the syntax tree to effectively remove any data
(text) associated with that line (including the trailing whitespace).
A structural command is any command that never emits any output. These come in three types:
- Commands that can contain other commands (eg, "alt", "each", "escape", "if", "loop", "with",
etc...).
- Commands that operate on the template itself (eg, "include", "autoescape", etc...).
- Comments.
This makes it much easier to write human readable templates in cases where the output format is
whitespace sensitive.
Thus the input:
----------------
Value is:
<?cs if:x>0 ?>
positive
<?cs elif:x<0 ?>
negative
<?cs else ?>
zero
<?cs /if ?>.
----------------
is equivalent to:
----------------
Value is:
<?cs if:x>0 ?> positive
<?cs elif:x<0 ?> negative
<?cs else ?> zero
<?cs /if ?>.
----------------
but is much easier to read.
Where data commands become empty they are replaced with Noop commands, which effectively removes
them from the tree. These can be removed (if needed) by a later optimization step but shouldn't
cause any issues.
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter |
caseAAddExpression, caseAAndExpression, caseAAutoescapeCommand, caseACallCommand, caseACommaExpression, caseACommentCommand, caseAContentTypeCommand, caseACsOpenPosition, caseADecimalExpression, caseADecNumberVariable, caseADescendVariable, caseADivideExpression, caseAEqExpression, caseAEvarCommand, caseAExistsExpression, caseAExpandVariable, caseAFunctionExpression, caseAGteExpression, caseAGtExpression, caseAHardIncludeCommand, caseAHardLincludeCommand, caseAHexExpression, caseAHexNumberVariable, caseAIncludeCommand, caseAInlineCommand, caseALincludeCommand, caseALteExpression, caseALtExpression, caseALvarCommand, caseAModuloExpression, caseAMultipleCommand, caseAMultiplyExpression, caseANameCommand, caseANameVariable, caseANeExpression, caseANegativeExpression, caseANoopCommand, caseANoopExpression, caseANotExpression, caseANumericAddExpression, caseANumericEqExpression, caseANumericExpression, caseANumericNeExpression, caseAOrExpression, caseASequenceExpression, caseASetCommand, caseAStringExpression, caseASubtractExpression, caseAUvarCommand, caseAVarCommand, caseAVariableExpression, defaultIn, defaultOut, inAAddExpression, inAAndExpression, inAAutoescapeCommand, inACommaExpression, inACommentCommand, inAContentTypeCommand, inACsOpenPosition, inADataCommand, inADecimalExpression, inADecNumberVariable, inADefCommand, inADescendVariable, inADivideExpression, inAEachCommand, inAEqExpression, inAEscapeCommand, inAExistsExpression, inAExpandVariable, inAFunctionExpression, inAGteExpression, inAGtExpression, inAHardIncludeCommand, inAHardLincludeCommand, inAHexExpression, inAHexNumberVariable, inAIfCommand, inAIncludeCommand, inAInlineCommand, inALincludeCommand, inALoopCommand, inALoopIncCommand, inALoopToCommand, inALteExpression, inALtExpression, inAModuloExpression, inAMultipleCommand, inAMultiplyExpression, inANameVariable, inANeExpression, inANegativeExpression, inANoopCommand, inANoopExpression, inANotExpression, inANumericAddExpression, inANumericEqExpression, inANumericExpression, inANumericNeExpression, inAOrExpression, inASequenceExpression, inAStringExpression, inASubtractExpression, inAVariableExpression, inAWithCommand, inStart, outAAddExpression, outAAltCommand, outAAndExpression, outAAutoescapeCommand, outACallCommand, outACommaExpression, outACommentCommand, outAContentTypeCommand, outACsOpenPosition, outADataCommand, outADecimalExpression, outADecNumberVariable, outADefCommand, outADescendVariable, outADivideExpression, outAEachCommand, outAEqExpression, outAEscapeCommand, outAEvarCommand, outAExistsExpression, outAExpandVariable, outAFunctionExpression, outAGteExpression, outAGtExpression, outAHardIncludeCommand, outAHardLincludeCommand, outAHexExpression, outAHexNumberVariable, outAIfCommand, outAIncludeCommand, outAInlineCommand, outALincludeCommand, outALoopCommand, outALoopIncCommand, outALoopToCommand, outALteExpression, outALtExpression, outALvarCommand, outAModuloExpression, outAMultipleCommand, outAMultiplyExpression, outANameCommand, outANameVariable, outANeExpression, outANegativeExpression, outANoopCommand, outANoopExpression, outANotExpression, outANumericAddExpression, outANumericEqExpression, outANumericExpression, outANumericNeExpression, outAOrExpression, outASequenceExpression, outASetCommand, outAStringExpression, outASubtractExpression, outAUvarCommand, outAVarCommand, outAVariableExpression, outAWithCommand, outStart |
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter |
caseEOF, caseTAlt, caseTAnd, caseTArgWhitespace, caseTAssignment, caseTAutoescape, caseTBang, caseTBracketClose, caseTBracketOpen, caseTCall, caseTComma, caseTCommandDelimiter, caseTComment, caseTCommentStart, caseTContentType, caseTCsClose, caseTCsOpen, caseTData, caseTDecNumber, caseTDef, caseTDollar, caseTDot, caseTEach, caseTElse, caseTElseIf, caseTEq, caseTEscape, caseTEvar, caseTGt, caseTGte, caseTHardDelimiter, caseTHash, caseTHexNumber, caseTIf, caseTInclude, caseTInline, caseTLinclude, caseTLoop, caseTLt, caseTLte, caseTLvar, caseTMinus, caseTName, caseTNe, caseTOr, caseTParenClose, caseTParenOpen, caseTPercent, caseTPlus, caseTQuestion, caseTSet, caseTSlash, caseTStar, caseTString, caseTUvar, caseTVar, caseTWith, caseTWord, defaultCase, getIn, getOut, setIn, setOut |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
StructuralWhitespaceStripper
public StructuralWhitespaceStripper()
caseStart
public void caseStart(Start node)
- Specified by:
caseStart
in interface Analysis
- Overrides:
caseStart
in class DepthFirstAdapter
caseADataCommand
public void caseADataCommand(ADataCommand data)
- Specified by:
caseADataCommand
in interface Analysis
- Overrides:
caseADataCommand
in class DepthFirstAdapter
inAAltCommand
public void inAAltCommand(AAltCommand node)
- Overrides:
inAAltCommand
in class DepthFirstAdapter
inACallCommand
public void inACallCommand(ACallCommand node)
- Overrides:
inACallCommand
in class DepthFirstAdapter
inAEvarCommand
public void inAEvarCommand(AEvarCommand node)
- Overrides:
inAEvarCommand
in class DepthFirstAdapter
inALvarCommand
public void inALvarCommand(ALvarCommand node)
- Overrides:
inALvarCommand
in class DepthFirstAdapter
inANameCommand
public void inANameCommand(ANameCommand node)
- Overrides:
inANameCommand
in class DepthFirstAdapter
inASetCommand
public void inASetCommand(ASetCommand node)
- Overrides:
inASetCommand
in class DepthFirstAdapter
inAUvarCommand
public void inAUvarCommand(AUvarCommand node)
- Overrides:
inAUvarCommand
in class DepthFirstAdapter
inAVarCommand
public void inAVarCommand(AVarCommand node)
- Overrides:
inAVarCommand
in class DepthFirstAdapter
enterComplexCommand
public void enterComplexCommand()
exitComplexCommand
public void exitComplexCommand()
caseAAltCommand
public void caseAAltCommand(AAltCommand node)
- Specified by:
caseAAltCommand
in interface Analysis
- Overrides:
caseAAltCommand
in class DepthFirstAdapter
caseADefCommand
public void caseADefCommand(ADefCommand node)
- Specified by:
caseADefCommand
in interface Analysis
- Overrides:
caseADefCommand
in class DepthFirstAdapter
caseAEachCommand
public void caseAEachCommand(AEachCommand node)
- Specified by:
caseAEachCommand
in interface Analysis
- Overrides:
caseAEachCommand
in class DepthFirstAdapter
caseAEscapeCommand
public void caseAEscapeCommand(AEscapeCommand node)
- Specified by:
caseAEscapeCommand
in interface Analysis
- Overrides:
caseAEscapeCommand
in class DepthFirstAdapter
caseAIfCommand
public void caseAIfCommand(AIfCommand node)
- Specified by:
caseAIfCommand
in interface Analysis
- Overrides:
caseAIfCommand
in class DepthFirstAdapter
caseALoopCommand
public void caseALoopCommand(ALoopCommand node)
- Specified by:
caseALoopCommand
in interface Analysis
- Overrides:
caseALoopCommand
in class DepthFirstAdapter
caseALoopIncCommand
public void caseALoopIncCommand(ALoopIncCommand node)
- Specified by:
caseALoopIncCommand
in interface Analysis
- Overrides:
caseALoopIncCommand
in class DepthFirstAdapter
caseALoopToCommand
public void caseALoopToCommand(ALoopToCommand node)
- Specified by:
caseALoopToCommand
in interface Analysis
- Overrides:
caseALoopToCommand
in class DepthFirstAdapter
caseAWithCommand
public void caseAWithCommand(AWithCommand node)
- Specified by:
caseAWithCommand
in interface Analysis
- Overrides:
caseAWithCommand
in class DepthFirstAdapter
Copyright © 2010-2012 Google. All Rights Reserved.