Skip to content

Commit ed9bfa0

Browse files
committed
Unescape codepoints in input rather than on terminals.
Automatically skip missing test manifests.
1 parent 65833fc commit ed9bfa0

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

lib/sparql/grammar/parser.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Parser
4141
terminal(:BLANK_NODE_LABEL, BLANK_NODE_LABEL) do |value, prod|
4242
bnode(value[2..-1])
4343
end
44-
terminal(:IRIREF, IRIREF, unescape: true) do |value, prod|
44+
terminal(:IRIREF, IRIREF) do |value, prod|
4545
begin
4646
iri(value[1..-2])
4747
rescue ArgumentError => e
@@ -2666,8 +2666,8 @@ class Parser
26662666
# @return [SPARQL::Grammar::Parser]
26672667
def initialize(input = nil, **options, &block)
26682668
@input = case input
2669-
when IO, StringIO then input.read
2670-
else input.to_s.dup
2669+
when IO, StringIO then EBNF::Unescape.unescape_codepoints(input.read)
2670+
else EBNF::Unescape.unescape_codepoints(input.to_s)
26712671
end
26722672
@input.encode!(Encoding::UTF_8) if @input.respond_to?(:encode!)
26732673
@options = {anon_base: "b0", validate: false}.merge(options)

lib/sparql/grammar/terminals.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module Terminals
1515
U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
1616
IRI_RANGE = Regexp.compile("[[^<>\"{}|^`\\\\]&&[^\\x00-\\x20]]").freeze
1717

18-
# 26
19-
UCHAR = EBNF::Unescape::UCHAR
2018
# 170s
2119
PERCENT = /%[0-9A-Fa-f]{2}/.freeze
2220
# 172s
@@ -43,7 +41,7 @@ module Terminals
4341
# 149
4442
ECHAR = /\\[tbnrf\\"']/.freeze
4543
# 18
46-
IRIREF = /<(?:#{IRI_RANGE}|#{UCHAR})*>/.freeze
44+
IRIREF = /<(?:#{IRI_RANGE})*>/.freeze
4745
# 129
4846
PNAME_NS = /#{PN_PREFIX}?:/.freeze
4947
# 130
@@ -76,13 +74,13 @@ module Terminals
7674
# 143
7775
DOUBLE_NEGATIVE = /(\-)([0-9]+\.[0-9]*#{EXPONENT}|\.?[0-9]+#{EXPONENT})/.freeze
7876
# 145
79-
STRING_LITERAL1 = /'([^\'\\\n\r]|#{ECHAR}|#{UCHAR})*'/.freeze
77+
STRING_LITERAL1 = /'([^\'\\\n\r]|#{ECHAR})*'/.freeze
8078
# 146
81-
STRING_LITERAL2 = /"([^\"\\\n\r]|#{ECHAR}|#{UCHAR})*"/.freeze
79+
STRING_LITERAL2 = /"([^\"\\\n\r]|#{ECHAR})*"/.freeze
8280
# 147
83-
STRING_LITERAL_LONG1 = /'''((?:'|'')?(?:[^'\\]|#{ECHAR}|#{UCHAR}))*'''/m.freeze
81+
STRING_LITERAL_LONG1 = /'''((?:'|'')?(?:[^'\\]|#{ECHAR}))*'''/m.freeze
8482
# 148
85-
STRING_LITERAL_LONG2 = /"""((?:"|"")?(?:[^"\\]|#{ECHAR}|#{UCHAR}))*"""/m.freeze
83+
STRING_LITERAL_LONG2 = /"""((?:"|"")?(?:[^"\\]|#{ECHAR}))*"""/m.freeze
8684

8785
# 151
8886
WS = /(?:\s|(?:#[^\n\r]*))+/m.freeze

script/tc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def run_tc(tc, **options)
4747

4848
id = tc.attributes['id'].
4949
sub('http://www.w3.org/2001/sw/DataAccess/tests/', '').
50-
sub('http://www.w3.org/2009/sparql/docs/tests/', '').
51-
sub('https://w3c.github.io/rdf-star/tests/', '').
50+
sub('https://www.w3.org/2009/sparql/docs/tests/', '').
51+
sub('https://w3c.github.io/rdf-tests/sparql/', '').
5252
sub('https://w3c.github.io/sparql-12/tests/', '')
5353
STDERR.write "run #{id}" unless options[:quiet]
5454

@@ -413,6 +413,8 @@ manifests.each do |path|
413413
run_tc(tc, **options)
414414
end
415415
end
416+
rescue IOError => e
417+
STDERR.puts "skip #{path}: IOError"
416418
end
417419

418420
STDERR.puts "" if options[:quiet]

spec/suite_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def self.sparql_11_tests
226226
end
227227

228228
def self.sparql_12_tests
229-
%w(grouping syntax-triple-terms-negative syntax-triple-terms-positive).map do |partial|
229+
%w(grouping syntax-escaping syntax-triple-terms-negative syntax-triple-terms-positive).map do |partial|
230230
"#{BASE}sparql12/#{partial}/manifest.ttl"
231231
end
232232
end

spec/suite_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@
278278
it_behaves_like "SUITE", man.attributes['id'], man.label, man.comment, man.entries
279279
it_behaves_like "to_sparql", man.attributes['id'], man.label, man.comment, man.entries
280280
end
281+
rescue IOError => e
282+
skip(e.message)
281283
end
282284
end
283285

@@ -287,6 +289,8 @@
287289
it_behaves_like "SUITE", man.attributes['id'], man.label, man.comment, man.entries
288290
it_behaves_like "to_sparql", man.attributes['id'], man.label, man.comment, man.entries
289291
end
292+
rescue IOError => e
293+
skip(e.message)
290294
end
291295
end
292296
end unless ENV['CI']

0 commit comments

Comments
 (0)