Грамматику языка Scala я нашел здесь:
https://github.com/antlr/grammars-v4 /blob/master/scala/Scala.g4
Я сгенерировал классы ANTLR из грамматики благодаря плагину antlr4-maven-plugin.
Код: Выделить всё
org.antlr
antlr4-maven-plugin
4.13.1
antlr-generate
generate-sources
antlr4
src/main/antlr4
target/generated-sources/antlr4
true
true
Код: Выделить всё
org.antlr
antlr4-runtime
4.13.1
Код: Выделить всё
public class Main {
public static void main(String[] args) throws IOException {
Path filePath = Paths.get(args[0]);
CharStream charStream = CharStreams.fromPath(filePath , StandardCharsets.UTF_8);
ScalaLexer lexer = new ScalaLexer(charStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ScalaParser parser = new ScalaParser(tokens);
ParseTree tree = parser.compilationUnit();
ParseTreeWalker.DEFAULT.walk(new ScalaBaseListener(), tree);
}
}
Код: Выделить всё
object replace extends RewriteRule {
def transform(node: Node): Seq[Node] = node match {
case { value @ _* } => { value }
case _ => node
}
}
Код: Выделить всё
object replace extends RewriteRule {
override def transform(node: Node): Seq[Node] = node match {
case { value @ _* } => { value }
case _ => node
}
}
Код: Выделить всё
line 3:13 extraneous input ':' expecting {'-', 'null', 'this', 'super', '(', '_', Id, BooleanLiteral, CharacterLiteral, SymbolLiteral, IntegerLiteral, StringLiteral, FloatingPointLiteral, Varid, NL}
line 3:19 extraneous input '{' expecting {'-', 'null', 'this', 'super', '(', '_', Id, BooleanLiteral, CharacterLiteral, SymbolLiteral, IntegerLiteral, StringLiteral, FloatingPointLiteral, Varid, NL}
line 3:27 mismatched input '@' expecting {'=>', 'if'}
line 3:30 extraneous input '*' expecting {'-', 'null', 'this', 'super', '(', '{', '}', 'type', 'val', '_', 'implicit', 'if', 'while', 'try', 'do', 'for', 'throw', 'return', '+', '~', '!', 'new', 'lazy', 'case', '@', 'var', 'override', 'abstract', 'final', 'sealed', 'private', 'protected', 'import', 'def', 'class', 'object', 'trait', Id, BooleanLiteral, CharacterLiteral, SymbolLiteral, IntegerLiteral, StringLiteral, FloatingPointLiteral}
Что мне нужно исправить в грамматике?
Подробнее здесь: https://stackoverflow.com/questions/782 ... lr-grammar