Skip to content

Commit

Permalink
340/80 with stems and exclusions implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
labra committed Nov 26, 2023
1 parent 90bbe5b commit 82c8227
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/sample_parser.shex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<http://a.example/S1> {
<http://a.example/p1> ["v"~ - "v1"]
<S> {
<p> [. - "v1" - "v2" ]
}
5 changes: 1 addition & 4 deletions shex_ast/src/ast/lang_or_wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use super::serde_string_or_struct::SerializeStringOrStruct;
#[serde(untagged)]
pub enum LangOrWildcard {
Lang(Lang),
Wildcard {
#[serde(rename = "type")]
type_: String,
},
Wildcard,
}

impl FromStr for LangOrWildcard {
Expand Down
51 changes: 26 additions & 25 deletions shex_compact/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ use nom::{
};
use shex_ast::{
object_value::ObjectValue, value_set_value::ValueSetValue, Annotation, NodeConstraint,
Ref, SemAct, Shape, ShapeExpr, TripleExpr, XsFacet, NodeKind, NumericFacet, Pattern, StringFacet, TripleExprLabel, BNode, LiteralExclusion, IriExclusion, LanguageExclusion, Exclusion,
Ref, SemAct, Shape, ShapeExpr, TripleExpr, XsFacet, NodeKind, NumericFacet, Pattern, StringFacet, TripleExprLabel, BNode, LiteralExclusion, IriExclusion, LanguageExclusion, Exclusion, LangOrWildcard
};
use shex_ast::iri_ref_or_wildcard::IriRefOrWildcard;
use shex_ast::string_or_wildcard::StringOrWildcard;
use log;
use thiserror::Error;

Expand Down Expand Up @@ -566,7 +568,7 @@ fn datatype_facets(i: Span) -> IRes<NodeConstraint> {

fn value_set_facets<'a>() -> impl FnMut(Span<'a>) -> IRes<'a, NodeConstraint> {
traced("value_set_facets", map_error(move |i| {
let (i, (vs, _, facets)) = tuple((value_set, tws0, facets()))(i)?;
let (i, (vs, _, facets)) = tuple((value_set(), tws0, facets()))(i)?;
Ok((i, vs.with_xsfacets(facets)))
}, || ShExParseError::ValueSetFacets))
}
Expand Down Expand Up @@ -1075,39 +1077,38 @@ fn optional(i: Span) -> IRes<Cardinality> {
}

/// `[48] valueSet ::= '[' valueSetValue* ']'`
fn value_set(i: Span) -> IRes<NodeConstraint> {
let (i, (_, _, vs, _, _)) = tuple((char('['), tws0, many0(value_set_value), tws0, char(']')))(i)?;
fn value_set<'a>() -> impl FnMut(Span<'a>) -> IRes<'a, NodeConstraint> {
traced("value set", map_error(move |i| {
let (i, (_, vs, _)) = tuple((token_tws("["), many0(value_set_value()), token_tws("]")))(i)?;
Ok((i, NodeConstraint::new().with_values(vs)))
}, || ShExParseError::ValueSet))
}

/// `[49] valueSetValue ::= iriRange | literalRange | languageRange`
/// ` | exclusion+`
fn value_set_value(i: Span) -> IRes<ValueSetValue> {
fn value_set_value<'a>() -> impl FnMut(Span<'a>) -> IRes<'a, ValueSetValue> {
traced("value_set_value", map_error(move |i| {
alt((
exclusion_plus(),
iri_range,
literal_range(),
language_range(),
exclusion_plus
))(i)
}

fn exclusion_plus(i: Span) -> IRes<ValueSetValue> {
let (i, excs) = many1(exclusion)(i)?;
todo!()
))(i) }, || ShExParseError::ValueSetValue))
}

/// `[50] exclusion ::= '.' '-' (iri | literal | LANGTAG) '~'?`
fn exclusion(i: Span) -> IRes<Exclusion> {
let (i, (_,exc)) = tuple(
(
token_tws("."),
alt((
map(literal_exclusion, |le| Exclusion::LiteralExclusion(le)),
map(iri_exclusion, |ie| Exclusion::IriExclusion(ie)),
map(language_exclusion, |le| Exclusion::LanguageExclusion(le))
))
))(i)?;
Ok((i, exc))
/// exclusion+ changed by: '.' (iriExclusion+ | literalExclusion+ | languageExclusion+)
fn exclusion_plus<'a>() -> impl FnMut(Span<'a>) -> IRes<'a, ValueSetValue> {
traced("wildcard exclusion", map_error(move |i| {
let (i, (_, e)) = tuple((
token_tws("."),
alt((
map(many1(literal_exclusion), |es| ValueSetValue::LiteralStemRange { stem: StringOrWildcard::Wildcard, exclusions: Some(es) }),
map(many1(language_exclusion), |es| ValueSetValue::LanguageStemRange { stem: LangOrWildcard::Wildcard, exclusions: Some(es) }),
map(many1(iri_exclusion), |es| ValueSetValue::IriStemRange { stem: IriRefOrWildcard::Wildcard, exclusions: Some(es) })
))
))(i)?;
Ok((i, e))
}, || ShExParseError::ExclusionPlus))
}

/// `[51] iriRange ::= iri ('~' exclusion*)?`
Expand Down Expand Up @@ -2295,7 +2296,7 @@ mod tests {

#[test]
fn test_value_set() {
let (_, result) = value_set(Span::new("[ 'a' ]")).unwrap();
let (_, result) = value_set()(Span::new("[ 'a' ]")).unwrap();
let expected_values = vec![
ValueSetValue::string_literal("a", None)
];
Expand Down
12 changes: 12 additions & 0 deletions shex_compact/src/parser_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ pub enum ParseError {
#[error("Expected shape expression declaration")]
ExpectedShapeExprDecl,

#[error("Expected exclusion that starts by .")]
ExclusionPlus,

#[error("Expected exclusion")]
Exclusion,

#[error("Expected set of values between [ and ]")]
ValueSet,

#[error("Expected value set value")]
ValueSetValue,

#[error("Expected value set")]
ValueSetFacets,

Expand Down

0 comments on commit 82c8227

Please sign in to comment.