-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
119 lines (103 loc) · 3.12 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
plugins {
id 'application'
id 'idea'
}
group 'com.craftinginterpreters'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
}
test {
useJUnitPlatform()
}
sourceSets {
main {
java {
srcDir "${buildDir}/generated/main/java"
}
}
}
idea {
module {
generatedSourceDirs += file "${buildDir}/generated/main/java"
}
}
jar.manifest.attributes('Main-Class': 'com.craftinginterpreters.lox.Lox')
application {
mainClass = 'com.craftinginterpreters.lox.Lox'
}
run {
standardInput = System.in
}
/*
* TODO: Make this not rely on the lox module.
* It won't compile if there are errors in the module that depends on the code this task generates.
* Use the following command to generate the code:
java -cp "D:\src\jlox\src\main\java" \
com.craftinginterpreters.tool.GenerateAst \
D:\src\jlox\build\generated\main\java\com\craftinginterpreters\lox \
Expr \
"Binary : Expr left, Token operator, Expr right" \
"Grouping : Expr expression" \
"Literal : Object value" \
"Unary : Token operator, Expr right"
*/
tasks.register('generateAst', JavaExec) {
description "Generate AST classes"
mainClass = 'com.craftinginterpreters.tool.GenerateAst'
classpath sourceSets.main.runtimeClasspath
args = [
"${buildDir}/generated/main/java/com/craftinginterpreters/lox",
"Expr",
"Binary : Expr left, Token operator, Expr right",
"Grouping : Expr expression",
"Literal : Object value",
"Unary : Token operator, Expr right"
]
}
def GenerateAst = "src/main/java/com/craftinginterpreters/tool/GenerateAst.java"
def outdir = "${buildDir}/generated/main/java/com/craftinginterpreters/lox"
// HACK: This is a hack to generate the AST classes before compiling the code. See above.
// Consider using `java -cp src/jlox/src/main/java
tasks.register('genAst') {
description "Generates AST classes"
dependsOn 'genExpr'
dependsOn 'genStmt'
}
tasks.register('genExpr', Exec) {
description "Generate Expr AST"
commandLine "java", GenerateAst, outdir,
"Expr",
"Assign : Token name, Expr value",
"Binary : Expr left, Token operator, Expr right",
"Call : Expr callee, Token paren, List<Expr> arguments",
"Grouping : Expr expression",
"Literal : Object value",
"Logical : Expr left, Token operator, Expr right",
"Unary : Token operator, Expr right",
"Variable : Token name"
}
tasks.register('genStmt', Exec) {
description "Generate Stmt AST"
commandLine "java", GenerateAst, outdir,
"Stmt",
"Block : List<Stmt> statements",
"Expression : Expr expression",
"Function : Token name, List<Token> params, List<Stmt> body",
"If : Expr condition, Stmt thenBranch, Stmt elseBranch",
"Print : Expr expression",
"Return : Token keyword, Expr value",
"Var : Token name, Expr initializer",
"While : Expr condition, Stmt body"
}
/*
// https://stackoverflow.com/a/29602484
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn genSources
}
*/