Quantcast

Using the Not-Predicate

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using the Not-Predicate

Dave Berry
Just looking for confirmation on the correct way to implement this EBNF notation in parboiled Scala

Given the EBNF Notation:

A - B   (matches any string that matches A but does not match B)

The Scala Rule would be:

def C = rule { !B ~ A }

Based on the Java Description of TestNot, it does not actually consume any input, so putting it first should confirm that it does not match B and the input should be available for matching A.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using the Not-Predicate

mathias
Administrator
Yes,

!B ~ A

would be the correct way to match all As at positions where B does not match.

Btw: This way of writing the rule is not parboiled specific but rather the common solution for all PEGs...

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 28.06.2011, at 15:27, Dave Berry [via parboiled users] wrote:

> Just looking for confirmation on the correct way to implement this EBNF notation in parboiled Scala
>
> Given the EBNF Notation:
>
> A - B   (matches any string that matches A but does not match B)
>
> The Scala Rule would be:
>
> def C = rule { !B ~ A }
>
> Based on the Java Description of TestNot, it does not actually consume any input, so putting it first should confirm that it does not match B and the input should be available for matching A.
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Using-the-Not-Predicate-tp3117754p3117754.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Loading...