shexjs / shex.js

shex.js javascript package
MIT License
60 stars 17 forks source link

Error parsing schema #96

Closed mistermboy closed 2 years ago

mistermboy commented 2 years ago

I´m not able to parse the following schema:

 PREFIX : <http://www.example.com>
 PREFIX schema:    <http://schema.org/>
 PREFIX xsd:    <http://www.w3.org/2001/XMLSchema#>

 :User{
      schema:knows  xsd:string @:User 
  }

It throws the following error:

Error: undefined(6): Parse error on line 6:
...      schema:knows  xsd:string @:User   }
---------------------------------^
Expecting 'EOF', 'IT_BASE', 'IRIREF', 'IT_PREFIX', 'PNAME_NS', 'IT_IMPORT', 'IT_start', 'IT_OR', 'IT_AND', ')', '.', 'IT_IRI', 'IT_BNODE', 'IT_NONLITERAL', 'INTEGER', 'REGEXP', 'IT_LENGTH', 'IT_MINLENGTH', 'IT_MAXLENGTH', 'DECIMAL', 'DOUBLE', 'STRING', 'IT_MININCLUSIVE', 'IT_MINEXCLUSIVE', 'IT_MAXINCLUSIVE', 'IT_MAXEXCLUSIVE', 'IT_TOTALDIGITS', 'IT_FRACTIONDIGITS', '}', '|', ',', ';', '*', '+', '?', 'REPEAT_RANGE', ']', '~', '-', 'LANGTAG', '//', '%', 'LANG_STRING', 'IT_true', 'IT_false', 'PNAME_LN', 'BLANK_NODE_LABEL', got 'ATPNAME_LN'
...      schema:knows  xsd:string @:User   }
---------------------------------^
    at Object.<anonymous> (D:\Repositories\shexjs\main.js:3:38)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

I think an "and" keyword is expected between the node constraint and the shapeRef, but the shex grammar allows it to be omitted, doesn't it?

ericprud commented 2 years ago

apologies, thought i'd responded earlier.

I imagine you already tried with the AND (try it); you can only elide the AND if it's between a non-literal node kind (IRI, BNODE, NONLITERAL) and a shape reference (@:User) (or inline-shape declaration with the {...}).

If you're a fan of grammars, this comes from:

[45] tripleConstraint ::= predicate inlineShapeExpression cardinality? [11] inlineShapeExpression ::= inlineShapeAnd ("OR" inlineShapeAnd) [15] inlineShapeAnd ::= inlineShapeNot ("AND" inlineShapeNot)                  // <-- AND [17] inlineShapeNot ::= "NOT"? inlineShapeAtom [20] inlineShapeAtom ::= nonLitNodeConstraint inlineShapeOrRef?                                        | litNodeConstraint                                        | inlineShapeOrRef nonLitNodeConstraint?                                        | '(' shapeExpression ')'                                        | '.' [24] litNodeConstraint ::= "LITERAL" xsFacet                                        | datatype xsFacet                                                  // <-- xsd:string                                        | valueSet xsFacet*                                        | numericFacet+ [22] inlineShapeOrRef ::= inlineShapeDefinition | shapeRef [23] shapeRef ::= ATPNAME_LN | ATPNAME_NS | '@' shapeExprLabel      // <-- @:User

Though in this case, you'd probably want an OR instead because nothing is both an xsd:string and a :User (try it).

mistermboy commented 2 years ago

Thanks for the response. I always thought it was possible to do that in shex :sweat: