提交 ee47e34d 编写于 作者: R Ronak Jangir

used predicate methods to avoid is_a? checks

上级 30bacc26
......@@ -42,6 +42,7 @@ def literal?; false; end
def terminal?; false; end
def star?; false; end
def cat?; false; end
def group?; false; end
end
class Terminal < Node # :nodoc:
......@@ -95,6 +96,7 @@ def children; [left] end
class Group < Unary # :nodoc:
def type; :GROUP; end
def group?; true; end
end
class Star < Unary # :nodoc:
......
......@@ -46,7 +46,7 @@ def ast
end
def names
@names ||= spec.grep(Nodes::Symbol).map(&:name)
@names ||= spec.find_all(&:symbol?).map(&:name)
end
def required_names
......@@ -54,8 +54,8 @@ def required_names
end
def optional_names
@optional_names ||= spec.grep(Nodes::Group).flat_map { |group|
group.grep(Nodes::Symbol)
@optional_names ||= spec.find_all(&:group?).flat_map { |group|
group.find_all(&:symbol?)
}.map(&:name).uniq
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册