提交 56f734a3 编写于 作者: A Aaron Patterson

pull RegexpOffsets in to a method

we don't really need this visitor
上级 15bc6b63
......@@ -59,31 +59,6 @@ def optional_names
}.map(&:name).uniq
end
class RegexpOffsets < Journey::Visitors::Visitor # :nodoc:
attr_reader :offsets
def initialize(matchers)
@matchers = matchers
@capture_count = [0]
end
def visit(node)
super
@capture_count
end
def visit_SYMBOL(node)
node = node.to_sym
if @matchers.key?(node)
re = /#{@matchers[node]}|/
@capture_count.push((re.match('').length - 1) + (@capture_count.last || 0))
else
@capture_count << (@capture_count.last || 0)
end
end
end
class AnchoredRegexp < Journey::Visitors::Visitor # :nodoc:
def initialize(separator, matchers)
@separator = separator
......@@ -193,8 +168,20 @@ def regexp_visitor
def offsets
return @offsets if @offsets
viz = RegexpOffsets.new(@requirements)
@offsets = viz.accept(spec)
@offsets = [0]
spec.find_all(&:symbol?).each do |node|
node = node.to_sym
if @requirements.key?(node)
re = /#{@requirements[node]}|/
@offsets.push((re.match('').length - 1) + @offsets.last)
else
@offsets << @offsets.last
end
end
@offsets
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册