I'm using the grammar on the Antlr github page: https://github.com/antlr/grammars-v4/tree/master/scala
But the grammar has a problem based on reading the reported issue on GitHub.
Here is my code:
InputStream targetStream = new FileInputStream(file);
System.out.println(targetStream.toString());
ANTLRInputStream input = new ANTLRInputStream(targetStream);
ScalaLexer lexer = new ScalaLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...
The error message is:
line 1:0 no viable alternative at input 'object HelloWorld {'
I searched the issue, several other people also found the problem. It is hard to understand why such a state-of-the-art tool has such an obvious issue, but the issue is there. I'm not an export of parsing and just need a working scala parser in Java. Are there any other grammar I can use for scala? Or are there any other scala parser written in Java?