lib/treetop/runtime/compiled_parser.rb in treetop-1.5.1 vs lib/treetop/runtime/compiled_parser.rb in treetop-1.5.3
- old
+ new
@@ -92,18 +92,18 @@
end
end
def has_terminal?(terminal, mode, index)
case mode
- when :regexp # A Regexp has been passed in, probably a character class
- input.index(terminal, index) == index
+ when :regexp # A Regexp has been passed in, either a character class or a literel regex 'foo'r
+ (terminal =~ input[index..-1]) == 0 && $&.length
when false # The terminal is a string which must match exactly
- input[index, terminal.size] == terminal
+ input[index, terminal.size] == terminal && terminal.size
when :insens # The terminal is a downcased string which must match input downcased
- input[index, terminal.size].downcase == terminal
+ input[index, terminal.size].downcase == terminal && terminal.size
when true # Only occurs with old compiled grammars, for character classes
rx = @regexps[terminal] ||= Regexp.new(terminal)
- input.index(rx, index) == index
+ input.index(rx, index) == index && $&.length
end
end
def terminal_parse_failure(expected_string)
return nil if index < max_terminal_failure_index