Skip to content

Commit

Permalink
Add optional parsing of bracketed inverse keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Feb 25, 2024
1 parent 9ab4b9a commit 41a390a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/from_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,13 +1365,25 @@ impl<A: ForIRI> FromPair<A> for ObjectPropertyExpression<A> {
const RULE: Rule = Rule::ObjectPropertyExpression;
fn from_pair_unchecked(pair: Pair<Rule>, ctx: &Context<'_, A>) -> Result<Self> {
let inner = descend(pair);
let span = inner.as_span();
match inner.as_rule() {
Rule::ObjectPropertyIRI => {
FromPair::from_pair(inner, ctx).map(ObjectPropertyExpression::ObjectProperty)
}
Rule::InverseObjectProperty => {
let pair = inner.into_inner().last().unwrap();
FromPair::from_pair(pair, ctx).map(ObjectPropertyExpression::InverseObjectProperty)
let pair = descend(inner);
let op = match pair.as_rule() {
Rule::BracketedObjectPropertyIRI if ctx.strict => {
return Err(Error::custom(
"inverse object properties should not be bracketed",
span,
));
}
Rule::BracketedObjectPropertyIRI => FromPair::from_pair(descend(pair), ctx)?,
Rule::ObjectPropertyIRI => FromPair::from_pair(pair, ctx)?,
rule => unexpected_rule!(ObjectPropertyExpression, rule),
};
Ok(ObjectPropertyExpression::InverseObjectProperty(op))
}
rule => unexpected_rule!(ObjectPropertyExpression, rule),
}
Expand Down Expand Up @@ -1457,7 +1469,7 @@ mod tests {
macro_rules! assert_parse_into {
($ty:ty, $rule:path, $build:ident, $prefixes:ident, $doc:expr, $expected:expr) => {
let doc = $doc.trim();
let mut ctx = Context::<'_, String>::new(&$build, &$prefixes);
let ctx = Context::<'_, String>::new(&$build, &$prefixes);
match OwlManchesterParser::parse($rule, doc) {
Ok(mut pairs) => {
let res = <$ty as FromPair<String>>::from_pair(pairs.next().unwrap(), &ctx);
Expand Down
4 changes: 3 additions & 1 deletion src/owl.pest
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ ObjectPropertyExpression2List = { ObjectPropertyExpression ~ (COMMA ~ ObjectProp
DataPropertyExpression2List = { DataPropertyExpression ~ (COMMA ~ DataPropertyExpression)+ }
Individual2List = { Individual ~ (COMMA ~ Individual)+ }

BracketedObjectPropertyIRI = { LBRACKET ~ ObjectPropertyIRI ~ RBRACKET }


// 2.1 IRIs, Integers, Literals and Entities

Expand Down Expand Up @@ -172,7 +174,7 @@ Frame = { DatatypeFrame | ClassFrame | ObjectPropertyFrame | DataPro
// 2.3 Property and Datatype Expressions

ObjectPropertyExpression = { InverseObjectProperty | ObjectPropertyIRI }
InverseObjectProperty = { KEYWORD_INVERSE ~ ObjectPropertyIRI }
InverseObjectProperty = { KEYWORD_INVERSE ~ (BracketedObjectPropertyIRI | ObjectPropertyIRI) }
DataPropertyExpression = { DataPropertyIRI }
PropertyExpression = { ObjectPropertyExpression | DataPropertyExpression }

Expand Down

0 comments on commit 41a390a

Please sign in to comment.