Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save practicingruby/9535963 to your computer and use it in GitHub Desktop.
Save practicingruby/9535963 to your computer and use it in GitHub Desktop.
class Parser
rule
string
| a_or_cs abb
| abb
;
a_or_cs
: a_or_cs a_or_c
| a_or_c
;
a_or_c : 'a' | 'c' ;
abb : 'a' 'b' 'b' { puts "I found abb!" };
end
---- inner
def next_token
@q.shift
end
def parse(text)
@q = text.chars.map { |c| [c, c] }
do_parse
end
---- footer
parser = Parser.new
# raises Racc::ParseError on failed match
parser.parse(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment