parserutils
NOTE: PyParsing setResultName/call provides a very similar solution to this I didn’t realise at the time of writing and I will remove a lot of this code at some point
Utility classes for creating an abstract-syntax tree out with pyparsing actions
Lets you label and group parts of parser production rules
For example:
[5] BaseDecl ::= ‘BASE’ IRIREF
BaseDecl = Comp(‘Base’, Keyword(‘BASE’) + Param(‘iri’,IRIREF))
After parsing, this gives you back an CompValue object, which is a dict/object with the parameters specified. So you can access the parameters are attributes or as keys:
baseDecl.iri
Comp lets you set an evalFn that is bound to the eval method of the resulting CompValue
Classes:
-
Comp–A pyparsing token for grouping together things with a label
-
CompValue–The result of parsing a Comp
-
Expr–A CompValue that is evaluatable
-
Param–A pyparsing token for labelling a part of the parse-tree
-
ParamList–A shortcut for a Param with isList=True
-
ParamValue–The result of parsing a Param
Functions:
-
prettify_parsetree– -
value–Utility function for evaluating something…
Comp
Bases: TokenConverter
A pyparsing token for grouping together things with a label Any sub-tokens that are not Params will be ignored.
Returns CompValue / Expr objects - depending on whether evalFn is set.
Methods:
Attributes:
Source code in rdflib/plugins/sparql/parserutils.py
postParse
Source code in rdflib/plugins/sparql/parserutils.py
CompValue
Bases: OrderedDict
The result of parsing a Comp Any included Params are available as Dict keys or as attributes
Methods:
-
__getattr__– -
__getitem__– -
__repr__– -
__setattr__– -
__str__– -
clone– -
get–
Attributes:
-
name–
Source code in rdflib/plugins/sparql/parserutils.py
__getattr__
Source code in rdflib/plugins/sparql/parserutils.py
__getitem__
__repr__
__setattr__
Source code in rdflib/plugins/sparql/parserutils.py
__str__
clone
clone() -> CompValue
Expr
Bases: CompValue
A CompValue that is evaluatable
Methods:
-
eval–
Source code in rdflib/plugins/sparql/parserutils.py
eval
eval(ctx: Any = {}) -> Union[SPARQLError, Any]
Source code in rdflib/plugins/sparql/parserutils.py
Param
Bases: TokenConverter
A pyparsing token for labelling a part of the parse-tree if isList is true repeat occurrences of ParamList have their values merged in a list
Methods:
Attributes:
-
isList–
Source code in rdflib/plugins/sparql/parserutils.py
postParse2
postParse2(tokenList: Union[List[Any], ParseResults]) -> ParamValue
ParamList
ParamValue
The result of parsing a Param This just keeps the name/value All cleverness is in the CompValue
Methods:
-
__str__–
Attributes:
Source code in rdflib/plugins/sparql/parserutils.py
prettify_parsetree
Source code in rdflib/plugins/sparql/parserutils.py
value
value(ctx: FrozenBindings, val: Any, variables: bool = False, errors: bool = False) -> Any
Utility function for evaluating something…
Variables will be looked up in the context Normally, non-bound vars is an error, set variables=True to return unbound vars
Normally, an error raises the error, set errors=True to return error