I have the following rule in a Parboiled parser:
public Rule AndExpression() {
return Sequence(
NotSwanExpression(),
ZeroOrMore(
Sequence(
FirstOf(AND(), AND_SYMBOL()),
NotSwanExpression(),push(searcher.and(pop(1),pop()))
)
)
);
}
That can parse "foo AND bar AND baz" into something like AND(AND(TERM(foo),TERM(bar)),TERM(baz))
The closest I could figure out to this in PEG.js was:
AndExpression
= left:NotSwanExpression (AND / AND_SYMBOL) right:NotSwanExpression { return new And(left, right) }
/ NotSwanExpression
However, that doesn't chain. I.e. it parses "foo AND bar" but it fails on "foo AND bar AND baz". I don't know how to properly handle recursion like that in PEG.js, and it is as you might guess a point of grief :( Can anyone help me out here? Thanks in advance,
-Josh Adams
Just didn't want to go without mentioning how I resolved the issue :) Thanks everybody
Hi Josh, I'm facing the same issue. Can you please post your solution if you still have it ?
Thanks.
Philippe