Skip to content

Commit 1d447c5

Browse files
authored
Merge pull request #459 from green-labs/precompiled-antlr
Bundle precompiled antlr parser
2 parents 506f14b + 57de211 commit 1d447c5

31 files changed

Lines changed: 11033 additions & 34 deletions

.github/workflows/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
key: cljdeps-${{ hashFiles('deps.edn') }}
3838

3939
- name: Execute tests (JDK ${{ matrix.java-version}}, Clojure ${{matrix.clojure-version}})
40-
run: clojure -X:dev:test:clojure-${{ matrix.clojure-version }}
40+
run: clojure -T:build compile-java && clojure -X:dev:test:clojure-${{ matrix.clojure-version }}

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ for [Duct](https://github.com/duct-framework/duct).
5555

5656
For more detailed documentation, [read the manual](http://lacinia.readthedocs.io/en/latest/).
5757

58+
### Using as a Dependency
59+
60+
When using Lacinia as a dependency, you may need to prepare the library:
61+
62+
```bash
63+
clojure -X:deps prep
64+
```
65+
66+
This is required because Lacinia uses precompiled ANTLR parsers that need to be built before use.
67+
5868
GraphQL starts with a schema definition of types that can be queried.
5969

6070
A schema starts as an EDN file; the example below demonstrates a small subset
@@ -216,6 +226,34 @@ a dependency on [clojure-future-spec](https://github.com/tonsky/clojure-future-s
216226

217227
More details are [in the manual](http://lacinia.readthedocs.io/en/latest/clojure.html).
218228

229+
## Development
230+
231+
Lacinia uses ANTLR-generated parsers for GraphQL query and schema parsing.
232+
233+
### Building from Source
234+
235+
Compile the Java sources:
236+
237+
```bash
238+
clojure -T:build compile-java
239+
```
240+
241+
This compiles the ANTLR-generated parser classes into `target/classes`.
242+
243+
### Regenerating Parsers
244+
245+
If you modify the ANTLR grammar files (`.g4`), regenerate the Java parsers:
246+
247+
```bash
248+
./codegen.sh
249+
```
250+
251+
### Running Tests
252+
253+
```bash
254+
clojure -X:dev:test
255+
```
256+
219257
## License
220258

221259
Copyright © 2017-2025 WalmartLabs

build.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@
2121

2222
(def lib 'com.walmartlabs/lacinia)
2323
(def version (-> "VERSION.txt" slurp string/trim))
24+
(def class-dir "target/classes")
2425

2526
(def jar-params {:project-name lib
26-
:version version})
27+
:version version
28+
:class-dir class-dir})
2729

2830
(defn clean
2931
[_params]
3032
(build/delete {:path "target"}))
3133

34+
(defn compile-java [_]
35+
(build/javac {:src-dirs ["java"]
36+
:class-dir class-dir
37+
:basis (build/create-basis)
38+
:javac-opts ["--release" "11"]}))
39+
3240
(defn jar
3341
[_params]
42+
(compile-java nil)
3443
(b/create-jar jar-params))
3544

3645
(defn deploy

codegen.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
set -x
4+
5+
pip install antlr4-tools
6+
7+
export ANTLR4_TOOLS_ANTLR_VERSION=4.13.2
8+
9+
PACKAGE_NAME=com.walmartlabs.lacinia
10+
DIR=$(echo $PACKAGE_NAME | tr . /)
11+
12+
antlr4 resources/$DIR/Graphql.g4 -o java/$DIR -Xexact-output-dir -package $PACKAGE_NAME
13+
antlr4 resources/$DIR/GraphqlSchema.g4 -o java/$DIR -Xexact-output-dir -package $PACKAGE_NAME

deps.edn

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{:deps {org.clojure/clojure {:mvn/version "1.11.1"}
2-
clj-antlr/clj-antlr {:mvn/version "0.2.14"}
2+
org.antlr/antlr4-runtime {:mvn/version "4.13.2"}
33
org.flatland/ordered {:mvn/version "1.15.12"}
44
org.clojure/data.json {:mvn/version "2.5.1"}}
5-
:paths ["src" "resources"]
5+
:paths ["src" "resources" "target/classes"]
6+
7+
:deps/prep-lib
8+
{:ensure "target/classes"
9+
:alias :build
10+
:fn compile-java}
611
:aliases
712
{:dev
813
{:extra-deps {criterium/criterium {:mvn/version "0.4.6"}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
token literal names:
2+
null
3+
'query'
4+
'mutation'
5+
'subscription'
6+
'('
7+
')'
8+
':'
9+
'$'
10+
'='
11+
'{'
12+
'}'
13+
'...'
14+
'on'
15+
'fragment'
16+
'['
17+
']'
18+
'@'
19+
'!'
20+
null
21+
null
22+
'null'
23+
null
24+
null
25+
null
26+
'-'
27+
null
28+
null
29+
null
30+
null
31+
null
32+
null
33+
null
34+
35+
token symbolic names:
36+
null
37+
null
38+
null
39+
null
40+
null
41+
null
42+
null
43+
null
44+
null
45+
null
46+
null
47+
null
48+
null
49+
null
50+
null
51+
null
52+
null
53+
null
54+
BooleanValue
55+
NullValue
56+
Null
57+
NameId
58+
IntValue
59+
FloatValue
60+
Sign
61+
IntegerPart
62+
NonZeroDigit
63+
ExponentPart
64+
Digit
65+
StringValue
66+
BlockStringValue
67+
Ignored
68+
69+
rule names:
70+
document
71+
definition
72+
operationDefinition
73+
name
74+
operationType
75+
variableDefinitions
76+
variableDefinition
77+
variable
78+
defaultValue
79+
selectionSet
80+
selection
81+
field
82+
alias
83+
arguments
84+
argument
85+
fragmentSpread
86+
inlineFragment
87+
fragmentDefinition
88+
fragmentName
89+
typeCondition
90+
value
91+
enumValue
92+
arrayValue
93+
objectValue
94+
objectField
95+
directives
96+
directive
97+
type
98+
typeName
99+
listType
100+
nonNullType
101+
102+
103+
atn:
104+
[4, 1, 31, 243, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 1, 0, 4, 0, 64, 8, 0, 11, 0, 12, 0, 65, 1, 1, 1, 1, 3, 1, 70, 8, 1, 1, 2, 1, 2, 1, 2, 3, 2, 75, 8, 2, 1, 2, 3, 2, 78, 8, 2, 1, 2, 3, 2, 81, 8, 2, 1, 2, 1, 2, 3, 2, 85, 8, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 4, 5, 93, 8, 5, 11, 5, 12, 5, 94, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 103, 8, 6, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 4, 9, 113, 8, 9, 11, 9, 12, 9, 114, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 3, 10, 122, 8, 10, 1, 11, 3, 11, 125, 8, 11, 1, 11, 1, 11, 3, 11, 129, 8, 11, 1, 11, 3, 11, 132, 8, 11, 1, 11, 3, 11, 135, 8, 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 4, 13, 142, 8, 13, 11, 13, 12, 13, 143, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 3, 15, 155, 8, 15, 1, 16, 1, 16, 1, 16, 1, 16, 3, 16, 161, 8, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 17, 1, 17, 3, 17, 170, 8, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 3, 20, 188, 8, 20, 1, 21, 1, 21, 1, 22, 1, 22, 5, 22, 194, 8, 22, 10, 22, 12, 22, 197, 9, 22, 1, 22, 1, 22, 1, 23, 1, 23, 5, 23, 203, 8, 23, 10, 23, 12, 23, 206, 9, 23, 1, 23, 1, 23, 1, 24, 1, 24, 1, 24, 1, 24, 1, 25, 4, 25, 215, 8, 25, 11, 25, 12, 25, 216, 1, 26, 1, 26, 1, 26, 3, 26, 222, 8, 26, 1, 27, 1, 27, 1, 27, 3, 27, 227, 8, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 29, 1, 29, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 3, 30, 241, 8, 30, 1, 30, 0, 0, 31, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 0, 2, 2, 0, 1, 3, 21, 21, 1, 0, 1, 3, 246, 0, 63, 1, 0, 0, 0, 2, 69, 1, 0, 0, 0, 4, 84, 1, 0, 0, 0, 6, 86, 1, 0, 0, 0, 8, 88, 1, 0, 0, 0, 10, 90, 1, 0, 0, 0, 12, 98, 1, 0, 0, 0, 14, 104, 1, 0, 0, 0, 16, 107, 1, 0, 0, 0, 18, 110, 1, 0, 0, 0, 20, 121, 1, 0, 0, 0, 22, 124, 1, 0, 0, 0, 24, 136, 1, 0, 0, 0, 26, 139, 1, 0, 0, 0, 28, 147, 1, 0, 0, 0, 30, 151, 1, 0, 0, 0, 32, 156, 1, 0, 0, 0, 34, 164, 1, 0, 0, 0, 36, 173, 1, 0, 0, 0, 38, 175, 1, 0, 0, 0, 40, 187, 1, 0, 0, 0, 42, 189, 1, 0, 0, 0, 44, 191, 1, 0, 0, 0, 46, 200, 1, 0, 0, 0, 48, 209, 1, 0, 0, 0, 50, 214, 1, 0, 0, 0, 52, 218, 1, 0, 0, 0, 54, 226, 1, 0, 0, 0, 56, 228, 1, 0, 0, 0, 58, 230, 1, 0, 0, 0, 60, 240, 1, 0, 0, 0, 62, 64, 3, 2, 1, 0, 63, 62, 1, 0, 0, 0, 64, 65, 1, 0, 0, 0, 65, 63, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 1, 1, 0, 0, 0, 67, 70, 3, 4, 2, 0, 68, 70, 3, 34, 17, 0, 69, 67, 1, 0, 0, 0, 69, 68, 1, 0, 0, 0, 70, 3, 1, 0, 0, 0, 71, 85, 3, 18, 9, 0, 72, 74, 3, 8, 4, 0, 73, 75, 3, 6, 3, 0, 74, 73, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 77, 1, 0, 0, 0, 76, 78, 3, 10, 5, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 80, 1, 0, 0, 0, 79, 81, 3, 50, 25, 0, 80, 79, 1, 0, 0, 0, 80, 81, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 83, 3, 18, 9, 0, 83, 85, 1, 0, 0, 0, 84, 71, 1, 0, 0, 0, 84, 72, 1, 0, 0, 0, 85, 5, 1, 0, 0, 0, 86, 87, 7, 0, 0, 0, 87, 7, 1, 0, 0, 0, 88, 89, 7, 1, 0, 0, 89, 9, 1, 0, 0, 0, 90, 92, 5, 4, 0, 0, 91, 93, 3, 12, 6, 0, 92, 91, 1, 0, 0, 0, 93, 94, 1, 0, 0, 0, 94, 92, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 97, 5, 5, 0, 0, 97, 11, 1, 0, 0, 0, 98, 99, 3, 14, 7, 0, 99, 100, 5, 6, 0, 0, 100, 102, 3, 54, 27, 0, 101, 103, 3, 16, 8, 0, 102, 101, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 13, 1, 0, 0, 0, 104, 105, 5, 7, 0, 0, 105, 106, 3, 6, 3, 0, 106, 15, 1, 0, 0, 0, 107, 108, 5, 8, 0, 0, 108, 109, 3, 40, 20, 0, 109, 17, 1, 0, 0, 0, 110, 112, 5, 9, 0, 0, 111, 113, 3, 20, 10, 0, 112, 111, 1, 0, 0, 0, 113, 114, 1, 0, 0, 0, 114, 112, 1, 0, 0, 0, 114, 115, 1, 0, 0, 0, 115, 116, 1, 0, 0, 0, 116, 117, 5, 10, 0, 0, 117, 19, 1, 0, 0, 0, 118, 122, 3, 22, 11, 0, 119, 122, 3, 30, 15, 0, 120, 122, 3, 32, 16, 0, 121, 118, 1, 0, 0, 0, 121, 119, 1, 0, 0, 0, 121, 120, 1, 0, 0, 0, 122, 21, 1, 0, 0, 0, 123, 125, 3, 24, 12, 0, 124, 123, 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 126, 1, 0, 0, 0, 126, 128, 3, 6, 3, 0, 127, 129, 3, 26, 13, 0, 128, 127, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 131, 1, 0, 0, 0, 130, 132, 3, 50, 25, 0, 131, 130, 1, 0, 0, 0, 131, 132, 1, 0, 0, 0, 132, 134, 1, 0, 0, 0, 133, 135, 3, 18, 9, 0, 134, 133, 1, 0, 0, 0, 134, 135, 1, 0, 0, 0, 135, 23, 1, 0, 0, 0, 136, 137, 3, 6, 3, 0, 137, 138, 5, 6, 0, 0, 138, 25, 1, 0, 0, 0, 139, 141, 5, 4, 0, 0, 140, 142, 3, 28, 14, 0, 141, 140, 1, 0, 0, 0, 142, 143, 1, 0, 0, 0, 143, 141, 1, 0, 0, 0, 143, 144, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 146, 5, 5, 0, 0, 146, 27, 1, 0, 0, 0, 147, 148, 3, 6, 3, 0, 148, 149, 5, 6, 0, 0, 149, 150, 3, 40, 20, 0, 150, 29, 1, 0, 0, 0, 151, 152, 5, 11, 0, 0, 152, 154, 3, 36, 18, 0, 153, 155, 3, 50, 25, 0, 154, 153, 1, 0, 0, 0, 154, 155, 1, 0, 0, 0, 155, 31, 1, 0, 0, 0, 156, 157, 5, 11, 0, 0, 157, 158, 5, 12, 0, 0, 158, 160, 3, 38, 19, 0, 159, 161, 3, 50, 25, 0, 160, 159, 1, 0, 0, 0, 160, 161, 1, 0, 0, 0, 161, 162, 1, 0, 0, 0, 162, 163, 3, 18, 9, 0, 163, 33, 1, 0, 0, 0, 164, 165, 5, 13, 0, 0, 165, 166, 3, 36, 18, 0, 166, 167, 5, 12, 0, 0, 167, 169, 3, 38, 19, 0, 168, 170, 3, 50, 25, 0, 169, 168, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, 171, 172, 3, 18, 9, 0, 172, 35, 1, 0, 0, 0, 173, 174, 3, 6, 3, 0, 174, 37, 1, 0, 0, 0, 175, 176, 3, 56, 28, 0, 176, 39, 1, 0, 0, 0, 177, 188, 5, 22, 0, 0, 178, 188, 5, 23, 0, 0, 179, 188, 5, 29, 0, 0, 180, 188, 5, 30, 0, 0, 181, 188, 5, 18, 0, 0, 182, 188, 5, 19, 0, 0, 183, 188, 3, 42, 21, 0, 184, 188, 3, 44, 22, 0, 185, 188, 3, 46, 23, 0, 186, 188, 3, 14, 7, 0, 187, 177, 1, 0, 0, 0, 187, 178, 1, 0, 0, 0, 187, 179, 1, 0, 0, 0, 187, 180, 1, 0, 0, 0, 187, 181, 1, 0, 0, 0, 187, 182, 1, 0, 0, 0, 187, 183, 1, 0, 0, 0, 187, 184, 1, 0, 0, 0, 187, 185, 1, 0, 0, 0, 187, 186, 1, 0, 0, 0, 188, 41, 1, 0, 0, 0, 189, 190, 3, 6, 3, 0, 190, 43, 1, 0, 0, 0, 191, 195, 5, 14, 0, 0, 192, 194, 3, 40, 20, 0, 193, 192, 1, 0, 0, 0, 194, 197, 1, 0, 0, 0, 195, 193, 1, 0, 0, 0, 195, 196, 1, 0, 0, 0, 196, 198, 1, 0, 0, 0, 197, 195, 1, 0, 0, 0, 198, 199, 5, 15, 0, 0, 199, 45, 1, 0, 0, 0, 200, 204, 5, 9, 0, 0, 201, 203, 3, 48, 24, 0, 202, 201, 1, 0, 0, 0, 203, 206, 1, 0, 0, 0, 204, 202, 1, 0, 0, 0, 204, 205, 1, 0, 0, 0, 205, 207, 1, 0, 0, 0, 206, 204, 1, 0, 0, 0, 207, 208, 5, 10, 0, 0, 208, 47, 1, 0, 0, 0, 209, 210, 3, 6, 3, 0, 210, 211, 5, 6, 0, 0, 211, 212, 3, 40, 20, 0, 212, 49, 1, 0, 0, 0, 213, 215, 3, 52, 26, 0, 214, 213, 1, 0, 0, 0, 215, 216, 1, 0, 0, 0, 216, 214, 1, 0, 0, 0, 216, 217, 1, 0, 0, 0, 217, 51, 1, 0, 0, 0, 218, 219, 5, 16, 0, 0, 219, 221, 3, 6, 3, 0, 220, 222, 3, 26, 13, 0, 221, 220, 1, 0, 0, 0, 221, 222, 1, 0, 0, 0, 222, 53, 1, 0, 0, 0, 223, 227, 3, 56, 28, 0, 224, 227, 3, 58, 29, 0, 225, 227, 3, 60, 30, 0, 226, 223, 1, 0, 0, 0, 226, 224, 1, 0, 0, 0, 226, 225, 1, 0, 0, 0, 227, 55, 1, 0, 0, 0, 228, 229, 3, 6, 3, 0, 229, 57, 1, 0, 0, 0, 230, 231, 5, 14, 0, 0, 231, 232, 3, 54, 27, 0, 232, 233, 5, 15, 0, 0, 233, 59, 1, 0, 0, 0, 234, 235, 3, 56, 28, 0, 235, 236, 5, 17, 0, 0, 236, 241, 1, 0, 0, 0, 237, 238, 3, 58, 29, 0, 238, 239, 5, 17, 0, 0, 239, 241, 1, 0, 0, 0, 240, 234, 1, 0, 0, 0, 240, 237, 1, 0, 0, 0, 241, 61, 1, 0, 0, 0, 25, 65, 69, 74, 77, 80, 84, 94, 102, 114, 121, 124, 128, 131, 134, 143, 154, 160, 169, 187, 195, 204, 216, 221, 226, 240]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
T__0=1
2+
T__1=2
3+
T__2=3
4+
T__3=4
5+
T__4=5
6+
T__5=6
7+
T__6=7
8+
T__7=8
9+
T__8=9
10+
T__9=10
11+
T__10=11
12+
T__11=12
13+
T__12=13
14+
T__13=14
15+
T__14=15
16+
T__15=16
17+
T__16=17
18+
BooleanValue=18
19+
NullValue=19
20+
Null=20
21+
NameId=21
22+
IntValue=22
23+
FloatValue=23
24+
Sign=24
25+
IntegerPart=25
26+
NonZeroDigit=26
27+
ExponentPart=27
28+
Digit=28
29+
StringValue=29
30+
BlockStringValue=30
31+
Ignored=31
32+
'query'=1
33+
'mutation'=2
34+
'subscription'=3
35+
'('=4
36+
')'=5
37+
':'=6
38+
'$'=7
39+
'='=8
40+
'{'=9
41+
'}'=10
42+
'...'=11
43+
'on'=12
44+
'fragment'=13
45+
'['=14
46+
']'=15
47+
'@'=16
48+
'!'=17
49+
'null'=20
50+
'-'=24

0 commit comments

Comments
 (0)