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>>,
}
impl Default for Selection {
fn default() -> Self {
Self {
option: SelectionOption::Default,
variables: None,
}
}
}
fn build_select(
select: Selection,
wher: MultiSetPattern,

@ -74,21 +74,18 @@ ConstructQuery -> Query =
Query::ConstructQuery {
construct: c,
dataset: d,
algebra: build_select(Selection {
option: SelectionOption::Reduced,
variables: None
}, w, h, o, l, v)
algebra: build_select(Selection::default(), 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 {
Query::ConstructQuery {
construct: c.clone(),
dataset: d,
algebra: build_select(Selection {
option: SelectionOption::Reduced,
variables: None
}, MultiSetPattern::BGP(c.into_iter().map(|p| TripleOrPathPattern::from(p)).collect()).into(),
h, o, l, v)
algebra: build_select(
Selection::default(),
MultiSetPattern::BGP(c.into_iter().map(|p| TripleOrPathPattern::from(p)).collect()).into(),
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 {
Query::DescribeQuery {
dataset: d,
algebra: build_select(Selection {
option: SelectionOption::Reduced,
variables: None
}, w.unwrap_or_else(MultiSetPattern::default), h, o, l, v)
algebra: build_select(Selection::default(), 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 {
Query::DescribeQuery {
dataset: d,
algebra: build_select(Selection {
option: SelectionOption::Reduced,
option: SelectionOption::Default,
variables: Some(p.into_iter().map(|var_or_iri| match var_or_iri {
NamedNodeOrVariable::NamedNode(n) => SelectionMember::Expression(n.into(), Variable::default()),
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 {
Query::AskQuery {
dataset: d,
algebra: build_select(Selection {
option: SelectionOption::Reduced,
variables: None
}, w, h, o, l, v)
algebra: build_select(Selection::default(), w, h, o, l, v)
}
}

Loading…
Cancel
Save