Python representation of the ShEx AST(ish) specification.
from ShExJSG import Schema, ShExJ
from PyShExC import ShExC
from pyjsg.jsglib.loader import is_valid
schema = Schema()
schema.start = ShExJ.Shape()
print(is_valid(schema))
print(schema._as_json_dumps())
print(str(ShExC(schema)))
True
{
"@context": "http://www.w3.org/ns/shex.jsonld",
"start": {
"type": "Shape"
},
"type": "Schema"
}
start= { }
This file is derived from the ShEx JSG specification. The differences are as follows:
labeledShapeExpr
- The official JSG implemention specifies a strange pattern where the objects with atype
of"ShapeOr"
,"ShapeAnd"
, ... are recognized as instances ofShapeOr
,ShapeAnd
, ... if they lack anid
element and aslabeledShapeOr
,labeledShapeAnd
, ... if theid
element exists. We simplify this construct, leavingid
optional. This potentially allows the parser to accept some highly unlikely invalid constructs, but these can be checked in a post-parse step if you feel deeply about it. (Note also that the ShEx semantics document does not include thelabeledShapeExpr
branch)- This uses the revised jsg syntax.
Output of the PyJSG generate_parser
for ShExJ.jsg. Python 3 representation of the ShEx AST
This package currently requires python 3.6 or later. It could be updated to support earlier python 3 versions if there is sufficient demand.
pip install ShExJSG
cd ShExJSG
generate_parser ShExJ.jsg
Then run all of the unit tests