lib/ebnf/rule.rb in ebnf-0.1.0 vs lib/ebnf/rule.rb in ebnf-0.2.0

- old
+ new

@@ -184,17 +184,23 @@ # expr starts with alt and contains that sym, or # expr starts with seq and the next element is that sym # @param [Symbol, class] sym # Symbol matching any start element, or if it is String, any start element which is a String # @return [Array<Symbol, String>] list of symbol (singular), or strings which are start symbol, or nil if there are none - def starts_with(sym) + def starts_with?(sym) if seq? && sym === (v = expr.fetch(1, nil)) [v] elsif alt? && expr.any? {|e| sym === e} expr.select {|e| sym === e} else nil end + end + + # Do the firsts of this rule include the empty string? + # @return [Boolean] + def first_includes_eps? + @first && @first.include?(:_eps) end # Add terminal as proceding this rule # @param [Array<Rule>] terminals # @return [Integer] if number of terminals added \ No newline at end of file