qasm-ts - v2.0.0
    Preparing search index...

    Module qasm3/lexer

    OpenQASM 3.0 Lexical Analyzer

    This module implements the lexer for OpenQASM 3.0, which transforms source code into a stream of tokens. The lexer handles the significantly expanded syntax of OpenQASM 3.0, including classical programming constructs, control flow, and advanced quantum features.

    Key features of the OpenQASM 3.0 lexer:

    • Extended token set: Classical types, control flow, functions
    • Complex operators: Compound assignment, bitwise operations
    • Advanced literals: Scientific notation, binary/hex/octal, durations
    • Gate modifiers: ctrl, negctrl, inv, pow with @ syntax
    • Unicode support: Mathematical constants (π, ℇ, τ)
    • Robust error handling: Detailed syntax error reporting

    The lexer performs several validation passes:

    • Semicolon verification for statement termination
    • Comment handling (single-line // and multi-line /* */)
    • String literal parsing with multiple quote styles
    • Number format validation and conversion
    const lexer = new Lexer('qubit[2] q; h q[0];');
    const tokens = lexer.lex();
    // Returns: [
    // [Token.Id, 'qubit'], [Token.LSParen], [Token.NNInteger, 2],
    // [Token.RSParen], [Token.Id, 'q'], [Token.Semicolon], ...
    // ]

    Classes

    default