| .. | ||
| ext/hammer_ext | ||
| lib | ||
| .gitignore | ||
| Gemfile | ||
| hammer-parser.gemspec | ||
| Rakefile | ||
| README.md | ||
hammer-parser
Ruby bindings for hammer, a parsing library.
Notes
-
I called the gem
hammer-parser, since there already is a gem namedhammer. -
C extension not really needed at the moment, if we don't mind hardcoding the token types in the ruby code.
Development
-
cd src/bindings/ruby. -
Run
bundle installto install dependencies. -
Run
rake compileto compile the C extension. -
Run
irb -I ./lib -r hammerto openirbwith hammer loaded.
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.