Last active
September 25, 2015 14:08
-
-
Save jasonwatkinspdx/933809 to your computer and use it in GitHub Desktop.
what I hate about peg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example, parsing a phone book of name, number lines: | |
| # bob, 867-5309 | |
| # ricky bobby, 867-5309 | |
| # classic style PEG would give me some s expression thing like: | |
| [:phonebook, | |
| [:line, [:name, "bob"], [:number, "867-5309"] | |
| [:line, [:name, "ricky bobby"], [:number, "867-5309"]] | |
| # and instead in the app I want an easy way to get something like: | |
| [["bob", "867-5309"], ["ricky bobby", "867-5309"]] | |
| # or maybe: | |
| phonebook[1].name # sue | |
| # for a grammar API I'm thinking something like | |
| Shrub.new do | |
| line do | |
| string :until => ',' | |
| string ", " | |
| string :allow => [0..9, "-"] | |
| end | |
| end | |
| # or | |
| name = Shrub.string :until => ',' | |
| number = Shrub.string :allow => [0..9, "-"] | |
| phonebook = Shrub.repeat name, ", ", number, "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment