Adds Selection::default and use it in the parser

pull/10/head
Tpt 6 years ago
parent b733435203
commit 9e0bd6470a
  1. 9
      src/sparql/parser.rs
  2. 27
      src/sparql/sparql_grammar.rustpeg

@ -165,6 +165,15 @@ mod grammar {
pub variables: Option<Vec<SelectionMember>>, pub variables: Option<Vec<SelectionMember>>,
} }
impl Default for Selection {
fn default() -> Self {
Self {
option: SelectionOption::Default,
variables: None,
}
}
}
fn build_select( fn build_select(
select: Selection, select: Selection,
wher: MultiSetPattern, wher: MultiSetPattern,

@ -74,21 +74,18 @@ ConstructQuery -> Query =
Query::ConstructQuery { Query::ConstructQuery {
construct: c, construct: c,
dataset: d, dataset: d,
algebra: build_select(Selection { algebra: build_select(Selection::default(), w, h, o, l, v)
option: SelectionOption::Reduced,
variables: None
}, w, h, o, l, v)
} }
} / } /
"CONSTRUCT"i _ d:DatasetClauses _ "WHERE"i _ '{' _ c:ConstructQuery_optional_triple_template _ '}' _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause { "CONSTRUCT"i _ d:DatasetClauses _ "WHERE"i _ '{' _ c:ConstructQuery_optional_triple_template _ '}' _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause {
Query::ConstructQuery { Query::ConstructQuery {
construct: c.clone(), construct: c.clone(),
dataset: d, dataset: d,
algebra: build_select(Selection { algebra: build_select(
option: SelectionOption::Reduced, Selection::default(),
variables: None MultiSetPattern::BGP(c.into_iter().map(|p| TripleOrPathPattern::from(p)).collect()).into(),
}, MultiSetPattern::BGP(c.into_iter().map(|p| TripleOrPathPattern::from(p)).collect()).into(), h, o, l, v
h, o, l, v) )
} }
} }
@ -99,17 +96,14 @@ DescribeQuery -> Query =
"DESCRIBE"i _ '*' _ d:DatasetClauses w:WhereClause? _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause { "DESCRIBE"i _ '*' _ d:DatasetClauses w:WhereClause? _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause {
Query::DescribeQuery { Query::DescribeQuery {
dataset: d, dataset: d,
algebra: build_select(Selection { algebra: build_select(Selection::default(), w.unwrap_or_else(MultiSetPattern::default), h, o, l, v)
option: SelectionOption::Reduced,
variables: None
}, w.unwrap_or_else(MultiSetPattern::default), h, o, l, v)
} }
} / } /
"DESCRIBE"i _ p:DescribeQuery_item+ _ d:DatasetClauses w:WhereClause? _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause { "DESCRIBE"i _ p:DescribeQuery_item+ _ d:DatasetClauses w:WhereClause? _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause {
Query::DescribeQuery { Query::DescribeQuery {
dataset: d, dataset: d,
algebra: build_select(Selection { algebra: build_select(Selection {
option: SelectionOption::Reduced, option: SelectionOption::Default,
variables: Some(p.into_iter().map(|var_or_iri| match var_or_iri { variables: Some(p.into_iter().map(|var_or_iri| match var_or_iri {
NamedNodeOrVariable::NamedNode(n) => SelectionMember::Expression(n.into(), Variable::default()), NamedNodeOrVariable::NamedNode(n) => SelectionMember::Expression(n.into(), Variable::default()),
NamedNodeOrVariable::Variable(v) => SelectionMember::Variable(v) NamedNodeOrVariable::Variable(v) => SelectionMember::Variable(v)
@ -123,10 +117,7 @@ DescribeQuery_item -> NamedNodeOrVariable = i:VarOrIri _ { i }
AskQuery -> Query = "ASK"i _ d:DatasetClauses w:WhereClause _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause { AskQuery -> Query = "ASK"i _ d:DatasetClauses w:WhereClause _ GroupClause? _ h:HavingClause? _ o:OrderClause? _ l:LimitOffsetClauses? _ v:ValuesClause {
Query::AskQuery { Query::AskQuery {
dataset: d, dataset: d,
algebra: build_select(Selection { algebra: build_select(Selection::default(), w, h, o, l, v)
option: SelectionOption::Reduced,
variables: None
}, w, h, o, l, v)
} }
} }

Loading…
Cancel
Save