Skip to content

Commit

Permalink
Fix native parsing of RANGE containing a backslash.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jun 2, 2023
1 parent 16dadca commit 5685540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/ebnf/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ def terminal(s)
l, s = s[1..-1].split(m.rstrip, 2)
[Unescape.unescape_string(l), s]
when '[' # RANGE, O_RANGE
l, s = s[1..-1].split(/(?<=[^\\])\]/, 2)
# Includes RANGE and O_RANGE which can't include a ']'
l, s = s[1..-1].split(']', 2)
[[:range, Unescape.unescape_string(l)], s]
when '#' # HEX
s.match(/(#x\h+)(.*)$/)
Expand Down
4 changes: 4 additions & 0 deletions spec/writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
%{[2] Prolog ::= BaseDecl? PrefixDecl*},
%{[2] Prolog ::= BaseDecl? PrefixDecl*\n}
],
backslash: [
%{LHS ::= [^'\] | ECHAR},
%{LHS ::= [^'\] | ECHAR\n}
]
}.each do |title, (grammar, plain)|
context title do
subject {EBNF::Base.new(grammar, format: :native).ast}
Expand Down

0 comments on commit 5685540

Please sign in to comment.