-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Description
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.

In an above Image for three children
0 -> NumberLiteral
1 -> Operator
2 -> NumberLiteral
Metadata
Metadata
Assignees
Labels
No labels