@faubulous/mentor-rdf-parsers
    Preparing search index...

    @faubulous/mentor-rdf-parsers

    Mentor RDF Parsers

    License: LGPL-2.1 Coverage npm downloads TypeScript RDF 1.2

    Standards-compliant, fault-tolerant parsers for RDF languages, built with Chevrotain. Designed for IDEs and language tools where error recovery and concrete syntax tree (CST) access are essential.

    • Standards Compliance — Implements grammar productions from W3C specifications
    • Fault Tolerance — Recovers from syntax errors and continues parsing
    • Concrete Syntax Trees — Full token access with positions for tooling
    • RDF/JS Quads — Reader classes produce RDF/JS-compliant quads
    • Blank Node Tracking — Pre-assigned IDs for IDE features like "go to definition"
    Language Parser Reader Specification
    N-Triples RDF 1.2 N-Triples
    N-Quads RDF 1.2 N-Quads
    Turtle RDF 1.2 Turtle
    TriG RDF 1.2 TriG
    N3 W3C N3
    SPARQL 1.2 SPARQL 1.2 Query
    npm install @faubulous/mentor-rdf-parsers
    
    import { TurtleLexer, TurtleParser, TurtleReader } from '@faubulous/mentor-rdf-parsers';

    const input = `
    @prefix ex: <http://example.org/> .
    ex:Alice ex:knows ex:Bob .
    `;

    // Tokenize → Parse → Read
    const lexResult = new TurtleLexer().tokenize(input);
    const cst = new TurtleParser().parse(lexResult.tokens);
    const quads = new TurtleReader().visit(cst);

    console.log(quads[0].subject.value); // "http://example.org/Alice"
    flowchart LR
        A[Input String] --> B[Lexer]
        B -->|tokens| C[Parser]
        C -->|CST| D[Reader]
        D -->|quads| E[RDF/JS Quads]
        
        B -.->|lexing errors| F[errors]
        C -.->|parsing errors| F
    
    Component Purpose
    Lexer Tokenizes input string into a token stream
    Parser Produces a concrete syntax tree (CST) from tokens
    Reader Walks the CST and produces RDF/JS Quad objects
    Language Guide
    Turtle docs/examples/turtle.md
    N-Triples docs/examples/n-triples.md
    N-Quads docs/examples/n-quads.md
    TriG docs/examples/trig.md
    N3 docs/examples/n3.md
    SPARQL docs/examples/sparql.md

    Parsers collect errors instead of throwing, allowing partial results:

    const parser = new TurtleParser();
    const cst = parser.parse(tokens, false); // Pass false to collect errors

    // Check all error sources
    console.log(lexResult.errors); // Lexer errors
    console.log(parser.errors); // Parser errors
    console.log(parser.semanticErrors); // Semantic errors (e.g., undefined prefixes)

    See Error Handling Guide for details.

    Each language exports its token array for use in formatters and syntax highlighters:

    import { TurtleTokens, SparqlTokens } from '@faubulous/mentor-rdf-parsers';

    console.log(TurtleTokens.map(t => t.name));
    npm test
    

    The test suite includes over 1,500 tests covering all supported languages and the official W3C conformance test suites.

    LGPL-2.1-or-later