Skip to content

Swift ANTLR Runtime: Terminals not working / crash when calling ctx.getText() #4892

@vinaykumar0339

Description

@vinaykumar0339

Description

  • I am building an expression language using ANTLR 4.13.2.

  • It works fine in JavaScript and Java.

  • In Swift, I’m encountering an issue when accessing terminals.

Issue

The crash occurs at this method:

// This method is from TerminalNodeImpl.swift file
public func getText() -> String {
    return (symbol.getText())!   // ⚠️ crash here
}

Example input expression:

1+1

And in the visitor:

public override func visitNumberLiteral(_ ctx: JexLangParser.NumberLiteralContext) -> Any? {
    ctx.getText() // ⚠️ crash occurs here
}
  • When the visitor tries to access ctx.getText(), the application crashes.

  • It seems related to terminals not being recognized properly in runtime Swift Parser.

Notes

  • The grammar works in JS and Java, so the issue may be specific to the Swift ANTLR runtime.

  • Terminals like NUMBER or + might not be producing valid symbols when parsed in Swift.

Image
In an above Image for three children
0 -> NumberLiteral
1 -> Operator
2 -> NumberLiteral

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