← All compilation units

Flyology_SPARQL.Parsers

Description

SPARQL query parsing.

Coverage is the query language: the prologue, all four query forms, group graph patterns with OPTIONAL, UNION, MINUS, GRAPH, SERVICE, FILTER, BIND and subqueries, the expression grammar with its precedence, and the solution modifiers. Property paths are read as far as sequence, alternative, inverse and the three cardinality operators.

Deliberately absent: SPARQL Update, federated-query specifics beyond recognising SERVICE, and evaluation of any kind. A query here is a document to be checked, formatted or inspected.

Create

function Create (Limits : Parse_Limits := (others => <>)) return Parser

Start a parser.

Parameters
Limits
Return value

A parser awaiting its first chunk

Feed

procedure Feed (Into : in out Parser; Bytes : String)

Supply the next piece of the query.

Parameters
Into

The parser

Bytes

The next bytes, split at any boundary

Raised exceptions
Parse_Error

The bytes cannot begin a token

Parser_State_Error

The parser has already finished

Finish

function Finish (Into : in out Parser) return Syntax.Query

Close the input and parse what arrived.

Parameters
Into

The parser

Return value

The parsed query

Raised exceptions
Parse_Error

The query is not well-formed

Parser_State_Error

The parser has already finished

Parse

function Parse
  (Query_Text : String;
   Limits     : Parse_Limits := (others => <>)) return Syntax.Query
Parameters
Query_Text
Limits
Return value

Parse_Error

Parse_Error : exception;

Raised when a query is not well-formed. The message names the line and column.

Parse_Limits

subtype Parse_Limits is Flyology_RDF.Chunk_Scanners.Scan_Limits;

Parse a query given whole. @param Query_Text The SPARQL text @return The parsed query @exception Parse_Error The query is not well-formed What one query may cost to read. A caller taking input from a network must be able to say what it will accept, and the defaults are the same as the RDF parser's.

Parser

type Parser is limited private;

A query read from input that arrives in pieces.

The tree is built at Finish rather than as the bytes arrive, because a query is not meaningful until it is closed and there is nothing to hand back before then. What streaming buys here is the scanner: the input may be split at any byte boundary, including inside an escape, a literal or an IRI, and the query that comes out is the one the whole text would have produced. A caller reading from a socket does not have to assemble the document first.

Parser_State_Error

Parser_State_Error : exception;

Raised when a parser is fed or finished twice.