diff --git a/lib/ebnf/peg/parser.rb b/lib/ebnf/peg/parser.rb index 704e333..3371d72 100644 --- a/lib/ebnf/peg/parser.rb +++ b/lib/ebnf/peg/parser.rb @@ -91,8 +91,7 @@ def terminal(term, regexp = nil, **options, &block) ## # Defines a production called at the beggining of a particular production - # with data from previous production along with data defined for the - # current production. Block is called in an evaluation block from + # with data from previous production. Block is called in an evaluation block from # the enclosing parser. # # @param [Symbol] term diff --git a/lib/ebnf/peg/rule.rb b/lib/ebnf/peg/rule.rb index 2ff7fc5..8492ba7 100644 --- a/lib/ebnf/peg/rule.rb +++ b/lib/ebnf/peg/rule.rb @@ -89,6 +89,7 @@ def parse(input, **options) when String # If the input matches any terminal, then it can't be treated as a string if matched = parser.class.terminal_regexps.detect {|sym, re| input.scan(re)} + input.unscan # Reset scan position :unmatched else s = input.scan(Regexp.new(Regexp.quote(prod), string_regexp_opts)) @@ -136,6 +137,7 @@ def parse(input, **options) rule.parse(input, **options) when String if matched = parser.class.terminal_regexps.detect {|sym, re| input.scan(re)} + input.unscan # Reset scan position :unmatched else s = input.scan(Regexp.new(Regexp.quote(prod), string_regexp_opts)) @@ -194,6 +196,7 @@ def parse(input, **options) rule.parse(input, **options.merge(_rept_data: accumulator)) when String if matched = parser.class.terminal_regexps.detect {|sym, re| input.scan(re)} + input.unscan # Reset scan position :unmatched else s = input.scan(Regexp.new(Regexp.quote(prod), string_regexp_opts))