1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/racc/assets/journey.y

48 lines
929 B
Text
Raw Normal View History

2019-05-13 08:25:22 -04:00
class Journey::Parser
token SLASH LITERAL SYMBOL LPAREN RPAREN DOT STAR OR
rule
expressions
: expressions expression { result = Cat.new(val.first, val.last) }
| expression { result = val.first }
| or
;
expression
: terminal
| group
| star
;
group
: LPAREN expressions RPAREN { result = Group.new(val[1]) }
;
or
: expressions OR expression { result = Or.new([val.first, val.last]) }
;
star
: STAR { result = Star.new(Symbol.new(val.last)) }
;
terminal
: symbol
| literal
| slash
| dot
;
slash
: SLASH { result = Slash.new('/') }
;
symbol
: SYMBOL { result = Symbol.new(val.first) }
;
literal
: LITERAL { result = Literal.new(val.first) }
dot
: DOT { result = Dot.new(val.first) }
;
end
---- header
require 'journey/parser_extras'