Permalink
Browse files

Update grammar to start with QueryUnit instead of query, and make Que…

…ry optional, to allow for empty input.
  • Loading branch information...
1 parent f288075 commit d56977670457de3ed1c87cf2d822d51c1a8b6c33 @gkellogg gkellogg committed Apr 3, 2013
Showing with 32 additions and 19 deletions.
  1. +2 −2 Rakefile
  2. +1 −1 etc/sparql11.bnf
  3. +4 −3 etc/sparql11.ll1.sxp
  4. +1 −1 etc/sparql11.sxp
  5. +13 −2 lib/sparql/grammar/meta.rb
  6. +1 −2 lib/sparql/grammar/parser11.rb
  7. +10 −8 spec/grammar/parser_spec.rb
View
@@ -62,7 +62,7 @@ task :meta => "lib/sparql/grammar/meta.rb"
file "lib/sparql/grammar/meta.rb" => "etc/sparql11.bnf" do |t|
sh %{
- ebnf --ll1 Query --format rb \
+ ebnf --ll1 QueryUnit --format rb \
--mod-name SPARQL::Grammar::Meta \
--output lib/sparql/grammar/meta.rb \
etc/sparql11.bnf
@@ -71,7 +71,7 @@ end
file "etc/sparql11.ll1.sxp" => "etc/sparql11.bnf" do |t|
sh %{
- ebnf --ll1 Query --format sxp \
+ ebnf --ll1 QueryUnit --format sxp \
--output etc/sparql11.ll1.sxp \
etc/sparql11.bnf
}
View
@@ -1,6 +1,6 @@
# SPARQL 1.1 Grammar
- [1] QueryUnit ::= Query
+ [1] QueryUnit ::= Query?
[2] Query ::= Prologue
( SelectQuery | ConstructQuery | DescribeQuery | AskQuery )
ValuesClause
View
@@ -1,10 +1,11 @@
(
(rule _empty "0" (first _eps) (seq))
(rule QueryUnit "1"
- (first "ASK" "BASE" "CONSTRUCT" "DESCRIBE" "PREFIX" "SELECT")
- (seq Query))
- (rule Query "2"
(start #t)
+ (first "ASK" "BASE" "CONSTRUCT" "DESCRIBE" "PREFIX" "SELECT" _eps)
+ (follow _eof)
+ (alt _empty Query))
+ (rule Query "2"
(first "ASK" "BASE" "CONSTRUCT" "DESCRIBE" "PREFIX" "SELECT")
(follow _eof)
(seq Prologue _Query_1 ValuesClause))
View
@@ -1,6 +1,6 @@
(
(rule _empty "0" (seq))
- (rule QueryUnit "1" (seq Query))
+ (rule QueryUnit "1" (alt _empty Query))
(rule Query "2" (seq Prologue _Query_1 ValuesClause))
(rule _Query_1 "2.1" (alt SelectQuery ConstructQuery DescribeQuery AskQuery))
(rule UpdateUnit "3" (seq Update))
View
@@ -1,7 +1,7 @@
-# This file is automatically generated by /Users/gregg/.rvm/gems/ruby-1.9.3-p392/bundler/gems/ebnf-cd313e5f46b4/bin/ebnf
+# This file is automatically generated by /Users/gregg/.rvm/gems/ruby-1.9.3-p392/bundler/gems/ebnf-92bb7ca4b9c0/bin/ebnf
# BRANCH derived from etc/sparql11.bnf
module SPARQL::Grammar::Meta
- START = :Query
+ START = :QueryUnit
BRANCH = {
:AdditiveExpression => {
@@ -4327,6 +4327,14 @@ module SPARQL::Grammar::Meta
"PREFIX" => [:Prologue, :_Query_1, :ValuesClause],
"SELECT" => [:Prologue, :_Query_1, :ValuesClause],
},
+ :QueryUnit => {
+ "ASK" => [:Query],
+ "BASE" => [:Query],
+ "CONSTRUCT" => [:Query],
+ "DESCRIBE" => [:Query],
+ "PREFIX" => [:Query],
+ "SELECT" => [:Query],
+ },
:_Query_1 => {
"ASK" => [:AskQuery],
"CONSTRUCT" => [:ConstructQuery],
@@ -13832,6 +13840,7 @@ module SPARQL::Grammar::Meta
"BASE",
"PREFIX"],
:QueryUnit => [
+ :_eps,
"CONSTRUCT",
"DESCRIBE",
"ASK",
@@ -40459,6 +40468,8 @@ module SPARQL::Grammar::Meta
"GRAPH"],
:Query => [
:_eof],
+ :QueryUnit => [
+ :_eof],
:_Query_1 => [
"VALUES",
:_eof],
@@ -1043,8 +1043,7 @@ def to_s
def parse(prod = START)
ll1_parse(@input, prod.to_sym, @options.merge(:branch => BRANCH,
:first => FIRST,
- :follow => FOLLOW)
- ) {}
+ :follow => FOLLOW))
# The last thing on the @prod_data stack is the result
@result = case
@@ -705,10 +705,18 @@ def bgp_patterns
include ProductionRequirements
include ProductionExamples
- describe "when matching the [2] Query production rule" do
- with_production(:Query) do |production|
+ describe "when matching the [1] QueryUnit production rule" do
+ with_production(:QueryUnit) do |production|
it_ignores_empty_input_using production
+ given_it_generates(production, "SELECT * FROM <a> WHERE {?a ?b ?c}", %q((dataset (<a>) (bgp (triple ?a ?b ?c)))))
+ given_it_generates(production, "CONSTRUCT {?a ?b ?c} WHERE {?a ?b ?c FILTER (?a)}", %q((construct ((triple ?a ?b ?c)) (filter ?a (bgp (triple ?a ?b ?c))))))
+ given_it_generates(production, "DESCRIBE * FROM <a> WHERE {?a ?b ?c}", %q((describe () (dataset (<a>) (bgp (triple ?a ?b ?c))))))
+ given_it_generates(production, "ASK WHERE {GRAPH <a> {?a ?b ?c}}", %q((ask (graph <a> (bgp (triple ?a ?b ?c))))))
+ end
+ end
+ describe "when matching the [2] Query production rule" do
+ with_production(:Query) do |production|
{
"BASE <foo/> SELECT * WHERE { <a> <b> <c> }" =>
%q((base <foo/> (bgp (triple <a> <b> <c>)))),
@@ -937,7 +945,6 @@ def bgp_patterns
describe "when matching the [13] DatasetClause production rule" do
with_production(:DatasetClause) do |production|
- it_ignores_empty_input_using production
given_it_generates(production, %q(FROM <http://example.org/foaf/aliceFoaf>), [:dataset, RDF::URI("http://example.org/foaf/aliceFoaf")])
given_it_generates(production, %q(FROM NAMED <http://example.org/foaf/aliceFoaf>), [:dataset, [:named, RDF::URI("http://example.org/foaf/aliceFoaf")]])
end
@@ -949,8 +956,6 @@ def bgp_patterns
# [16] SourceSelector
describe "when matching the [17] WhereClause production rule" do
with_production(:WhereClause) do |production|
- it_ignores_empty_input_using production
-
bgp_patterns.each_pair do |input, result|
given_it_generates(production, "WHERE {#{input}}", result,
:prefixes => {nil => "http://example.com/", :rdf => RDF.to_uri.to_s},
@@ -1238,7 +1243,6 @@ def bgp_patterns
# [69] Constraint ::= BrackettedExpression | BuiltInCall | FunctionCall
describe "when matching the [69] Constraint production rule" do
with_production(:Constraint) do |production|
- it_ignores_empty_input_using production
it_recognizes_bracketted_expression_using production
it_recognizes_built_in_call_using production
it_recognizes_function_using production
@@ -1341,8 +1345,6 @@ def bgp_patterns
describe "when matching the [108] Var production rule" do
with_production(:Var) do |production|
- it_ignores_empty_input_using production
-
it "recognizes the VAR1 terminal" do
it_recognizes_var1(production)
end

0 comments on commit d569776

Please sign in to comment.