rails/actionpack/lib/action_dispatch/journey/parser.y
Jack Danger Canty 0b8f35dd9c Using no_result_var in Journey's parser generator
Previously the generated parser had an intermediate local variable
`result` that really useful if you're building up a stateful object but
Journey always discards the result argument to the reduce functions.

This produces a simpler parser for anybody who actually wants to read
the thing.

Sadly, there's no real performance speedup with this change.
2014-08-03 15:23:56 -07:00

50 lines
965 B
Plaintext

class ActionDispatch::Journey::Parser
options no_result_var
token SLASH LITERAL SYMBOL LPAREN RPAREN DOT STAR OR
rule
expressions
: expression expressions { Cat.new(val.first, val.last) }
| expression { val.first }
| or
;
expression
: terminal
| group
| star
;
group
: LPAREN expressions RPAREN { Group.new(val[1]) }
;
or
: expression OR expression { Or.new([val.first, val.last]) }
| expression OR or { Or.new([val.first, val.last]) }
;
star
: STAR { Star.new(Symbol.new(val.last)) }
;
terminal
: symbol
| literal
| slash
| dot
;
slash
: SLASH { Slash.new('/') }
;
symbol
: SYMBOL { Symbol.new(val.first) }
;
literal
: LITERAL { Literal.new(val.first) }
;
dot
: DOT { Dot.new(val.first) }
;
end
---- header
require 'action_dispatch/journey/parser_extras'