Skip to content

Instantly share code, notes, and snippets.

@jasonwatkinspdx
Last active September 25, 2015 14:08
Show Gist options
  • Select an option

  • Save jasonwatkinspdx/933809 to your computer and use it in GitHub Desktop.

Select an option

Save jasonwatkinspdx/933809 to your computer and use it in GitHub Desktop.
what I hate about peg
# 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