@designliquido/xpath
    Preparing search index...

    Class XPathLexer

    Lexer (tokenizer) for XPath expressions.

    Converts XPath expression strings into a sequence of tokens that can be parsed by XPath10Parser or XPath20Parser.

    // Create lexer with default options (XPath 1.0)
    const lexer = new XPathLexer();

    // Create lexer with explicit version
    const lexer10 = new XPathLexer('1.0');
    const lexer20 = new XPathLexer('2.0');

    // Create lexer with options object
    const lexer = new XPathLexer({ version: '2.0' });

    // Tokenize an expression
    const tokens = lexer.scan('//book[@price > 10]');
    Index

    Constructors

    • Create a new XPath lexer.

      Parameters

      • OptionalversionOrOptions: XPathVersion | XPathLexerOptions

        Either an XPath version string ('1.0', '2.0', '3.0', '3.1') or an options object with a version property. Defaults to '1.0' for backward compatibility.

      Returns XPathLexer

      // All of these create an XPath 1.0 lexer:
      const lexer1 = new XPathLexer();
      const lexer2 = new XPathLexer('1.0');
      const lexer3 = new XPathLexer({ version: '1.0' });

      // Create an XPath 2.0 lexer:
      const lexer4 = new XPathLexer('2.0');
      const lexer5 = new XPathLexer({ version: '2.0' });

    Properties

    expression: string
    current: number
    tokens: XPathToken[]

    Methods

    • Get the XPath version this lexer is configured for.

      Returns XPathVersion

    • Register additional function names to be recognized by the lexer. Used for XSLT extension functions.

      Parameters

      • functionNames: string[]

      Returns void

    • Check if character is a valid start of an identifier. Supports Unicode letters according to XML NCName specification.

      Parameters

      • char: string

      Returns boolean

    • Check if character is valid in an identifier (after the first character). Supports Unicode letters and digits according to XML NCName specification. Note: Hyphen is handled separately in parseIdentifier for reserved words.

      Parameters

      • char: string

      Returns boolean

    • Parameters

      • char: string

      Returns boolean

    • Parameters

      • char: string

      Returns boolean

    • Parameters

      • expected: string

      Returns boolean

    • Parse string template: Hello {$name}! Returns the entire template as-is for the parser to handle interpolation.

      Returns XPathToken