Parslet 1.0 - a PEG parser library

parslet is a Parsing Expression Grammar based[1] parser generator
library. Uff. Now that is out of our system, here goes what it really
does: It makes writing parsers pleasant for the rest of us. No code
generation, clear access to data, unit testable.

Installation:

gem install parslet

Changes:

This hasn’t ever been publicly announced, so that is the real big
change.

Synopsis:

require ‘parslet’
class Mini < Parslet::Parser
rule(:integer) { match(‘[0-9]’).repeat(1) }
root(:integer)
end

Mini.new.parse(“132432”) # => 132432

Please, ladies and gents, amuse yourselves!

[1] Parsing expression grammar - Wikipedia

On Dec 29, 2010, at 01:37 , Kaspar S. wrote:

Mini.new.parse(“132432”) # => 132432
Cool!

Questions:

  • Any performance benchmarks?

  • Does this PEG support left recursion?

  • I assume with it subclassing Parslet::Parser that it does support
    language extension via further subclassing… But does that also imply
    that it can’t support composition? I’ve usually seen that via multiple
    inheritance, and we’d usually do it via modules in ruby.

AH! I see that Parslet is a module and provides at least some of the
grammar API.

  • Any performance benchmarks?

Official ones, no. Working with it: I just might have gotten the
impression that there is room for improvement. (slow!) This is certainly
the next thing on the menu. For example, it uses exceptions heavily
which isn’t the fastest thing to do. Can be and will be changed.

  • Does this PEG support left recursion?
    Not yet. (Or only in the limited fashion, after a grammar
    transformation) Cool you mention the possibility to me, might just add
    that.
  • I assume with it subclassing Parslet::Parser that it does support language
    extension via further subclassing… But does that also imply that it can’t
    support composition? I’ve usually seen that via multiple inheritance, and we’d
    usually do it via modules in ruby.

AH! I see that Parslet is a module and provides at least some of the grammar
API.

That’s a complicated topic :wink: Parser rules are just methods on a class,
so go ahead and use modules, classes and other tricks any way you like
it. Like in example/ip_address.rb.

The documentation tries to simplify that for the general case. And I
have yet to see a sample of composition that is really useful (in the
sense of orthogonality of pieces).

Also, don’t dig too hard, hidden features lurking to bite you :wink:

regards,
kaspar