ruby-rdf / sparql

Ruby SPARQL library
http://rubygems.org/gems/sparql
The Unlicense
88 stars 14 forks source link

Parser fails on empty `values` group #32

Closed Richard-Degenne closed 6 years ago

Richard-Degenne commented 6 years ago

Hi,

Considering the following valid SPARQL query:

require 'sparql'

query = SPARQL.parse(<<~QUERY)
  SELECT * WHERE {
      ?s ?p ?o
      VALUES ?s { } # Notice the empty values list
  }
QUERY

The parser fails with the following error.

NoMethodError: undefined method `each' for nil:NilClass
    from /home/richard/dev/.bundle/gems/sparql-2.2.2/lib/sparql/grammar/parser11.rb:706:in `block in <class:Parser>'
    from /home/richard/dev/.bundle/gems/ebnf-1.1.1/lib/ebnf/ll1/parser.rb:600:in `block in onFinish'
    from /home/richard/dev/.bundle/gems/ebnf-1.1.1/lib/ebnf/ll1/parser.rb:118:in `block in eval_with_binding'
    from /home/richard/dev/.bundle/gems/ebnf-1.1.1/lib/ebnf/ll1/parser.rb:118:in `instance_eval'
    from /home/richard/dev/.bundle/gems/ebnf-1.1.1/lib/ebnf/ll1/parser.rb:118:in `eval_with_binding'
    from /home/richard/dev/.bundle/gems/ebnf-1.1.1/lib/ebnf/ll1/parser.rb:599:in `onFinish'
    from /home/richard/dev/.bundle/gems/ebnf-1.1.1/lib/ebnf/ll1/parser.rb:402:in `parse'
    from /home/richard/dev/.bundle/gems/sparql-2.2.2/lib/sparql/grammar/parser11.rb:1525:in `parse'
    from /home/richard/dev/.bundle/gems/sparql-2.2.2/lib/sparql.rb:32:in `parse'

This is caused by the values list being empty, as you can see given the following counter-example:

require 'sparql'

query = SPARQL.parse(<<~QUERY)
  SELECT * WHERE {
      ?s ?p ?o
      VALUES ?s { <http://www.example.com> }
  }
QUERY
=> #<SPARQL::Algebra::Operator::Join:0x12f0b38(((bgp (triple ?s ?p ?o)) (table (vars ?s) (row (?s <http://www.example.com>)))) )>