-
Notifications
You must be signed in to change notification settings - Fork 4
Home
onnlucky edited this page Sep 13, 2010
·
6 revisions
parser Count {
start: counted(0) ;
counted n=_ m={return (Integer)n + 1; }: l=_ r=counted(m) { [n, l] + r } | empty { [] } ;
}
will return an interleaved array:
new Count.parse(new Object[] { "hello", "world"}); // Object[] { 0, "hello", 1, "world" }
The shorthand notation of { ['NUM, 42] } will always return an array.
The zero or more, or one or more, modifiers will always return an ArrayList. E.g. rule: something+ ; will result in an ArrayList of somethings.
Something interesting to think about in error handling of jmeta:
foo(arg1, 10 + 10)in a certain language initial almost parse as function definition, but
10 + 10 is obviously not allowed as args. So if args looks like:args: f=arg fs=(.","! .arg)*then this perfectly sane error if comma but no arg code is pretty sane, but fails since ultimately this code backtracks and becomes regular function call. But that means these sort of error reports are less useful in this situation.