From f751400e624b2c3f45caf03f9bbf895479c32858 Mon Sep 17 00:00:00 2001 From: TQ Hirsch <thequux@upstandinghackers.com> Date: Sat, 11 Jan 2014 06:05:23 +0100 Subject: [PATCH] Updated Ruby-specific README --- src/bindings/ruby/README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bindings/ruby/README.md b/src/bindings/ruby/README.md index 61ce0b37..ae29459f 100644 --- a/src/bindings/ruby/README.md +++ b/src/bindings/ruby/README.md @@ -14,9 +14,9 @@ Ruby bindings for [hammer](https://github.com/UpstandingHackers/hammer), a parsi 2. Run `bundle install` to install dependencies. -3. Run `irb -I ./lib -r hammer` to open `irb` with hammer loaded. +3. Run `bundle console` to open `irb` with hammer loaded. -4. To run tests, just run `rake`. +4. To run tests, just run `bundle exec rake test`. ## Installation @@ -60,11 +60,17 @@ parser = h.sequence(h.token('Hello '), h.choice(h.token('Mom'), h.token('Dad')), ### Parsing ```ruby -parser.parse 'Hello Mom!' -=> true -parser.parse 'Hello Someone!' -=> false +result = parser.parse 'Hello Mom!' +=> #<HParseResult> +result = parser.parse 'Hello Someone!' +=> nil ``` -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. +The `parse` method returns an `HParseResult` object, which needs to be +kept around until you're entirely done with the parse tree, which can +be accessed with `result.ast`. + +While the AST can be accessed using the same interface as the C +HParsedToken type, we recommend using `result.ast.unmarshal` instead. +This converts the entire parse tree into a standalone Ruby-native +datastructure which will likely be much easier to work with. -- GitLab