com.google.clearsilver.jsilver.syntax
Class SyntaxTreeBuilder

java.lang.Object
  extended by com.google.clearsilver.jsilver.syntax.SyntaxTreeBuilder

public class SyntaxTreeBuilder
extends Object

Parses a JSilver text template into an abstract syntax tree (AST).

Acts as a facade around SableCC generated code. The simplest way to process the resulting tree is to use a visitor by extending DepthFirstAdapter and passing it to Start.apply(com.google.clearsilver.jsilver.syntax.node.Switch).

Example:

 SyntaxTreeBuilder builder = new SyntaxTreeBuilder();
 Start tree = builder.parse(myTemplate, "some-template.cs");
 // Dump out the tree
 tree.apply(new SyntaxTreeDumper(System.out));
 


Field Summary
protected  Switch inlineRewriter
           
protected  Switch sequenceOptimizer
           
protected  Switch typeResolver
          Syntax tree optimizers, declared in the order they must be applied: Type resultion makes the abstract tree concrete and must come first.
protected  Switch varOptimizer
           
 
Constructor Summary
SyntaxTreeBuilder()
           
 
Method Summary
 TemplateSyntaxTree parse(Reader input, String templateName, EscapeMode escapeMode)
           
protected  void process(Start root, EscapeMode escapeMode, String templateName)
          Perform any additional processing on the tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeResolver

protected final Switch typeResolver
Syntax tree optimizers, declared in the order they must be applied:
  1. Type resultion makes the abstract tree concrete and must come first.
  2. Sequence optimization simplifies the tree and should come before most other optimizations.
  3. Inline rewriting to remove data nodes from 'inline' sections. This should come before any optimization of variables.
  4. Var optimization simplifies complex var expressions and must come after both type resolution and sequence optimization.


sequenceOptimizer

protected final Switch sequenceOptimizer

inlineRewriter

protected final Switch inlineRewriter

varOptimizer

protected final Switch varOptimizer
Constructor Detail

SyntaxTreeBuilder

public SyntaxTreeBuilder()
Method Detail

process

protected void process(Start root,
                       EscapeMode escapeMode,
                       String templateName)
Perform any additional processing on the tree. EscapeMode and templateName are required by AutoEscaper.

Parameters:
root - The AST to post process.
escapeMode - The escaping mode to apply to the given AST. If this is not EscapeMode.ESCAPE_NONE, AutoEscaper will be called on the AST.
templateName - The name of template being processed. Passed to AutoEscaper, which uses it when displaying error messages.

parse

public TemplateSyntaxTree parse(Reader input,
                                String templateName,
                                EscapeMode escapeMode)
                         throws JSilverIOException,
                                JSilverBadSyntaxException
Parameters:
templateName - Used for meaningful error messages.
escapeMode - Run AutoEscaper on the abstract syntax tree created from template.
Throws:
JSilverIOException
JSilverBadSyntaxException


Copyright © 2010-2012 Google. All Rights Reserved.