Traqula
    Preparing search index...

    Module @traqula/parser-sparql-1-1

    Traqula logo

    A query language transpiler framework for JavaScript

    WARNING: V2 will come shortly and will have lots of breaking changes.

    Traqula parser engine for SPARQL 1.1

    Traqula Sparql 1.1 is a SPARQL 1.1 query parser for TypeScript.

    npm install @traqula/parser-sparql-1-1
    

    or

    yarn add @traqula/parser-sparql-1-1
    

    Either through ESM import:

    import {Parser} from 'engines/parser-sparql-1-1';
    

    or CJS require:

    const Parser = require('engines/parser-sparql-1-1').Parser;
    

    This package contains a Parser that is able to parse SPARQL 1.1 queries:

    const parser = new Parser();
    const abstractSyntaxTree = parser.parse('SELECT * { ?s ?p ?o }');

    The package also contains multiple parserBuilders. These builders can be used either to consume to a parser, or to usage as a starting point for your own grammar.

    At the core of Traqula, parser are constructed of multiple parser rules that have been consumed by the builder. This consumption returns a parser that can parse strings starting from any grammar rule.

    The sparql11ParserBuilder for example contains both the rules queryOrUpdate and path (among many others). The consumption of sparql11ParserBuilder will thus return an object that has function queryOrUpdate and path. Calling those function with a string will cause that string to be parsed using the appropriate rule as a starting rule.

    const parser: {
    queryOrUpdate: (input: string) => SparqlQuery;
    path: (input: string) => PropertyPath | IriTerm;
    } = sparql11ParserBuilder.consumeToParser({
    tokenVocabulary: l.sparql11Tokens.build(),
    }, {
    parseMode: new Set([ gram.canParseVars, gram.canCreateBlankNodes ]),
    dataFactory: new DataFactory(),
    });

    The builders can also be used to construct new parsers. As an example the triplesBlockParserBuilder is created by merging the objectListBuilder with some new rules.

    Optionally, the following parameters can be set in the Parser constructor:

    • dataFactory: A custom RDFJS DataFactory to construct terms and triples. (Default: require('@rdfjs/data-model'))
    • baseIRI: An initial default base IRI. (Default: none)
    • prefixes: An initial map of prefixes
    • skipValidation: Can be used to disable the validation that used variables in a select clause are in scope.

    Classes

    Parser

    Variables

    expressionParserBuilder
    objectListBuilder
    queryUnitParserBuilder
    sparql11ParserBuilder
    subSelectParserBuilder
    triplesBlockParserBuilder
    triplesTemplateParserBuilder
    updateNoModifyParserBuilder
    updateParserBuilder