Gradle 2.0 用户指南翻译——第四十章. ANTLR 插件

本文禁止w3cschool转载!

翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc 。

本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2.0 。
更好的阅读体验请访问:http://gradledoc.githang.com/2.0/userguide/userguide.html 。
另外,Android 手机用户可通过我写的一个程序浏览文档,带缓存功能的,目前0.6.1版本兼容 Android 4.0.3以上系统,项目地址如下:
https://github.com/msdx/gradle-doc-apk

翻译不易,本文采用 CC BY-NC-SA 4.0 许可协议,转载请务必署名及注明本文在CSDN博客上的出处:

https://coder.blog.csdn.net/article/details/90407270

关于我对Gradle的翻译,以Github上的项目及http://gradledoc.githang.com 上的文档为准。如发现翻译有误的地方,将首先在以上两个地方更新。因时间精力问题,博客中发表的译文基本不会同步修改。

第四十章. ANTLR 插件

Chapter 40. The ANTLR Plugin

ANTLR 插件扩展自 Java 插件并添加了对使用 ANTLR 的生成解析器的支持。
The ANTLR plugin extends the Java plugin to add support for generating parsers using ANTLR.

ANTLR插件只支持ANTLR版本2。 
The ANTLR plugin only supports ANTLR version 2.

40.1. 用法

40.1. Usage

要使用 ANTLR 插件,请在构建脚本中包含以下语句:
To use the ANTLR plugin, include in your build script:

示例 40.1. 使用 ANTLR 插件 - Example 40.1. Using the ANTLR plugin

build.gradle

apply plugin: 'antlr'

40.2. 任务

40.2. Tasks

ANTLR 插件向你的项目添加了许多任务,如下所示。
The ANTLR plugin adds a number of tasks to your project, as shown below.

表 40.1. ANTLR 插件——任务 - Table 40.1. ANTLR plugin - tasks

任务名称
Task name
依赖于
Depends on
类型
Type
描述
Description
generateGrammarSource-AntlrTask为所有生产 ANTLR 语法生成源文件。
Generates the source files for all production ANTLR grammars.
generateTestGrammarSource-AntlrTask为所有测试 ANTLR 语法生成源文件。
Generates the source files for all test ANTLR grammars.
generateSourceSetGrammarSource-AntlrTask为给定源集的所有 ANTLR 语法生成源文件。
Generates the source files for all ANTLR grammars for the given source set.

ANTLR 插件向 Java 插件所添加的任务添加了以下依赖。
The ANTLR plugin adds the following dependencies to tasks added by the Java plugin.

表 40.2. ANTLR 插件——附加的任务依赖 - Table 40.2. ANTLR plugin - additional task dependencies

任务名称
Task name
依赖于
Depends on
CompileJavagenerateGrammarSource
compileTestJavagenerateTestGrammarSource
compileSourceSetJavagenerateSourceSetGrammarSource

40.3. 项目布局

40.3. Project layout

表 40.3. ANTLR 插件——项目布局 - Table 40.3. ANTLR plugin - project layout

目录
Directory
意义
Meaning
src/main/antlr生产 ANTLR 语法文件。
Production ANTLR grammar files.
src/test/antlr测试 ANTLR 语法文件。
Test ANTLR grammar files.
src/sourceSet/antlr给定源集的 ANTLR 语法文件。
ANTLR grammar files for the given source set.

40.4. 依赖管理

40.4. Dependency management

ANTLR 插件添加了一个 antlr 依赖配置,你可以使用它来声明你希望使用的 ANTLR 依赖。
The ANTLR plugin adds an antlr dependency configuration. You use this to declare the ANTLR dependency that you wish to use.

示例 40.2. 声明 ANTLR 版本 - Example 40.2. Declare ANTLR version

build.gradle

repositories {
    mavenCentral()
}

dependencies {
    antlr 'antlr:antlr:2.7.7'
}

40.5. 约定属性

40.5. Convention properties

ANTLR 插件不添加任何约定属性。
The ANTLR plugin does not add any convention properties.

40.6. 源集属性

40.6. Source set properties

ANTLR 插件向项目的每一个源集添加了下列属性。
The ANTLR plugin adds the following properties to each source set in the project.

表 40.4. ANTLR 插件——源集属性 - Table 40.4. ANTLR plugin - source set properties

属性名称
Property name
类型
Type
默认值
Default value
描述
Description
antlrSourceDirectorySet (只读) 
SourceDirectorySet (read-only)
不为 null 
Not null
此源集的 ANTLR 语法文件。包含在ANTLR源目录中找到的所有.g文件,并排除所有其他类型的文件。 
The ANTLR grammar files of this source set. Contains all .g found in the ANTLR source directories, and excludes all other types of files.
antlr.srcDirsSet<File>。可以使用《第 16.5 节,“指定一组输入文件”》中所讲到的任何一种方法来设置。 
Set<File>. Can set using anything described in Section 16.5, “Specifying a set of input files”.
[projectDir/src/name/antlr]包含该源集的 ANTLR 语法文件的源目录。 
The source directories containing the ANTLR grammar files of this source set.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值