Skip to content

Commit

Permalink
Add some missing unscans to PEG rule parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Oct 13, 2024
1 parent 38832ac commit 27d6ed2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/ebnf/peg/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/ebnf/peg/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 27d6ed2

Please sign in to comment.