Repository navigation
parser: generated ANTLR front-ends and an SPL2 subset - #1
Merged
Merged
Conversation
Add pinned ANTLR 4.13.2 generation for the classic SPL and SPL2 grammars and commit the generated Go, so builds, Docker, and releases need neither Java nor the ANTLR jar. make generate rewrites both gen trees; make generate-check fails on drift and runs in CI. The ANTLR Go runtime is the only new module.
The combined grammar owns commands, expressions, precedence, and the search-literal versus field-reference rule sets. A small Go driver sequences stages, classifies command names, and lowers each stage as it is parsed so the existing fail-fast diagnostic priority is preserved. SourceMap converts ANTLR rune indexes to byte-based ast.Pos, the error listener turns the first grammar rejection into a positioned diagnostic, and tight.go resolves adjacent wildcard and hyphen runs before prediction. Lexer parity tests and fuzz targets guard the duplicated lexical rules.
SPL2 gets its own ANTLR grammar and lowering for from, where, and stats. A pipeline must start at a dataset, bare words are field references on both sides of a comparison, AND is explicit, and a wildcard outside a dataset name is a syntax error. from main lowers to the same IR as index=main, so emitters and mappings apply unchanged. Namespaced datasets are refused with unsupported-dataset. compiler.Options.SPLVersion and ParseVersion select the dialect; the CLI exposes --spl-version 1|2 and rejects any other value as a usage error. The conformance runner accepts options.spl_version and fails on unknown values.
Cover the subset end to end: plain, wildcard, and hyphenated datasets; where and stats lowering; a PromQL time-series case with its warnings; and refusals for classic SPL syntax, namespaced datasets, a wildcard expression, an unsupported command, and a second from stage.
Describe the ANTLR grammars, committed generated code, SourceMap, stage driver, and visitor lowering; add ADR 0004 amending the empty-module-graph decision; and record the single runtime dependency in the notices, security policy, and README. Document the SPL2 input dialect, --spl-version, spl_version conformance metadata, the new diagnostics, and the regeneration workflow.
A wildcard that touches the preceding word belongs to that term, so `error* | stats count` no longer reads the star as multiplication with a missing operand. The driver retypes such a star as STAR_TERM, and the term-position multiplication rule excludes it. `atSearchMul` keeps the term position's operator set separate from the expression one. `not` is a field name after an arithmetic or comparison operator (`eval x=1+not`) but the negation operator at the start of an expression (`eval x=not(2)`). The driver retypes the former as NOT_WORD, including after an `eval` that begins the pipeline with no leading pipe. Out-of-range numbers are rejected in the lexical pass again, so a bad number in a later stage still wins over an earlier semantic error, and a malformed numeric literal quotes the whole letter run instead of its first byte. Adds regression tests for both token passes and a conformance case for a wildcard term immediately before a stage.
Compose interpolates every service in the files it reads, including one behind a profile, so the required SPLUNK_PASSWORD broke `make e2e` for everyone. Move the optional Splunk oracle into docker-compose.splunk.yml and start it only when the reference check is wanted. The engine error checks also grepped the raw response text. A row value can be the word "error" (for example an eval result) without the engine failing, which made eval-sort-head fail on a successful query. Parse the top-level JSON field instead. Verified with `make check` and `make e2e` (8 passed, 0 failed).
be-thomas
commented
Oct 26, 2026
be-thomas
left a comment
Owner
Author
There was a problem hiding this comment.
Reviewed the full diff at 257c293. Independently verified:
make checkpasses.make generate-checkregenerates both parsers with no drift.go test ./conformance -updateleaves the working tree clean (no golden churn).- About 2,200 differential queries (directed plus generated) against main, comparing AST, exit code, and diagnostic code/line/column. The known position-shift cases (
a + (b,a AND (b,y-(x,by*index]) reproduce exactly and are not re-reported.
Five correctness defects are inline: silent operator loss (STAR_TERM), rejected keyword sort fields, star-as-term in value expressions (both accepts and rejects), not after a wildcard star, and one fail-fast ordering regression in bin.
A star that follows a completed operand is a multiplication operator, and the grammar now says so with its own STAR_OP token. A semantic predicate cannot carry that decision: SLL prediction simulates the implicit-AND alternative whenever both sides start with a star and never asks. Operand positions accept operandStar only, so `a * *` parses as `a * TRUE`, while `where (a*)` reports the missing operand at the `)`. Multiplicative operator lowering accepts every star spelling, so `eval x=a*b` and `eval pct=count/total*100` multiply instead of losing the operator. `sort` treats a word after a sign as a field name, so `sort -limit` and `sort -not` no longer read as the limit keyword or the negation operator. `bin` refuses a second field at that field's token, so a later argument error cannot overtake it. A `not` after an assignment's `=` negates the value that follows, so `eval y=not * b` is `NOT TRUE AND b`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Replaces the hand-written classic-SPL lexer and recursive-descent parser with
ANTLR 4.13.2 grammars and generated Go, and adds a working SPL2 subset. The
hand parser is deleted; the public
Parse,Lex, andTokencontracts arepreserved.
Parsers
pkg/parser/spl1/grammar/SPL1.g4describes the whole classic-SPL surface:commands, search expressions, field-reference expressions, and the
literal-versus-expression split on the right of a comparison.
pkg/parser/spl2/grammar/SPL2.g4describes the subset:from,where, andstats, withfrom <dataset>lowering to the sameindex = "<dataset>"shape the SPL1 front-end produces.
pkg/parser/spl1/genandpkg/parser/spl2/gen, sogo build,go install, Docker, and releasebuilds need neither Java nor the ANTLR jar.
.gitattributesmarks the treesas generated.
pkg/parser/internal/antlrposmaps ANTLR rune indexes to byte-basedast.Pos.pkg/parser/internal/antlrsupportrecords the first syntax erroras one positioned
diag.Errorand aborts the parse.tight.goretypes a few tokens in the stream before parsing, becauseALL(*) prediction cannot use semantic predicates to choose between the two
meanings of a word. The passes cover value-run starts, a wildcard that
touches the preceding term, and
notafter an operator (field name) versusat the start of an expression (negation).
Dialect plumbing
compiler.Options.SPLVersion:0/1select classic SPL,2selects SPL2,anything else is refused with
unsupported-spl-versionat 1:1.--spl-version 1|2ontranspileandast; invalid values exit 2.options.spl_version; newconformance/cases/spl2/and
conformance/cases/search/wildcard-term-before-stage.*cases.Tooling, dependencies, docs
v4.13.1 and its indirect
golang.org/x/exp.scripts/generate-parsers.shpins the ANTLR 4.13.2 jar by SHA-256 andregenerates both grammars;
make generate/make generate-checkwrap it,and CI runs
generate-checkin a Java-only job.CHANGELOG, SECURITY, and THIRD_PARTY_NOTICES describe the generated parsers
and the SPL2 subset.
Tests run
make check(format, vet, all tests, build)make generate-check(both regenerated trees match the committed ones;generation is idempotent)
go test -race ./...GOMAXPROCS=1 go test ./...go test ./conformance -count=1, thenmake conformance-updatewith nochanges to existing goldens
go test ./pkg/parser/spl1 -fuzz FuzzParseSPL1 -fuzztime 30sand the samefor
FuzzParseSPL2; no failuresSPL1 conformance case and a 35-case
notmatrix: result codes and positionsmatch; AST JSON is byte-identical for accepted queries
--spl-version 2ontranspileandast,invalid
--spl-versionexits 2, and--strictstill fails on warningsdocker run ... transpileOpen questions
unexpected ","instead of the hand parser'sexpected ')', found ','.The documented contract is the
syntaxcode and its position; the wordingis not. Is the new wording acceptable?
a + (b,a AND (b,y-(x, andby*index], ALL(*) prediction can commit to a rulewhose failure is reported slightly left of the hand parser's position,
because predicates are not used to prune the simulation. Codes and
fail-fast ordering are unchanged. Is that tradeoff acceptable, or should a
follow-up add a pre-pass for these shapes?
from,where, andstats; namespaceddatasets (
datamodel:/lookup:) andcount(*)are refused withpositioned diagnostics rather than guessed. Confirm this is the right
boundary for the first SPL2 release.