parslet is many peoples favorite parser construction toolkit. It uses a
grammar system called Parsing Expression Grammar (PEG)[1]. With parslet,
you can create neat parsers, from big to small. parslet has unit testing
support and spits out error messages for human beings.
- http://kschiess.github.com/parslet/index.html
- GitHub - kschiess/parslet: A small PEG based parser library. See the Hacking page in the Wiki as well.
Installation:
gem install parslet
Synopsis:
require ‘parslet’
class Mini < Parslet::Parser
rule(:integer) { match(‘[0-9]’).repeat(1) }
root(:integer)
end
Mini.new.parse(“132432”) # => “132432”@0
Changes:
Why the new release? So soon? Here’s why: parslet 1.5 features Ruby
HEREDOC support! Please look at the documentation or the ‘capture.rb’ in
the examples folder[2].
This also includes a few bugfixes, notably to EOF support - end of file
conditions are now normal error conditions that are handled by the same
code that handles other parse errors. As a consequence of this, you
might notice improved messages on premature EOF.
[1] Parsing expression grammar - Wikipedia
[2] https://github.com/kschiess/parslet/blob/master/example/capture.rb