Skip to content

Commit 0e7bac9

Browse files
authored
feat: add ANTLR v4 grammar parser with CI integration (#13)
feat: antlr v4 self grammar
1 parent b61cb63 commit 0e7bac9

14 files changed

+15740
-2
lines changed

.github/workflows/tests.yml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,60 @@ jobs:
102102
# awk: accumulate sum by test time in seconds
103103
run: grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}'
104104

105+
antlr-grammar-tests:
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v4
109+
with:
110+
fetch-depth: 0
111+
112+
- name: Check for grammar file changes
113+
id: check-grammar-changes
114+
run: |
115+
if [ "${{ github.event_name }}" = "pull_request" ]; then
116+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD)
117+
else
118+
CHANGED_FILES=$(git diff --name-only HEAD~1..HEAD)
119+
fi
120+
121+
# Check if any .g4 files or tools/grammar/ files changed (Go target only)
122+
if echo "$CHANGED_FILES" | grep -E '\.(g4)$|^tools/grammar/'; then
123+
echo "grammar_changed=true" >> $GITHUB_OUTPUT
124+
echo "Grammar files or tools/grammar/ changed, running Go ANTLR tests"
125+
else
126+
echo "grammar_changed=false" >> $GITHUB_OUTPUT
127+
echo "No grammar file changes detected, skipping ANTLR tests"
128+
fi
129+
130+
- uses: actions/setup-go@v5
131+
if: steps.check-grammar-changes.outputs.grammar_changed == 'true'
132+
with:
133+
go-version-file: go.mod
134+
cache-dependency-path: go.sum
135+
136+
- name: Run Go ANTLR grammar tests
137+
if: steps.check-grammar-changes.outputs.grammar_changed == 'true'
138+
working-directory: tools/grammar
139+
run: go test -p=8 -timeout 30m -ldflags "-w -s" -v ./... | tee test.log; exit ${PIPESTATUS[0]}
140+
141+
- name: Pretty print grammar tests running time
142+
if: steps.check-grammar-changes.outputs.grammar_changed == 'true'
143+
working-directory: tools/grammar
144+
# grep: filter out lines like "--- PASS: Test (15.04s)"
145+
# sed: remove unnecessary characters
146+
# awk: re-format lines to "PASS: Test (15.04s)"
147+
# sort: cut into columns by delimiter ' ' (single space) and sort by column 3 (test time in seconds) as numeric type in reverse order (largest comes first)
148+
# awk: accumulate sum by test time in seconds
149+
run: grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}'
150+
105151
all-tests-passed:
106152
runs-on: ubuntu-latest
107-
# This job needs both detect-changes and go-tests
108-
needs: [detect-changes, go-tests]
153+
# This job needs detect-changes, go-tests, and antlr-grammar-tests
154+
needs: [detect-changes, go-tests, antlr-grammar-tests]
109155
# This condition is key:
110156
# - Run if no files were changed (the 'go-tests' job was skipped).
111157
# - Or run if the 'go-tests' job (the whole matrix) succeeded.
158+
# - And run if antlr-grammar-tests succeeded or was skipped.
112159
if: success() || needs.detect-changes.outputs.any_changed == 'false'
113160
steps:
114161
- name: Report overall status

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ go.work.sum
4141
**/*.interp
4242
**/*.tokens
4343

44+
# node_modules
45+
**/node_modules/

0 commit comments

Comments
 (0)