All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.antlr.codegen.templates.JavaScript.ASTTreeParser.stg Maven / Gradle / Ivy

There is a newer version: 3.5.3
Show newest version
/** Templates for building ASTs during tree parsing.
 *
 *  Deal with many combinations.  Dimensions are:
 *  Auto build or rewrite
 *    no label, label, list label  (label/no-label handled together)
 *    child, root
 *    token, set, rule, wildcard
 *
 *  Each combination has its own template except that label/no label
 *  is combined into tokenRef, ruleRef, ...
 */
group ASTTreeParser;

/** Add a variable to track last element matched */
ruleDeclarations() ::= <<

var _first_0 = null;
var _last = null;<\n>
>>

/** What to emit when there is no rewrite rule.  For auto build
 *  mode, does nothing.
 */
noRewrite(rewriteBlockLevel, treeLevel) ::= <<
if (  ) {

retval.tree = _first_0;
if ( this.adaptor.getParent(retval.tree) && this.adaptor.isNil( this.adaptor.getParent(retval.tree) ) )
    retval.tree = this.adaptor.getParent(retval.tree);

}
>>

/** match ^(root children) in tree parser; override here to
 *  add tree construction actions.
 */
tree(root, actionsAfterRoot, children, nullableChildList,
     enclosingTreeLevel, treeLevel) ::= <<
_last = this.input.LT(1);
{
var _save_last_ = _last;
var _first_ = null;

var root_ = this.adaptor.nil();



if (  )

if ( !_first_ ) _first_ = .tree;

if ( !_first_ ) _first_ = ;




if ( this.input.LA(1)==org.antlr.runtime.Token.DOWN ) {
    this.match(this.input, org.antlr.runtime.Token.DOWN, null); 
    
    this.match(this.input, org.antlr.runtime.Token.UP, null); 
}

this.match(this.input, org.antlr.runtime.Token.DOWN, null); 

this.match(this.input, org.antlr.runtime.Token.UP, null); 


this.adaptor.addChild(root_, root_);

_last = _save_last_;
}<\n>
>>

// TOKEN AST STUFF

/** ID! and output=AST (same as plain tokenRef) 'cept add
 *  setting of _last
 */
tokenRefBang(token,label,elementIndex) ::= <<
_last = this.input.LT(1);

>>

/** ID auto construct */
tokenRef(token,label,elementIndex,terminalOptions) ::= <<
_last = this.input.LT(1);


if (  ) {





© 2015 - 2024 Weber Informatics LLC | Privacy Policy