Skip to content

Commit

Permalink
Change reifiedTriple to use subject and object productions instead of…
Browse files Browse the repository at this point in the history
… ttSubject and ttObject.
  • Loading branch information
gkellogg committed Aug 4, 2024
1 parent 7ac9eae commit 430c874
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion etc/turtle.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ iri ::= IRIREF | PrefixedName
PrefixedName ::= PNAME_LN | PNAME_NS
BlankNode ::= BLANK_NODE_LABEL | ANON
reifier ::= '~' (iri | BlankNode)?
reifiedTriple ::= '<<' ttSubject predicate ttObject reifier* '>>'
reifiedTriple ::= '<<' (subject | reifiedTriple) predicate object reifier* '>>'
tripleTerm ::= '<<(' ttSubject predicate ttObject ')>>'
ttSubject ::= iri | BlankNode
ttObject ::= iri | BlankNode | literal | tripleTerm
Expand Down
6 changes: 3 additions & 3 deletions lib/rdf/turtle/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,17 @@ def read_object(subject = nil, predicate = nil)
##
# Read reifiedTriple
#
# reifiedTriple ::= '<<' ttSubject predicate ttObject reifier? '>>'
# reifiedTriple ::= '<<' (subject | reifiedTriple) predicate object reifier* '>>'
#
# @return [RDF::Term]
def read_reifiedTriple
return unless @options[:rdfstar]
if @lexer.first.value == '<<'
prod(:reifiedTriple) do
@lexer.shift # eat <<
subject = read_ttSubject || error("Failed to parse subject", production: :reifiedTriple, token: @lexer.first)
subject = read_ttSubject || read_reifiedTriple || error("Failed to parse subject", production: :reifiedTriple, token: @lexer.first)
predicate = read_verb || error("Failed to parse predicate", production: :reifiedTriple, token: @lexer.first)
object = read_ttObject || error("Failed to parse object", production: :reifiedTriple, token: @lexer.first)
object = read_object || error("Failed to parse object", production: :reifiedTriple, token: @lexer.first)
tt = RDF::Statement(subject, predicate, object, tripleTerm: true)

# An optional reifier. If not specified it is a new blank node.
Expand Down
2 changes: 1 addition & 1 deletion script/tc
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def run_tc(tc, **options)
begin
graph << reader
rescue Exception => e
#require 'byebug'; byebug
STDERR.puts "Unexpected exception: #{e.inspect}" if options[:verbose]
result = "failed"
end
else
begin
graph << reader
raise RDF::ReaderError, "triple term" if graph.statements.any? {|s| s.to_a.any?(&:statement?)}
STDERR.puts "Expected exception" if options[:verbose]
result = "failed"
rescue RDF::ReaderError
Expand Down
2 changes: 0 additions & 2 deletions spec/ntriples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
else
expect {
graph << reader
raise RDF::ReaderError, "triple term" if graph.statements.any? {|s| s.to_a.any?(&:statement?)}
#expect(graph.dump(:ntriples).should produce("", t.debug)
}.to raise_error RDF::ReaderError
end

Expand Down
6 changes: 5 additions & 1 deletion spec/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,11 @@
ex:p1 ex:o1 >>
ex:p ex:o .
),
RDF::ReaderError
%(
_:anon1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(<http://example/s2> <http://example/p2> <http://example/o2>)>> .
_:anon2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(_:anon1 <http://example/p1> <http://example/o1>)>> .
_:anon2 <http://example/p> <http://example/o> .
)
],
"IRI identifier": [
%(
Expand Down

0 comments on commit 430c874

Please sign in to comment.