diff --git a/lib/ebnf/native.rb b/lib/ebnf/native.rb index 54cf77d..512cef2 100644 --- a/lib/ebnf/native.rb +++ b/lib/ebnf/native.rb @@ -288,11 +288,11 @@ def terminal(s) case m = s[0,1] when '"', "'" # STRING1 or STRING2 l, s = s[1..-1].split(m.rstrip, 2) - [Unescape.unescape_string(l).tap {|str| str.quote_style = (m == "'" ? :squote : :dquote)}, s] + [Unescape.unescape(l).tap {|str| str.quote_style = (m == "'" ? :squote : :dquote)}, s] when '[' # RANGE, O_RANGE # Includes RANGE and O_RANGE which can't include a ']' l, s = s[1..-1].split(']', 2) - [[:range, Unescape.unescape_string(l)], s] + [[:range, Unescape.unescape(l)], s] when '#' # HEX s.match(/(#x\h+)(.*)$/) l, s = $1, $2 diff --git a/lib/ebnf/unescape.rb b/lib/ebnf/unescape.rb index e501608..9523942 100644 --- a/lib/ebnf/unescape.rb +++ b/lib/ebnf/unescape.rb @@ -48,7 +48,7 @@ def unescape_codepoints(string) # @return [String] # @see https://www.w3.org/TR/rdf-sparql-query/#grammarEscapes def unescape_string(input) - input.gsub(ECHAR) { |escaped| ESCAPE_CHARS[escaped] || escaped[1..-1]} + input.gsub(ECHAR) {|escaped| ESCAPE_CHARS[escaped] || escaped} end module_function :unescape_string diff --git a/spec/native_spec.rb b/spec/native_spec.rb index 87e5497..7fd612c 100644 --- a/spec/native_spec.rb +++ b/spec/native_spec.rb @@ -42,6 +42,12 @@ UCHAR)) '>')))}, ], + "UCHAR": [ + %(UCHAR ::= ( '\\u' HEX HEX HEX HEX ) | ( '\\U' HEX HEX HEX HEX HEX HEX HEX HEX )), + %{( + (terminal UCHAR + (alt (seq '\\\\u' HEX HEX HEX HEX) (seq '\\\\U' HEX HEX HEX HEX HEX HEX HEX HEX))) )} + ] }.each do |title, (input, expect)| it title do expect(parse(input).to_sxp).to produce(expect, logger)