antlr/doc/faq/actions-preds.md

11 lines
400 B
Markdown
Raw Normal View History

2015-10-28 01:44:23 +08:00
# Actions and semantic predicates
## How do I test if an optional rule was matched?
For optional rule references such as the initialization clause in the following
```
decl : 'var' ID (EQUALS expr)? ;
```
testing to see if that clause was matched can be done using `$EQUALS!=null` or `$expr.ctx!=null` where `$expr.ctx` points to the context or parse tree created for that reference to rule expr.