Quantcast

NoneOf("...")

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

NoneOf("...")

sulfinu
Hi.

Parboiled appears to have support for specifiying rules that exclude a few characters, rather than admit them. See org.parboiled.support.Characters.allBut() methods.
I believe something like:

public Rule NoneOf(String x)  // x could be char[], as well
{
  // some checks...
  // ...
  return AnyOfMatcher(Characters.allBut(x));
}

in BaseParser should work. What do you think?

PS: By the way, in this page
https://github.com/sirthias/parboiled/wiki/Rule-Construction-in-Java
the AnyOf method is wrongly listed as "FirstOf", while the underlying link points to a probably dead and buried method.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

mathias
Administrator
Good idea!
I just implemented it:
https://github.com/sirthias/parboiled/commit/ca74069d1c10ffecece93a5995d4cc446e37cb52

'NoneOf(...)' is now available as a more efficient way of saying 'Sequence(TestNot(AnyOf(...)), ANY)'

Cheers,
Mathias

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

On 08.07.2011, at 16:05, sulfinu [via parboiled users] wrote:

> Hi.
>
> Parboiled appears to have support for specifiying rules that exclude a few characters, rather than admit them. See org.parboiled.support.Characters.allBut() methods.
> I believe something like:
>
> public Rule NoneOf(String x)  // x could be char[], as well
> {
>   // some checks...
>   // ...
>   return AnyOfMatcher(Characters.allBut(x));
> }
>
> in BaseParser should work. What do you think?
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/NoneOf-tp3151906p3151906.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

sulfinu
Don't forget about the documentation page correction.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

Freewind
In reply to this post by mathias
And don't forget to add it to `org.parboiled.scala.Parser`, it's very useful.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

mathias
Administrator
I just committed the Scala version of 'noneOf' to the develop branch.
Will update the documentation when the next release goes out...

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

On 16.07.2011, at 16:55, Freewind [via parboiled users] wrote:

> And don't forget to add it to `org.parboiled.scala.Parser`, it's very useful.
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/NoneOf-tp3151906p3174743.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

sulfinu
This post was updated on .
Just in case you've forgotten, this page
https://github.com/sirthias/parboiled/wiki/Rule-Construction-in-Java
looks still as it did when I started this thread.

Also, the first code snippet in page
https://github.com/sirthias/parboiled/wiki/Action-Variables
is illegal in Java, because this group of lines is useless:

> return Sequence(
>      StringVar text = new StringVar("");
>      StringVar temp = new StringVar("");
...
> );
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

mathias
Administrator
Sulfinu,

thanks a lot!
Indeed I had forgotten to update this page.
Fixed now...

Thanks again for the report!

Cheers,
Mathias

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

On 20.10.2011, at 17:03, sulfinu [via parboiled users] wrote:

> Just in case you've forgotten, this page
> https://github.com/sirthias/parboiled/wiki/Rule-Construction-in-Java
> looks still as it did when I started this thread.
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/NoneOf-tp3151906p3437951.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

cosmindumy
Hi again,
I didn't managed to implement a rule that doesn't want to match a string. For example I want to implement a rule
that matches not('is')~in~ english. Meaning before 'in' can be anything but not word ('in').
My try was Sequence(Word("translate), Space(), Optional(Sequence(NoneOf("i"), NoneOf("s"))),Word("in),Space(), ...) but is clear why it didn't worked.
I also want to match a phrase like "I want to go to" and after 'go' can be anything except word "England".
Thanks.
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: NoneOf("...")

fge
On Thu, Jan 17, 2013 at 2:49 PM, cosmindumy [via parboiled users]
<[hidden email]> wrote:

> Hi again,
> I didn't managed to implement a rule that doesn't want to match a string.
> For example I want to implement a rule
> that matches not('is')~in~ english. Meaning before 'in' can be anything but
> not word ('in').
> My try was Sequence(Word("translate), Space(),
> Optional(Sequence(NoneOf("i"), NoneOf("s"))),Word("in),Space(), ...) but is
> clear why it didn't worked.
> I also want to match a phrase like "I want to go to" and after 'go' can be
> anything except word "England".
> Thanks.
>

Use TestNot(). NoneOf() matches _one_ character which is not any of
the characters in the argument.

Note however that TestNot() will not consume text, you will need to
consume it after that. For instance:

    Sequence(TestNot("England"), WordChars());


--
Francis Galiegue, [hidden email]
"It seems obvious [...] that at least some 'business intelligence'
tools invest so much intelligence on the business side that they have
nothing left for generating SQL queries" (St├ęphane Faroult, in "The
Art of SQL", ISBN 0-596-00894-5)
Loading...