Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Commit 5cd0f86

Browse files
committed
Update example in README
1 parent 0aa40c2 commit 5cd0f86

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@ require "marpa"
3131
parser = Marpa::Parser.new
3232

3333
grammar = <<-'END_BNF'
34-
:start ::= language
35-
36-
language ::= number op_plus number
37-
number ~ [\d]+
38-
op_plus ~ '+'
34+
# Grammar from https://metacpan.org/pod/distribution/Marpa-R2/pod/Semantics.pod
35+
:start ::= Expression
36+
Expression ::= Number
37+
| '(' Expression ')'
38+
|| Expression '**' Expression
39+
|| Expression '*' Expression
40+
| Expression '/' Expression
41+
|| Expression '+' Expression
42+
| Expression '-' Expression
43+
44+
Number ~ [\d]+
3945

4046
:discard ~ whitespace
4147
whitespace ~ [\s]+
4248
END_BNF
4349

44-
input = "100 + 200"
50+
input = "3 + 5 * 10"
4551

46-
parser.parse(input, grammar) # => ["100", "+", "200"]
52+
pp parser.parse(input, grammar) # => [["3"], "+", [["5"], "*", ["10"]]]
4753
```
4854

4955
See `examples/` for a more thorough demonstration of this interface's capabilities, including a JSON parser.

0 commit comments

Comments
 (0)