rails/actionpack/lib/action_dispatch/journey/parser.y
Daniel Colson 185c4f2d11
Build symbols descending from stars with regexp
Before this commit we initialized all Symbols with the default regexp,
then later on reassigned any symbols descending from stars with either
their regexp from `@requirements` or the default greedy regexp.

With this commit we initialize all Symbols descending from Stars with
the greedy regexp at parse time. This allows us to get rid of the star
branch in path/pattern, since any regexps from `@requirements` will
already have been set in the symbol branch of this code.

This is essentially an alternate version of #38901. Getting rid of the
extra branch makes some performance work I am doing a bit easier, plus
it saves us a few method calls. Also the constant saves us from creating
the same regexp multiple times, and it is nice to give that regexp a
name.
2020-07-24 22:30:20 -04:00

51 lines
1003 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, Symbol::GREEDY_EXP)) }
;
terminal
: symbol
| literal
| slash
| dot
;
slash
: SLASH { Slash.new(val.first) }
;
symbol
: SYMBOL { Symbol.new(val.first) }
;
literal
: LITERAL { Literal.new(val.first) }
;
dot
: DOT { Dot.new(val.first) }
;
end
---- header
# :stopdoc:
require "action_dispatch/journey/parser_extras"