User:OrenBochman/ParserNG/antlr

The preprocessor is tricky business to code.
 * It has recursive rules a complicated (for parsing) format.
 * double curly expressions can have different semantics
 * triple curlies too
 * single curlies also on occasion.

next follow some advanced Antlr specific features illustrated by things they could help to fix.

Semantic and Syntactic Predicates
two advanced ideas are

syntactic predicates
parts of a template look like:

Using Semantics To Simplify Syntax Parsing
does lit. '...' reffer to a parser function, magic word or a template ?

since the parser should be privy to a symbol table of parser_functions, magic_words, templates, variables, etc they can be used to simplify (read: speed up parsing using a simple semantic check (isMagicWord) instead of a deep syntax scan.) in Antlr speak lookahead is said to be analogous to checking all options of the maze, using predicates is called sending in a trained monkiess to stand in the required junction points.

IncludeOnly and NoInclude semantics

 * IncludeOnly means include the following text only within the scope of the tansculded page (expanded page).
 * NoInclude means include the following text only within the scope of the template page (expanded page).

Look Ahead
This is an example of using look ahead in the parser. There is also lookahead in the lexer. But it does not return string only ints (of chars).

Implementing some parser functions
if switch etc are the where parsers shine. the parser rules below use sysntactic predicates:

Implementing some Magic Words
Magic words can be trickier to take care of since. one idea is to keep them in a data structure like a hash or a trie.