1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #39925 from composerinteralia/set-star-regexp-on-initialize

Build symbols descending from stars with regexp
This commit is contained in:
Eugene Kenny 2020-07-25 09:52:42 +01:00 committed by GitHub
commit de2520718f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 26 deletions

View file

@ -79,9 +79,10 @@ module ActionDispatch
attr_reader :name
DEFAULT_EXP = /[^\.\/\?]+/
def initialize(left)
super
@regexp = DEFAULT_EXP
GREEDY_EXP = /(.+)/
def initialize(left, regexp = DEFAULT_EXP)
super(left)
@regexp = regexp
@name = -left.tr("*:", "")
end

View file

@ -1,10 +1,10 @@
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.14
# This file is automatically generated by Racc 1.4.16
# from Racc grammar file "".
#
require "racc/parser.rb"
require 'racc/parser.rb'
# :stopdoc:
@ -135,11 +135,11 @@ Racc_debug_parser = false
# reduce 0 omitted
def _reduce_1(val, _values)
Cat.new(val.first, val.last)
Cat.new(val.first, val.last)
end
def _reduce_2(val, _values)
val.first
val.first
end
# reduce 3 omitted
@ -151,19 +151,19 @@ end
# reduce 6 omitted
def _reduce_7(val, _values)
Group.new(val[1])
Group.new(val[1])
end
def _reduce_8(val, _values)
Or.new([val.first, val.last])
Or.new([val.first, val.last])
end
def _reduce_9(val, _values)
Or.new([val.first, val.last])
Or.new([val.first, val.last])
end
def _reduce_10(val, _values)
Star.new(Symbol.new(val.last))
Star.new(Symbol.new(val.last, Symbol::GREEDY_EXP))
end
# reduce 11 omitted
@ -175,19 +175,19 @@ end
# reduce 14 omitted
def _reduce_15(val, _values)
Slash.new(val.first)
Slash.new(val.first)
end
def _reduce_16(val, _values)
Symbol.new(val.first)
Symbol.new(val.first)
end
def _reduce_17(val, _values)
Literal.new(val.first)
Literal.new(val.first)
end
def _reduce_18(val, _values)
Dot.new(val.first)
Dot.new(val.first)
end
def _reduce_none(val, _values)
@ -195,5 +195,5 @@ def _reduce_none(val, _values)
end
end # class Parser
end # module Journey
end # module ActionDispatch
end # module Journey
end # module ActionDispatch

View file

@ -21,7 +21,7 @@ rule
| expression OR or { Or.new([val.first, val.last]) }
;
star
: STAR { Star.new(Symbol.new(val.last)) }
: STAR { Star.new(Symbol.new(val.last, Symbol::GREEDY_EXP)) }
;
terminal
: symbol

View file

@ -41,14 +41,9 @@ module ActionDispatch
end
def ast
@spec.each do |node|
if node.symbol?
re = @requirements[node.to_sym]
node.regexp = re if re
elsif node.star?
node = node.left
node.regexp = @requirements[node.to_sym] || /(.+)/
end
@spec.find_all(&:symbol?).each do |node|
re = @requirements[node.to_sym]
node.regexp = re if re
end
@spec