Scala grammar for Antlr4 not working

I use 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 problem 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);
 ...

Error message:

line 1:0 no viable alternative at input 'object HelloWorld {'

I was looking for this problem, some other people also found the problem. It is hard to understand why such an ultramodern tool has such an obvious problem, but the problem is there. I am not an export of parsing and just need a working scala parser in Java. Is there any other grammar I can use for scala? Or is there any other scala parser written in Java?

+4

Source: https://habr.com/ru/post/1679020/


All Articles