java - antlr 对 pascal 语法的 panic

标签 java gradle antlr

我想生成 Pascal java 解析器,然后在我的 gradle 应用程序中使用它。

对于 Pascal 我使用了这个语法 https://github.com/antlr/grammars-v4/tree/master/pascal

我的 build.gradle 看起来像这样。我使用了 antlr 插件。

apply plugin: 'groovy'
apply plugin: 'antlr'

repositories {
    jcenter()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.6'
    compile 'org.antlr:antlr4:4.5.3'

    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
    testCompile 'junit:junit:4.12'
}

但是当我尝试运行任务时 generateGrammarSource 我得到这个错误

:generateGrammarSource
L:\app\src\main\antlr\pascal.g4:36:1: unexpected token: grammar
error: Token stream error reading grammar(s):
L:\app\src\main\antlr\pascal.g4:804:8: expecting ''', found '='
L:\app\src\main\antlr\pascal.g4:36:1: unexpected token: grammar
error: Token stream error reading grammar(s):
L:\app\src\main\antlr\pascal.g4:804:8: expecting ''', found '='
L:\app\src\main\antlr\pascal.g4:36:1: rule grammar trapped:
L:\app\src\main\antlr\pascal.g4:36:1: unexpected token: grammar
TokenStreamException: expecting ''', found '='
:generateGrammarSource FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateGrammarSource'.
> There was 1 error during grammar generation
   > ANTLR Panic: TokenStreamException: expecting ''', found '='

这是什么问题?

最佳答案

来自 https://docs.gradle.org/current/userguide/antlr_plugin.html#sec:antlr_dependency_management 的插件文档

“antlr:antlr:2.7.7 将用作默认值。”

要更改它,只需说出要使用的版本,如下所示

dependencies {
    //antlr "org.antlr:antlr:3.5.2" // use ANTLR version 3
    antlr "org.antlr:antlr4:4.5" // use ANTLR version 4
}

关于java - antlr 对 pascal 语法的 panic ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36338445/

相关文章:

java - 使用 Files.newBufferedReader() 读取文件和直接构造读取器的不同结果

java部分类

android - 如何确定 kotlin-multiplatform 项目中的构建类型

gradle - 如何从 Gradle Maven Publishing 插件构建的 POM 中排除依赖项?

java - ANTLR4 -> 检查文字是 STRING_LITERAL 还是 NUMBER_LITERAL

java - 在不使用 BorderPane 的情况下设置节点的对齐方式?

Java Inflate 与大字符串不一致

reference - 可以使用 proguard 跨多个 gradle 模块进行混淆吗?

Linux - Gradle 无法删除临时文件并且构建失败

java - Antlr:无法找到或本地主类,即使它存在