Grammar Commands

Commands, like Instructions, resemble function calls. They serve two main purposes:

To process tokens in a specific way or
To provide a result to the caller
 

Commands

Command

Description

attribute(Name: String, Value: Expression)

Creates an attribute on the current AST node. The attribute will be created with the Name specified in the grammar source, and will be given the value of all tokens consumed as a part of executing the Value expression.

This command produces the AST node attributes that Enterprise Architect operates on in code engineering.

 

attributeEx(Name: String)

attributeEx(Name: String , Value: String)

Creates an attribute on the current AST node without consuming any tokens.  The attribute will be created with the Name specified in the grammar source, and with either an empty value or the value specified by the optional Value argument.

This command produces the AST node attributes that Enterprise Architect operates on in code engineering.

 

node(Name: String, Target: Expression)

Creates an AST node under the current AST node (the nodes that Enterprise Architect operates on in code engineering).  The node will be created with the Name specified in the grammar source.

 

token(Target: Expression)

Creates a token during lexical analysis for processing during parsing.  The value of the token will be the value of all characters consumed as a result of executing the Target expression.

 

keywords()

 

Matches any keyword from the parser rules set for the language.

skip(Target: Expression)

skip(Target: Expression, Escape: Expression)

 

Consumes input data (characters when lexing, and tokens when parsing) until the Target expression is matched.  The optional Escape expression can be used to handle instances such as escaped quotes within strings.

skipBalanced(Origin: Expression, Target: Expression)

skipBalanced(Origin: Expression, Target: Expression, Escape: Expression)

 

Consumes input data (characters or tokens) until the Target expression is matched and the nesting level reaches zero.  If the Origin expression is matched during this process, the nesting level is increased.  If the Target expression is matched, the nesting level is decreased.  When the nesting level reaches zero, the command exits with success.  An optional Escape expression can be provided.

skipEOF()

Consumes all remaining data (characters or tokens) until the end of the file.

 

fail()

Causes the parser to fail the current rule, including any remaining definitions.

 

warning()

Inserts a warning into the resulting AST.

 

except(Target: Expression, Exception: Expression)

Consumes input data that matches the Target expression, but fail on data that matches the Exception expression.  This operates somewhat similar to, but exactly the opposite of, the skip command.

 

preProcess(Target: Expression)

Evaluates an expression and uses that pre-processed data in multiple definitions.  This is most useful within expression parsing, where the same left hand side expression will be evaluated against a number of operators.  This command reduces the work the parser must do to make this happen.

 

Learn more