May 02, 2015 .. currentmodule:: rdfextras.sparql.parser

parser - SPARQL parser

rdfextras.sparql.parser.refer_component(component, initial_args=None, projection=None, **kwargs)[source]

Create a function to forward parsing results to the appropriate constructor.

The pyparsing library allows us to modify the token stream that is returned by a particular expression with the setParseAction() method. This method sets a handler function that should take a single ParseResults instance as an argument, and then return a new token or list of tokens. Mainly, we want to pass lower level tokens to SPARQL parse tree objects; the constructors for these objects take a number of positional arguments, so this function builds a new function that will forward the pyparsing results to the positional arguments of the appropriate constructor.

This function provides a bit more functionality with its additional arguments:

  • initial_args: static list of initial arguments to add to the

    beginning of the arguments list before additional processing

  • projection: list of integers that reorders the initial arguments

    based on the indices that it contains.

Finally, any additional keyword arguments passed to this function are passed along to the handler that is constructed.

Note that we always convert pyparsing results to a list with the asList() method before using those results; this works, but we may only need this for testing. To be safe, we include it here, but we might want to investigate further whether or not it could be moved only to testing code. Also, we might want to investigate whether a list-only parsing mode could be added to pyparsing.


Previous topic

operators - SPARQL Operators

Next topic

processor - SPARQL processor