hammer/src/bindings/ruby
2014-01-08 20:18:08 +01:00
..
lib Made library name cross-platform 2014-01-08 20:18:08 +01:00
test Add tests about token encoding (failing for now). 2014-01-08 20:18:08 +01:00
.gitignore Don't use C extensions (JRuby compatibility). 2014-01-08 20:18:07 +01:00
Gemfile Add real tests. 2014-01-08 20:18:08 +01:00
hammer-parser.gemspec Add first version of ruby bindings. 2014-01-08 20:18:07 +01:00
Rakefile Add real tests. 2014-01-08 20:18:08 +01:00
README.md Add real tests. 2014-01-08 20:18:08 +01:00

hammer-parser

Ruby bindings for hammer, a parsing library.

Notes

Development

  1. cd src/bindings/ruby.

  2. Run bundle install to install dependencies.

  3. Run irb -I ./lib -r hammer to open irb with hammer loaded.

  4. To run tests, just run rake.

Installation

TODO

Examples

Building a parser

parser = Hammer::Parser.build {
  token 'Hello '
  choice {
    token 'Mom'
    token 'Dad'
  }
  token '!'
}

Also possible:

parser = Hammer::ParserBuilder.new
  .token('Hello ')
  .choice(Hammer::Parser.token('Mom'), Hammer::Parser.token('Dad'))
  .token('!')
  .build

More like hammer in C:

h = Hammer::Parser
parser = h.sequence(h.token('Hello '), h.choice(h.token('Mom'), h.token('Dad')), h.token('!'))

Parsing

parser.parse 'Hello Mom!'
=> true
parser.parse 'Hello Someone!'
=> false

Currently you only get true or false depending on whether the parse succeeded or failed. There's no way to access the parsed data yet.