parboiled and handling spaces/lexers

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

parboiled and handling spaces/lexers

jms_nh
For clarity + reduced possibility of errors, I would like to avoid having to handle spacing in my parser, which pushes me towards a hand-coded lexer... but then I lose the ability to use parboiled with all kinds of goodies.

What options do I have? I'd love to have a two-phase lexer/parser in parboiled.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: parboiled and handling spaces/lexers

mathias
Administrator
PEG parsing is lexer-less, there is nothing you can really do about this.
Of course you could preprocess the input and replace any character sequences with special characters, that you then match from your PEG grammar.
The `IndentDedentInputBuffer`[1] for example does exactly that to all line indentations.

Another alternative would be to automatically augment rules with the matching of certain types of whitespace.
One example: https://github.com/sirthias/parboiled/blob/master/examples-java/src/main/java/org/parboiled/examples/calculators/CalculatorParser4.java#L98

HTH and cheers,
Mathias

  [1]: https://github.com/sirthias/parboiled/blob/master/parboiled-core/src/main/java/org/parboiled/buffers/IndentDedentInputBuffer.java

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

On 05.07.2013, at 18:09, jms_nh [via parboiled users] <[hidden email]> wrote:

>
>
> For clarity + reduced possibility of errors, I would like to avoid having to
> handle spacing in my parser, which pushes me towards a hand-coded lexer...
> but then I lose the ability to use parboiled with all kinds of goodies.
>
> What options do I have? I'd love to have a two-phase lexer/parser in
> parboiled.
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/parboiled-and-handling-spaces-lexers-tp4024227.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Loading...