Created
February 8, 2012 20:55
-
-
Save bookshelfdave/1773744 to your computer and use it in GitHub Desktop.
This file contains 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
require 'parslet' | |
class Butter < Parslet::Parser | |
rule(:op_equals) { str('=') >> space? } | |
rule(:let) { str("let") >> space? } | |
rule(:space) { match('\s').repeat(1) } | |
rule(:space?) { space.maybe } | |
rule(:integer) { match('[0-9]').repeat(1).as(:int) >> space? } | |
rule(:identifier) { (match['a-z'].repeat(1,1) >> match['a-zA-Z0-9_'].repeat).as(:id) } | |
rule(:letexpr) { let >> identifier >> op_equals >> integer } | |
root :letexpr | |
end | |
b = Butter.new | |
b.parse("let a1 = 1") | |
#C:/Ruby192/lib/ruby/gems/1.9.1/gems/parslet-1.2.3/lib/parslet/atoms/base.rb:257:in `parse_failed': Failed to match sequence (LET IDENTIFIER OP_EQUALS INTEGER) at line 1 char 6. (Parslet::ParseFailed) | |
# from C:/Ruby192/lib/ruby/gems/1.9.1/gems/parslet-1.2.3/lib/parslet/atoms/base.rb:39:in `parse' | |
# from C:/src/butterexample.rb:20:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment