miguel01997 / cookcc

Automatically exported from code.google.com/p/cookcc
Other
0 stars 1 forks source link

Optional rule #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is for short handed version of writing parser rules.

For example, two rules of the following could potentially reduced 
{{{
@Rule (lhs = "Goal", rhs = "Name", args = "1")
Object parseGoal (String name) { ... }
@Rule (lhs = "Goal", rhs = "Name Suffix", args = "1 2")
Object parseGoal (String name, String suffix) { ... }
}}}
could be simplified to a single rule
{{{
@Rule (lhs = "Goal", rhs = "Name ?Suffix", args = "1 2")
Object parseGoal (String name, String suffix) { ... }
}}}
And let the value for Suffix to be null in this case.

Original issue reported on code.google.com by superdup...@gmail.com on 11 Oct 2009 at 4:40

GoogleCodeExporter commented 9 years ago
The rules can be expanded to include optional list (*) and list (+).  For
consistency, ?, *, and + needs to be located at the end of the token.

Original comment by superdup...@gmail.com on 20 Oct 2009 at 3:56

GoogleCodeExporter commented 9 years ago
Done. See r687.

Original comment by superdup...@gmail.com on 20 Oct 2009 at 4:00