I'm trying to write a (scannerless) recursive descent parser with a "catch all" rule for the following "Mustache template" grammar (simplified here):
content : (variable_tag | section_tag | static)*
variable_tag : mustache_open id mustache_close
section_tag : mustache_open '#' id mustache_close
content mustache_open '/' id mustache_close
mustache_open : '{{'
mustache_close : '}}'
id : [a–zA–Z$_][a–zA–Z0–9$_]*
static : .+ // "catch all"
The static
production would have to stop before the next matched production. And I can't come to a solution for this that would not break the grammar structure.
A valid input is:
You have just won {{value}} dollars!
{{#in_ca}}
Well, {{taxed_value}} dollars, after taxes.
{{/in_ca}}
The output for that would be an abstract syntactic tree like:
+-------+
|Content|
+-------+
|
+---------------+------+--------+--------------+
| | | |
+--------------+ +-----------+ +-------------+ +----------+
|Static | |VariableTag| |Static | |SectionTag|
|"\nYou...won "| |value | |" dollars"\n"| |in_ca |
+--------------+ +-----------+ +-------------+ +----------+
|
+-------+
|Content|
+-------+
|
+-------------+----+--------------+
| | |
+----------+ +-----------+ +---------------------+
|Static | |VariableTag| |Static |
|"\nWell, "| |taxed_value| |" dollars...taxes.\n"|
+----------+ +-----------+ +---------------------+
Any reference to a implementation of a "catch all" rule for a recursive descent parser?
static
match.
not.*
since.*
would require arbitrary lookahead to know when to stop..+
.+
suffers from the same problems.