Antlr4 - 为gradle中的更多语言生成语法源

时间:2018-05-28 14:19:15

标签: gradle antlr4

在我的项目中,我必须使用gradle为多种语言(Java,Javascript和Python)生成语法源。

我正在使用antlr插件,因此我的build.gradle文件中包含以下行:

[DateValidation(ErrorMessageResourceType = typeof(Language), InvalidDateFormat = nameof(Language.InvalidDateFormat, InvalidDateFormatPast = nameof(Language.InvalidDateFormatPast), InvalidDateFormatFuture = nameof(Language.InvalidDateFormatFuture))]
public string Date { get; set; }

我省略了有关存储库,依赖项等的行。

通过这种方式,我可以三次拨打gradle:

apply plugin: 'antlr'

generateGrammarSource {
    def languageFlag = project.hasProperty('Language') ?project.property('Language') : 'Python2'

    arguments = ['-Dlanguage=' + languageFlag]

    def pythonOutputDirectory = "python/engine_lib/kpi_attributes"
    switch (languageFlag) {
        case "Java":    
            outputDirectory = file("../../../../XSpotterGUI/sviluppo/src/com/xech/xspotter4/grammars/kpiattributes")
            arguments += ['-package', 'com.xech.xspotter4.grammars.kpiattributes']
            break
        case "JavaScript":  
            outputDirectory = file("../../../../XSpotterGUI/sviluppo/WebContent/xspotter4/js/xech/grammars/kpiattributes")
            break
        case "Python2":
            outputDirectory = file(pythonOutputDirectory)
            break
    }
    description = 'Generates Java sources from Antlr4 grammars.'
    maxHeapSize = "64m"
    sourceSets.main.antlr.srcDirs = ['.']

    includes = ['KpiAttributes.g4']

    doLast {
        if (languageFlag.equals("Python2")) {
            File file = new File("$pythonOutputDirectory/__init__.py")
            file.write ""
        }    
    }
}

但是我无法创建任务&generate'AllGrammarSources'为了只调用gradlew一次并生成所有来源

0 个答案:

没有答案