Skip to content

this.src.mark is not a function #61

Closed

Description

@pkozuchowski

Not sure what I'm doing wrong, there's no mark() method on string.

const fs = require('fs');
const {ApexLexer, CommonTokenStream, CaseInsensitiveInputStream, ApexParser} = require('@apexdevtools/apex-parser');

let lexer = new ApexLexer(new CaseInsensitiveInputStream("public class Hello {}"))
let tokens  = new CommonTokenStream(lexer);

let parser = new ApexParser(tokens)
let context = parser.compilationUnit()
\node_modules\@apexdevtools\apex-parser\lib\CaseInsensitiveInputStream.js:46
        return this.src.mark();
                        ^


TypeError: this.src.mark is not a function
    at CaseInsensitiveInputStream.mark (XXX\node_modules\@apexdevtools\apex-parser\lib\CaseInsensitiveInputStream.js:46:25)
    at ApexLexer.nextToken (XXX\node_modules\antlr4ts\Lexer.js:87:44)
    at CommonTokenStream.fetch (XXX\node_modules\antlr4ts\BufferedTokenStream.js:147:38)
    at CommonTokenStream.sync (XXX\node_modules\antlr4ts\BufferedTokenStream.js:133:32)
    at CommonTokenStream.setup (XXX\node_modules\antlr4ts\BufferedTokenStream.js:244:14)
    at CommonTokenStream.lazyInit (XXX\node_modules\antlr4ts\BufferedTokenStream.js:240:18)
    at CommonTokenStream.tryLT (XXX\node_modules\antlr4ts\CommonTokenStream.js:78:14)
    at CommonTokenStream.LT (XXX\node_modules\antlr4ts\BufferedTokenStream.js:198:27)
    at ApexParser.enterRule (XXX\node_modules\antlr4ts\Parser.js:491:40)
    at ApexParser.compilationUnit (XXX\node_modules\@apexdevtools\a

Activity

  1. adangel commented on Jan 10, 2025

    @adangel
    Contributor

    When creating CaseInsensitiveInputStream, you need to provide a CharStream and not a simple string:

    let lexer = new ApexLexer(new CaseInsensitiveInputStream(CharStreams.fromString("public class Hello {}")))

    CharStreams is from antlr4ts: import { CharStreams } from "antlr4ts";

    See also the test code:

    const stream = CharStreams.fromString(input);
    const lexer = new ApexLexer(
    caseInsensitive ? new CaseInsensitiveInputStream(stream) : stream
    );

  2. pkozuchowski commented on Jan 10, 2025

    @pkozuchowski
    Author

    Ok, thanks :) I was looking at example on README, it's probably outdated.

  3. added 2 commits that reference this issue on Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions