diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..93011e0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# ANTLR output is generated; review the .g4 grammar instead. +pkg/parser/*/gen/** linguist-generated=true +pkg/parser/*/gen/** -diff + +*.g4 linguist-language=ANTLR +*.g4 text eol=lf + +go.sum text eol=lf +*.sh text eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f84708..962a5bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: run: make fmt-check - name: Vet - run: go vet ./... + run: make vet - name: Test run: go test -race ./... @@ -48,6 +48,26 @@ jobs: ./openspl transpile -t esql 'index=web status>=500 | stats count by host' ./openspl transpile -t promql --metric http_requests_total 'index=metrics | stats count by host' + generated: + name: generated parsers + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - name: Cache the pinned ANTLR jar + uses: actions/cache@v4 + with: + path: ~/.cache/openspl + key: antlr-4.13.2 + + - name: Check generated code matches the grammars + run: make generate-check + commit-message: name: commit messages runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 29ad4f7..e42c53d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,32 @@ All notable changes to this project are documented here. The format follows ## [Unreleased] +### Added + +- Parsing for both dialects is generated from ANTLR grammars + (`pkg/parser/spl1/grammar/SPL1.g4`, `pkg/parser/spl2/grammar/SPL2.g4`). The + generated Go is committed, so builds and releases need neither Java nor the + ANTLR jar; `make generate-check` fails on drift. +- A working SPL2 subset: `from `, `where`, and `stats`, selected with + `--spl-version 2` (or `compiler.Options.SPLVersion`). `from main` lowers to + the same IR as `index=main`, so all emitters and mappings apply unchanged. +- `unsupported-dataset` for namespaced SPL2 datasets and + `unsupported-spl-version` for unknown dialect numbers. +- Conformance cases under `cases/spl2/` and an `options.spl_version` metadata + key; unknown versions fail the case instead of silently running as classic + SPL. +- Fuzz targets `FuzzParseSPL1` and `FuzzParseSPL2`, and a lexer-parity test + that tokenizes one corpus with both generated lexers. + +### Changed + +- The module graph is no longer empty: the binary links the ANTLR Go runtime + and its transitive `golang.org/x/exp` helper. [ADR 0004](docs/adr/0004-antlr-parsers.md) + records the exception and the pinned version pair. +- SPL2 no longer returns `spl2-not-implemented`; constructs outside the subset + are refused with a positioned `unsupported-command`, `unknown-command`, or + `unsupported-dataset` diagnostic. + ### Fixed - ES|QL aggregations now use the valid `alias = COUNT(*)` form instead of the @@ -44,7 +70,6 @@ All notable changes to this project are documented here. The format follows ### Planned -- SPL2 front-end - Docker parity harness results - `dedup`, `top`, `rare`, `rename`, `fillnull` - Batch migration reports diff --git a/CONFORMANCE.md b/CONFORMANCE.md index 5da92af..c2a4f94 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -16,6 +16,7 @@ conformance/ │ ├── shaping/ table, fields, sort, head │ ├── mapping/ custom field and index mappings │ ├── promql/ PromQL-specific output and refusals +│ ├── spl2/ SPL2 subset (`spl_version: 2`) │ └── errors/ parser and unsupported-construct refusals ├── fixtures/ │ ├── mappings/ mapping files referenced by case metadata @@ -56,7 +57,8 @@ exercised by that case. A case must be exercised by at least one target. "options": { "metric": "http_requests_total", "span": "1m", - "index": "logs-*" + "index": "logs-*", + "spl_version": 2 }, "targets": { "esql": { @@ -75,7 +77,8 @@ exercised by that case. A case must be exercised by at least one target. |---|---| | `description` | Free text. Never asserted. | | `mapping` | Mapping file, relative to the case file. | -| `options` | `metric`, `span`, and `index` passed to the compiler. | +| `options` | `metric`, `span`, `index`, and `spl_version` passed to the compiler. | +| `options.spl_version` | Input dialect. `1` (or absent) is classic SPL, `2` is the SPL2 subset. Any other value fails the case rather than silently falling back. | | `targets..diagnostics` | The complete warning/info list with exact positions. Order is line, then column, then severity (`error`, `info`, `warning`), then code. | | `targets..error` | The target must refuse the query with this error code and position. No golden file may exist. | @@ -110,6 +113,7 @@ Directories are the suite grouping, so Go's `-run` selects an area: ```sh go test ./conformance -run 'TestConformance/promql' -v go test ./conformance -run 'TestConformance/errors' -v +go test ./conformance -run 'TestConformance/spl2' -v ``` Cases and their per-target checks run in parallel, bounded by `GOMAXPROCS`, so diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ee9aa8d..1d2907b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,27 @@ make check # format check, vet, tests, build ``` Requirements: Go 1.24+ and `make`. Docker is optional, for the engine harness. +Java 17 is needed only to regenerate the parser sources, not to build or test. + +## Generated parsers + +Both dialects are ANTLR grammars. Generated Go is committed, so a normal build +never needs Java or the ANTLR jar. + +| Path | Contents | +|---|---| +| `pkg/parser/spl1/grammar/SPL1.g4` | Classic SPL grammar (source of truth) | +| `pkg/parser/spl2/grammar/SPL2.g4` | SPL2 subset grammar (source of truth) | +| `pkg/parser/spl1/gen`, `pkg/parser/spl2/gen` | Generated lexer, parser, visitor; never hand-edited | + +```bash +make generate # rewrite the gen/ trees (needs Java 17) +make generate-check # fail if gen/ is stale; runs in CI +``` + +Edit the `.g4`, run `make generate`, and commit both the grammar and the +regenerated output. A change that edits only `gen/` is rejected by review and +by `make generate-check`. ## Repository layout @@ -22,8 +43,12 @@ Requirements: Go 1.24+ and `make`. Docker is optional, for the engine harness. | `cmd/openspl` | CLI entry point | | `pkg/ast` | Unified IR | | `pkg/diag` | Positioned diagnostics | -| `pkg/parser/spl1` | Classic SPL front-end | -| `pkg/parser/spl2` | SPL2 front-end (reserved) | +| `pkg/parser/spl1` | Classic SPL front-end: stage driver, visitor, `Lex` adapter | +| `pkg/parser/spl2` | SPL2 subset front-end | +| `pkg/parser/commands` | Implemented and known command-name tables, per dialect | +| `pkg/parser/internal/antlrpos` | Byte-accurate `ast.Pos` source map | +| `pkg/parser/internal/antlrsupport` | Error listener and bail/recover | +| `pkg/parser/internal/lexerparity` | Test-only SPL1/SPL2 lexical parity gate | | `pkg/mapping` | Field, index, and label mapping | | `pkg/emitter/esql` | ES\|QL back-end | | `pkg/emitter/promql` | PromQL back-end | @@ -65,8 +90,11 @@ Reject mixed label matchers in PromQL 1. **IR:** add a stage or expression node in `pkg/ast` if no existing node fits. Every node implements `StageName()`/`Position()` or `exprNode()`/`Position()`. -2. **Parser:** lex and parse the command in `pkg/parser/spl1`. If the command is - recognized but not implemented, add it to `knownCommands` so users get +2. **Grammar:** add the command's rule to the relevant `.g4`, run + `make generate`, and lower the new rule context in that front-end's + `build.go`. The Go driver in `parse.go` only sequences stages and classifies + command names; it is not a second parser. If the command is recognized but + not implemented, add it to `pkg/parser/commands` so users get `unsupported-command` rather than a misleading syntax error. 3. **Emitters:** implement the ES|QL mapping and decide the PromQL tier (supported or refused). An unsupported stage must return a diagnostic with a @@ -124,15 +152,15 @@ Do not parse SPL in the emitter. If the IR lacks something, add an IR node. | Errors | `diag.NewError` with a stable code and source position | | Warnings | `warnf` with a code that appears in `docs/COMPATIBILITY.md` | | Naming | Short, package-local; exported API documented | -| Dependencies | Standard library only; justify any exception in an ADR | +| Dependencies | Standard library plus the pinned ANTLR runtime; any further exception needs an ADR | | Tests | Table-driven; assert codes and exact output | ## Pull request checklist -- [ ] `make check` passes +- [ ] `make check` and `make generate-check` pass - [ ] New behavior has tests and, when relevant, a conformance case - [ ] Diagnostic codes are documented -- [ ] No new third-party dependencies +- [ ] No new third-party dependencies beyond the ANTLR runtime ([ADR 0004](docs/adr/0004-antlr-parsers.md)) - [ ] Commit messages follow the hard rule - [ ] The PR description explains the semantic mapping and its risks diff --git a/Dockerfile b/Dockerfile index d256106..8d965c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ ARG COMMIT=none ARG DATE=unknown WORKDIR /src -COPY go.mod ./ +COPY go.mod go.sum ./ +RUN go mod download COPY . . RUN CGO_ENABLED=0 go build -trimpath \ diff --git a/Makefile b/Makefile index 645526c..9217c4c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ LDFLAGS := -s -w \ -X github.com/be-thomas/openspl/pkg/version.Commit=$(COMMIT) \ -X github.com/be-thomas/openspl/pkg/version.Date=$(DATE) -.PHONY: all build test race vet fmt fmt-check check hooks conformance conformance-update e2e clean help +.PHONY: all build test race vet fmt fmt-check check hooks generate generate-check conformance conformance-update e2e clean help all: check @@ -20,8 +20,14 @@ test: race: go test -race ./... +# Generated ANTLR parsers trip vet's unreachable analyzer: upstream codegen +# emits a defensive `goto` after a `return` in every rule. They are vetted with +# that one analyzer disabled; hand-written packages get the full set. vet: - go vet ./... + @handwritten="$$(go list ./... | grep -v '/gen$$' || true)"; \ + if [ -n "$$handwritten" ]; then go vet $$handwritten; fi + @generated="$$(go list ./... | grep '/gen$$' || true)"; \ + if [ -n "$$generated" ]; then go vet -unreachable=false $$generated; fi fmt: gofmt -w . @@ -36,10 +42,23 @@ check: fmt-check vet test build @echo "ok: format, vet, tests, build" hooks: - chmod +x .githooks/commit-msg .githooks/pre-commit scripts/check-commit-message.sh conformance/engines/run.sh + chmod +x .githooks/commit-msg .githooks/pre-commit scripts/check-commit-message.sh scripts/generate-parsers.sh conformance/engines/run.sh git config core.hooksPath .githooks @echo "installed: core.hooksPath=.githooks" +# Regenerate the ANTLR parsers. Needs Java 17+; builds never do. +generate: + ./scripts/generate-parsers.sh + +generate-check: + ./scripts/generate-parsers.sh + @changed="$$(git status --porcelain -- pkg/parser/spl1/gen pkg/parser/spl2/gen)"; \ + if [ -n "$$changed" ]; then \ + echo "generated parsers are out of date; run make generate and commit the result"; \ + echo "$$changed"; exit 1; \ + fi + @echo "generated parsers are current" + conformance: go test ./conformance -count=1 @@ -63,6 +82,8 @@ help: 'fmt-check fail if sources are not formatted' \ 'check format check + vet + test + build' \ 'hooks install the commit hooks' \ + 'generate regenerate the ANTLR parsers (needs Java 17+)' \ + 'generate-check fail if committed parsers differ from the grammars' \ 'conformance run the offline conformance suite' \ 'conformance-update regenerate goldens and expectations' \ 'e2e run the Docker engine harness' \ diff --git a/README.md b/README.md index 802ed55..8a887ff 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![CI](https://github.com/be-thomas/openspl/actions/workflows/ci.yml/badge.svg)](https://github.com/be-thomas/openspl/actions/workflows/ci.yml) [![Go](https://img.shields.io/badge/Go-1.24+-00ADD8?logo=go&logoColor=white)](https://go.dev) - [![Dependencies](https://img.shields.io/badge/dependencies-0-34d399)](go.mod) + [![Dependencies](https://img.shields.io/badge/dependencies-1_runtime-34d399)](go.mod) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Status](https://img.shields.io/badge/status-alpha-orange)](#project-status) [![PRs](https://img.shields.io/badge/PRs-welcome-22d3ee)](CONTRIBUTING.md) @@ -17,7 +17,7 @@

OpenSPL — Splunk SPL to Elastic ES|QL & PromQL Transpiler

Translate Splunk SPL into Elastic ES|QL or Prometheus PromQL.
- Deterministic. Offline. Zero dependencies. Every warning points at the exact token.

+ Deterministic. Offline. No runtime services. Every warning points at the exact token.

--- @@ -67,9 +67,11 @@ sum by (host) (increase(splunk_events_total{job="metrics"}[5m])) |---|---|---|---| | **`esql`** | Elasticsearch ES\|QL | ✅ Supported | Logs, search, stats, timecharts, regex extraction | | **`promql`** | Prometheus | ✅ Supported | Counters and rate-style time-series aggregations | -| `spl2` | Splunk SPL2 | 🧪 Planned | Next-generation Splunk pipelines | | `kusto` | Azure Data Explorer | 💡 Proposed | Microsoft observability stacks | +SPL2 is an **input dialect**, not a target. Pass `--spl-version 2` to parse the +supported subset (`from`, `where`, `stats`) and emit either target above. + ### Fidelity contract | Tier | Meaning | Example | @@ -145,6 +147,7 @@ openspl transpile --strict -f savedsearch.spl | `--index name` | Override the index selected in the query | from SPL | | `--metric name` | PromQL metric name | `splunk_events_total` | | `--span duration` | PromQL range window or timechart fallback | `5m` | +| `--spl-version 1\|2` | Input dialect: classic SPL or the SPL2 subset | `1` | | `-f, --file file` | Read the query from a file (`-` = stdin) | stdin | | `--json` | Emit JSON with `ok`, `query`, and diagnostics | off | | `--strict` | Treat warnings as errors | off | @@ -177,6 +180,24 @@ openspl transpile --strict -f savedsearch.spl **Recognized but not implemented** — `join`, `lookup`, `transaction`, `eventstats`, `streamstats`, `dedup`, `top`, `rare`, `chart`, `append`, `multisearch`, subsearches, and more. These return `unsupported-command` with a precise position rather than a misleading parse. +### SPL2 subset + +With `--spl-version 2`, a pipeline must start at `from` and may continue with +`where` and `stats`: + +```console +$ openspl transpile --spl-version 2 'from main | where status=500 | stats count() AS count BY host' + +FROM main +| WHERE status == 500 +| STATS count = COUNT(*) BY `host.name` +``` + +SPL2 semantics are not classic SPL: a bare word is a field reference on both +sides of a comparison, and conditions need an explicit `AND`. Namespaced +datasets (`datamodel:…`, `lookup:…`) and every command outside the subset are +refused with a positioned diagnostic. + Full matrix → [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md) --- @@ -185,8 +206,8 @@ Full matrix → [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md) ```mermaid flowchart LR - A["SPL v1
classic Splunk"] --> P1["spl1 parser"] - B["SPL v2
planned"] --> P2["spl2 parser"] + A["SPL v1
classic Splunk"] --> P1["spl1 ANTLR grammar"] + B["SPL v2
supported subset"] --> P2["spl2 ANTLR grammar"] P1 --> IR["Unified IR
pkg/ast"] P2 --> IR IR --> M["Mapping
ECS · indexes · labels"] @@ -201,8 +222,9 @@ flowchart LR | Layer | Package | Responsibility | |---|---|---| -| Front-end | `pkg/parser/spl1` | Lex + parse classic SPL into IR. Knows nothing about targets. | -| Front-end | `pkg/parser/spl2` | Reserved SPL2 grammar. | +| Front-end | `pkg/parser/spl1` | ANTLR grammar and generated parser for classic SPL; lowers into IR. | +| Front-end | `pkg/parser/spl2` | ANTLR grammar for the SPL2 subset (`from`, `where`, `stats`). | +| Generated | `pkg/parser/*/gen` | Committed ANTLR output; edit the `.g4`, never these files. | | IR | `pkg/ast` | One typed pipeline shared by every language. | | Mapping | `pkg/mapping` | Splunk field → ECS field, index patterns, Prometheus labels. | | Back-end | `pkg/emitter/esql` | IR → ES\|QL. | @@ -279,7 +301,7 @@ Only time-series aggregations. PromQL has no concept of raw log rows, so OpenSPL
Does OpenSPL call an LLM or send my queries anywhere? -No. It is a Go compiler with zero external dependencies. Queries are processed in memory, and the process makes no network calls. This matters when searches contain internal hostnames, customer identifiers, or credentials. +No. Queries are processed in memory, and the process makes no network calls. The binary links one third-party module, the ANTLR Go parser runtime; there are no services, plugins, or telemetry. This matters when searches contain internal hostnames, customer identifiers, or credentials.
@@ -291,7 +313,7 @@ OpenSPL is deterministic: the same input and mapping produce the same bytes. Eve
Does it support SPL2? -Not yet. SPL2 lives in its own front-end package so its grammar and semantics do not leak into classic SPL. Until it ships, the package returns `spl2-not-implemented`. +Partially: `--spl-version 2` accepts `from`, `where`, and `stats`, emitting the same targets as classic SPL. SPL2 lives in its own ANTLR grammar and front-end so its semantics do not leak into classic SPL. Every other SPL2 command is recognized and refused with a position; see [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md).
diff --git a/SECURITY.md b/SECURITY.md index 00b37ba..a912ce7 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -39,22 +39,28 @@ OpenSPL is an offline compiler. It parses text and prints text. | Telemetry | None | | Accounts or credentials | None | | Query persistence | None; input is processed in memory | -| Third-party Go dependencies | None | +| Third-party Go dependencies | One: the ANTLR Go parser runtime and its transitive `golang.org/x/exp` helper, both pinned in `go.mod` and recorded in [ADR 0004](docs/adr/0004-antlr-parsers.md) | +| Build-time tools | ANTLR 4.13.2 and Java 17 are needed only to regenerate the committed parser code, never to build or run the binary | | Shell execution | None | | File writes | Only the output the caller redirects | The primary risks are therefore: 1. **Parsing denial of service** — pathological input causing excessive CPU or - memory. Reports are welcome; the parser is single-pass and bounded by input - size, but nested expressions are recursive. + memory. Reports are welcome; lexing is single-pass and bounded by input size, + but nested expressions and ANTLR's adaptive prediction are recursive. The + generated parsers have fuzz targets (`FuzzParseSPL1`, `FuzzParseSPL2`); their + seed corpora run with the normal test suite, and every accepted failure must + be a positioned diagnostic, never a panic. 2. **Diagnostic injection** — untrusted query text containing control characters that corrupt terminal output. Messages preserve source values; avoid piping diagnostics from untrusted sources into privileged logs without sanitizing. 3. **Misleading translation** — a warning that is ignored. Use `--strict` in CI and review `rex-lossy`, `fulltext-approximation`, and `default-span` warnings. -4. **Supply chain** — the module graph is empty. Verify releases against the - published checksums when available. +4. **Supply chain** — the runtime graph is two pinned modules. Releases embed + `go.sum`; verify releases against their published checksums when available. + Generated parser sources are committed, so a release build compiles the same + Go files a reviewer can see, with no code generation step. ## Secrets in queries diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md new file mode 100644 index 0000000..3a8f7ea --- /dev/null +++ b/THIRD_PARTY_NOTICES.md @@ -0,0 +1,45 @@ +# Third-party notices + +OpenSPL is distributed under the license in [LICENSE](LICENSE). It links one +third-party runtime library and uses one third-party build tool. Both are +listed here with their versions and licenses. + +## ANTLR 4 Go runtime + +| Field | Value | +|---|---| +| Module | `github.com/antlr4-go/antlr/v4` | +| Version | `v4.13.1` | +| License | BSD 3-Clause | +| Upstream | | +| Role | Runtime support for the generated SPL1 and SPL2 parsers. Linked into every OpenSPL binary. | + +## golang.org/x/exp + +| Field | Value | +|---|---| +| Module | `golang.org/x/exp` | +| Version | `v0.0.0-20240506185415-9bf2ced13842` | +| License | BSD 3-Clause | +| Upstream | | +| Role | Indirect dependency of the ANTLR Go runtime. | + +## ANTLR tool + +| Field | Value | +|---|---| +| Artifact | `org.antlr:antlr4:4.13.2` complete jar | +| SHA-256 | `eae2dfa119a64327444672aff63e9ec35a20180dc5b8090b7a6ab85125df4d76` | +| License | BSD 3-Clause | +| Upstream | | +| Role | Build-time only. Generates the Go parser sources committed under `pkg/parser/*/gen`. Never shipped, and not needed to build OpenSPL. | + +## Generated code + +The Go files under `pkg/parser/spl1/gen` and `pkg/parser/spl2/gen` are produced +from the grammars in this repository by the ANTLR tool. They are covered by the +BSD 3-Clause license above because they embed portions of ANTLR's generated +runtime scaffolding; the grammar itself is part of OpenSPL. + +See [ADR 0004](docs/adr/0004-antlr-parsers.md) for the version pairing and the +upgrade procedure. diff --git a/cmd/openspl/main.go b/cmd/openspl/main.go index ffc8910..dfc9b02 100644 --- a/cmd/openspl/main.go +++ b/cmd/openspl/main.go @@ -15,7 +15,6 @@ import ( "github.com/be-thomas/openspl/pkg/compiler" "github.com/be-thomas/openspl/pkg/diag" "github.com/be-thomas/openspl/pkg/mapping" - "github.com/be-thomas/openspl/pkg/parser/spl1" "github.com/be-thomas/openspl/pkg/version" ) @@ -65,10 +64,14 @@ Transpile flags: --index name override the index selected by the query --metric name PromQL metric name (default from mapping) --span duration PromQL range window / timechart default (e.g. 5m) + --spl-version 1|2 input dialect (default 1: classic SPL; 2: SPL2) -f, --file file read the query from a file ("-" for stdin) --json emit machine-readable JSON --strict treat warnings as errors +AST flags: + --spl-version 1|2 input dialect (default 1: classic SPL; 2: SPL2) + Examples: openspl transpile 'index=web status=500 | stats count by host' openspl transpile -t promql 'index=metrics | timechart span=5m count by host' @@ -83,6 +86,7 @@ func cmdTranspile(args []string) int { fs.SetOutput(io.Discard) target := "esql" + splVersion := compiler.SPLVersion1 var mappingPath, index, metric, span, file string var jsonOut, strict bool @@ -92,6 +96,7 @@ func cmdTranspile(args []string) int { fs.StringVar(&index, "index", "", "index override") fs.StringVar(&metric, "metric", "", "PromQL metric name") fs.StringVar(&span, "span", "", "span or range") + fs.IntVar(&splVersion, "spl-version", compiler.SPLVersion1, "input SPL dialect version") fs.StringVar(&file, "file", "", "query file") fs.StringVar(&file, "f", "", "query file") fs.BoolVar(&jsonOut, "json", false, "JSON output") @@ -112,6 +117,11 @@ func cmdTranspile(args []string) int { return 2 } + if !supportedSPLVersion(splVersion) { + fmt.Fprintf(os.Stderr, "openspl: unsupported SPL version %d; supported versions: 1, 2\n", splVersion) + return 2 + } + var cfg *mapping.Config if mappingPath != "" { cfg, err = mapping.Load(mappingPath) @@ -130,10 +140,11 @@ func cmdTranspile(args []string) int { } res, _, err := compiler.Compile(src, t, compiler.Options{ - Index: index, - Metric: metric, - Span: span, - Mapping: cfg, + Index: index, + Metric: metric, + Span: span, + Mapping: cfg, + SPLVersion: splVersion, }) diagnostics := []diag.Diagnostic{} @@ -200,21 +211,28 @@ func cmdAST(args []string) int { fs := flag.NewFlagSet("ast", flag.ContinueOnError) fs.SetOutput(io.Discard) + splVersion := compiler.SPLVersion1 var file string fs.StringVar(&file, "file", "", "query file") fs.StringVar(&file, "f", "", "query file") + fs.IntVar(&splVersion, "spl-version", compiler.SPLVersion1, "input SPL dialect version") if err := fs.Parse(flagArgs); err != nil { fmt.Fprintf(os.Stderr, "openspl: %v\n", err) return 2 } + if !supportedSPLVersion(splVersion) { + fmt.Fprintf(os.Stderr, "openspl: unsupported SPL version %d; supported versions: 1, 2\n", splVersion) + return 2 + } + src, err := readQuery(file, positional) if err != nil { fmt.Fprintf(os.Stderr, "openspl: %v\n", err) return 2 } - p, err := spl1.Parse(src) + p, err := compiler.ParseVersion(src, splVersion) if err != nil { ds, ok := diag.FromError(err) if !ok { @@ -277,6 +295,13 @@ func readStdin() (string, error) { return src, nil } +// supportedSPLVersion lists the dialects the CLI accepts. Zero is the +// compiler's "default" spelling for classic SPL, but the flag is explicit about +// its value, so only 1 and 2 are accepted here. +func supportedSPLVersion(v int) bool { + return v == compiler.SPLVersion1 || v == compiler.SPLVersion2 +} + func hasWarnings(ds []diag.Diagnostic) bool { for _, d := range ds { if d.Severity == diag.SeverityWarning { @@ -292,11 +317,12 @@ func hasWarnings(ds []diag.Diagnostic) bool { func splitFlags(args []string) (flagArgs, positional []string) { takesValue := map[string]bool{ "target": true, "t": true, - "mapping": true, - "index": true, - "metric": true, - "span": true, - "file": true, "f": true, + "mapping": true, + "index": true, + "metric": true, + "span": true, + "spl-version": true, + "file": true, "f": true, } for i := 0; i < len(args); i++ { a := args[i] diff --git a/cmd/openspl/main_test.go b/cmd/openspl/main_test.go index 784c171..f4787de 100644 --- a/cmd/openspl/main_test.go +++ b/cmd/openspl/main_test.go @@ -139,6 +139,36 @@ func TestCLITranspile(t *testing.T) { t.Fatalf("exit = %d, stdout = %q, stderr = %q", code, stdout, stderr) } }) + + t.Run("spl-version 2 selects SPL2", func(t *testing.T) { + code, stdout, stderr := runCaptured(t, "transpile", "--spl-version", "2", + "from main | where status=500") + if code != 0 || stderr != "" { + t.Fatalf("exit = %d, stderr = %q", code, stderr) + } + if stdout != "FROM main\n| WHERE status == 500\n" { + t.Fatalf("stdout = %q", stdout) + } + }) + + t.Run("spl-version defaults to classic SPL", func(t *testing.T) { + // `from` is a recognized classic SPL command, so without the flag this + // is an unsupported-command refusal rather than an SPL2 parse. + code, _, stderr := runCaptured(t, "transpile", "from main") + if code != 1 || !strings.Contains(stderr, "unsupported-command") { + t.Fatalf("exit = %d, stderr = %q", code, stderr) + } + }) + + t.Run("unsupported spl-version is a usage error before reading input", func(t *testing.T) { + for _, version := range []string{"0", "3", "two"} { + code, stdout, stderr := runCaptured(t, "transpile", "--spl-version", version) + if code != 2 || stdout != "" || !strings.Contains(stderr, "version") { + t.Fatalf("version %q: exit = %d, stdout = %q, stderr = %q", + version, code, stdout, stderr) + } + } + }) } func TestCLIAST(t *testing.T) { @@ -161,6 +191,18 @@ func TestCLIAST(t *testing.T) { } } +func TestCLIASTSPL2(t *testing.T) { + code, stdout, stderr := runCaptured(t, "ast", "--spl-version", "2", "from main") + if code != 0 || stderr != "" { + t.Fatalf("exit = %d, stderr = %q", code, stderr) + } + for _, want := range []string{`"op": "="`, `"value": "main"`} { + if !strings.Contains(stdout, want) { + t.Fatalf("stdout = %q, want %s", stdout, want) + } + } +} + func TestCLIUsage(t *testing.T) { if code, _, stderr := runCaptured(t); code != 2 || !strings.Contains(stderr, "Usage:") { t.Fatalf("no args: exit = %d, stderr = %q", code, stderr) diff --git a/conformance/cases/search/wildcard-term-before-stage.esql b/conformance/cases/search/wildcard-term-before-stage.esql new file mode 100644 index 0000000..798e083 --- /dev/null +++ b/conformance/cases/search/wildcard-term-before-stage.esql @@ -0,0 +1,3 @@ +FROM web +| WHERE MATCH(message, "error") +| STATS count = COUNT(*) BY `host.name` diff --git a/conformance/cases/search/wildcard-term-before-stage.json b/conformance/cases/search/wildcard-term-before-stage.json new file mode 100644 index 0000000..ce440ef --- /dev/null +++ b/conformance/cases/search/wildcard-term-before-stage.json @@ -0,0 +1,15 @@ +{ + "description": "a wildcard that ends a search term before a pipe stays part of the term", + "targets": { + "esql": { + "diagnostics": [ + { + "code": "fulltext-approximation", + "severity": "warning", + "line": 1, + "col": 11 + } + ] + } + } +} diff --git a/conformance/cases/search/wildcard-term-before-stage.spl b/conformance/cases/search/wildcard-term-before-stage.spl new file mode 100644 index 0000000..d52d619 --- /dev/null +++ b/conformance/cases/search/wildcard-term-before-stage.spl @@ -0,0 +1 @@ +index=web error* | stats count by host diff --git a/conformance/cases/spl2/classic-syntax.json b/conformance/cases/spl2/classic-syntax.json new file mode 100644 index 0000000..84f9c6f --- /dev/null +++ b/conformance/cases/spl2/classic-syntax.json @@ -0,0 +1,22 @@ +{ + "description": "classic SPL is not accepted as SPL2: the pipeline must start with from", + "options": { + "spl_version": 2 + }, + "targets": { + "esql": { + "error": { + "code": "syntax", + "line": 1, + "col": 1 + } + }, + "promql": { + "error": { + "code": "syntax", + "line": 1, + "col": 1 + } + } + } +} diff --git a/conformance/cases/spl2/classic-syntax.spl b/conformance/cases/spl2/classic-syntax.spl new file mode 100644 index 0000000..629e512 --- /dev/null +++ b/conformance/cases/spl2/classic-syntax.spl @@ -0,0 +1 @@ +index=web | stats count diff --git a/conformance/cases/spl2/from-hyphenated.esql b/conformance/cases/spl2/from-hyphenated.esql new file mode 100644 index 0000000..99266ba --- /dev/null +++ b/conformance/cases/spl2/from-hyphenated.esql @@ -0,0 +1 @@ +FROM logs-2024-01 diff --git a/conformance/cases/spl2/from-hyphenated.json b/conformance/cases/spl2/from-hyphenated.json new file mode 100644 index 0000000..09f715b --- /dev/null +++ b/conformance/cases/spl2/from-hyphenated.json @@ -0,0 +1,6 @@ +{ + "description": "hyphens inside a dataset name stay part of one name", + "options": { + "spl_version": 2 + } +} diff --git a/conformance/cases/spl2/from-hyphenated.spl b/conformance/cases/spl2/from-hyphenated.spl new file mode 100644 index 0000000..9295429 --- /dev/null +++ b/conformance/cases/spl2/from-hyphenated.spl @@ -0,0 +1 @@ +from logs-2024-01 diff --git a/conformance/cases/spl2/from-index.esql b/conformance/cases/spl2/from-index.esql new file mode 100644 index 0000000..eb0c769 --- /dev/null +++ b/conformance/cases/spl2/from-index.esql @@ -0,0 +1 @@ +FROM main diff --git a/conformance/cases/spl2/from-index.json b/conformance/cases/spl2/from-index.json new file mode 100644 index 0000000..461a1e2 --- /dev/null +++ b/conformance/cases/spl2/from-index.json @@ -0,0 +1,6 @@ +{ + "description": "a bare from stage becomes the index filter both emitters already understand", + "options": { + "spl_version": 2 + } +} diff --git a/conformance/cases/spl2/from-index.spl b/conformance/cases/spl2/from-index.spl new file mode 100644 index 0000000..26f343c --- /dev/null +++ b/conformance/cases/spl2/from-index.spl @@ -0,0 +1 @@ +from main diff --git a/conformance/cases/spl2/from-wildcard.esql b/conformance/cases/spl2/from-wildcard.esql new file mode 100644 index 0000000..b3dd3b4 --- /dev/null +++ b/conformance/cases/spl2/from-wildcard.esql @@ -0,0 +1 @@ +FROM logs-* diff --git a/conformance/cases/spl2/from-wildcard.json b/conformance/cases/spl2/from-wildcard.json new file mode 100644 index 0000000..a3cf73f --- /dev/null +++ b/conformance/cases/spl2/from-wildcard.json @@ -0,0 +1,6 @@ +{ + "description": "a trailing wildcard in a dataset name is preserved", + "options": { + "spl_version": 2 + } +} diff --git a/conformance/cases/spl2/from-wildcard.spl b/conformance/cases/spl2/from-wildcard.spl new file mode 100644 index 0000000..408afc5 --- /dev/null +++ b/conformance/cases/spl2/from-wildcard.spl @@ -0,0 +1 @@ +from logs-* diff --git a/conformance/cases/spl2/namespaced-dataset.json b/conformance/cases/spl2/namespaced-dataset.json new file mode 100644 index 0000000..6d10e02 --- /dev/null +++ b/conformance/cases/spl2/namespaced-dataset.json @@ -0,0 +1,22 @@ +{ + "description": "a namespaced dataset cannot become an Elasticsearch index", + "options": { + "spl_version": 2 + }, + "targets": { + "esql": { + "error": { + "code": "unsupported-dataset", + "line": 1, + "col": 6 + } + }, + "promql": { + "error": { + "code": "unsupported-dataset", + "line": 1, + "col": 6 + } + } + } +} diff --git a/conformance/cases/spl2/namespaced-dataset.spl b/conformance/cases/spl2/namespaced-dataset.spl new file mode 100644 index 0000000..39db692 --- /dev/null +++ b/conformance/cases/spl2/namespaced-dataset.spl @@ -0,0 +1 @@ +from datamodel:events diff --git a/conformance/cases/spl2/promql-count.esql b/conformance/cases/spl2/promql-count.esql new file mode 100644 index 0000000..364b8f9 --- /dev/null +++ b/conformance/cases/spl2/promql-count.esql @@ -0,0 +1,2 @@ +FROM metrics +| STATS count = COUNT(*) BY `host.name` diff --git a/conformance/cases/spl2/promql-count.json b/conformance/cases/spl2/promql-count.json new file mode 100644 index 0000000..73dd376 --- /dev/null +++ b/conformance/cases/spl2/promql-count.json @@ -0,0 +1,24 @@ +{ + "description": "SPL2 stats produces the same PromQL rate as classic SPL, with its warnings", + "options": { + "spl_version": 2 + }, + "targets": { + "promql": { + "diagnostics": [ + { + "code": "default-span", + "severity": "warning", + "line": 1, + "col": 16 + }, + { + "code": "promql-window", + "severity": "warning", + "line": 1, + "col": 16 + } + ] + } + } +} diff --git a/conformance/cases/spl2/promql-count.promql b/conformance/cases/spl2/promql-count.promql new file mode 100644 index 0000000..d099fe0 --- /dev/null +++ b/conformance/cases/spl2/promql-count.promql @@ -0,0 +1 @@ +sum by (host) (increase(splunk_events_total{job="metrics"}[5m])) diff --git a/conformance/cases/spl2/promql-count.spl b/conformance/cases/spl2/promql-count.spl new file mode 100644 index 0000000..ff99d1f --- /dev/null +++ b/conformance/cases/spl2/promql-count.spl @@ -0,0 +1 @@ +from metrics | stats count() BY host diff --git a/conformance/cases/spl2/second-from.json b/conformance/cases/spl2/second-from.json new file mode 100644 index 0000000..07473b6 --- /dev/null +++ b/conformance/cases/spl2/second-from.json @@ -0,0 +1,22 @@ +{ + "description": "from is only valid as the first stage", + "options": { + "spl_version": 2 + }, + "targets": { + "esql": { + "error": { + "code": "syntax", + "line": 1, + "col": 10 + } + }, + "promql": { + "error": { + "code": "syntax", + "line": 1, + "col": 10 + } + } + } +} diff --git a/conformance/cases/spl2/second-from.spl b/conformance/cases/spl2/second-from.spl new file mode 100644 index 0000000..58da183 --- /dev/null +++ b/conformance/cases/spl2/second-from.spl @@ -0,0 +1 @@ +from a | from b diff --git a/conformance/cases/spl2/star-in-expression.json b/conformance/cases/spl2/star-in-expression.json new file mode 100644 index 0000000..8326c7c --- /dev/null +++ b/conformance/cases/spl2/star-in-expression.json @@ -0,0 +1,22 @@ +{ + "description": "the SPL2 subset has no meaning for a wildcard inside an expression", + "options": { + "spl_version": 2 + }, + "targets": { + "esql": { + "error": { + "code": "syntax", + "line": 1, + "col": 26 + } + }, + "promql": { + "error": { + "code": "syntax", + "line": 1, + "col": 26 + } + } + } +} diff --git a/conformance/cases/spl2/star-in-expression.spl b/conformance/cases/spl2/star-in-expression.spl new file mode 100644 index 0000000..ce04c79 --- /dev/null +++ b/conformance/cases/spl2/star-in-expression.spl @@ -0,0 +1 @@ +from main | where status=* diff --git a/conformance/cases/spl2/stats-distinct.esql b/conformance/cases/spl2/stats-distinct.esql new file mode 100644 index 0000000..48c17f7 --- /dev/null +++ b/conformance/cases/spl2/stats-distinct.esql @@ -0,0 +1,2 @@ +FROM main +| STATS users = COUNT_DISTINCT(user) BY `host.name` diff --git a/conformance/cases/spl2/stats-distinct.json b/conformance/cases/spl2/stats-distinct.json new file mode 100644 index 0000000..16a2f18 --- /dev/null +++ b/conformance/cases/spl2/stats-distinct.json @@ -0,0 +1,6 @@ +{ + "description": "distinct_count normalizes to the dc aggregate name", + "options": { + "spl_version": 2 + } +} diff --git a/conformance/cases/spl2/stats-distinct.spl b/conformance/cases/spl2/stats-distinct.spl new file mode 100644 index 0000000..1c74c3d --- /dev/null +++ b/conformance/cases/spl2/stats-distinct.spl @@ -0,0 +1 @@ +from main | stats distinct_count(user) AS users BY host diff --git a/conformance/cases/spl2/unsupported-command.json b/conformance/cases/spl2/unsupported-command.json new file mode 100644 index 0000000..cf7077a --- /dev/null +++ b/conformance/cases/spl2/unsupported-command.json @@ -0,0 +1,22 @@ +{ + "description": "a recognized SPL2 command outside the subset is refused with a position", + "options": { + "spl_version": 2 + }, + "targets": { + "esql": { + "error": { + "code": "unsupported-command", + "line": 1, + "col": 13 + } + }, + "promql": { + "error": { + "code": "unsupported-command", + "line": 1, + "col": 13 + } + } + } +} diff --git a/conformance/cases/spl2/unsupported-command.spl b/conformance/cases/spl2/unsupported-command.spl new file mode 100644 index 0000000..1d426a3 --- /dev/null +++ b/conformance/cases/spl2/unsupported-command.spl @@ -0,0 +1 @@ +from main | eval x=1 diff --git a/conformance/cases/spl2/where-stats.esql b/conformance/cases/spl2/where-stats.esql new file mode 100644 index 0000000..b3712ef --- /dev/null +++ b/conformance/cases/spl2/where-stats.esql @@ -0,0 +1,3 @@ +FROM main +| WHERE status == 500 +| STATS count = COUNT(*) BY `host.name` diff --git a/conformance/cases/spl2/where-stats.json b/conformance/cases/spl2/where-stats.json new file mode 100644 index 0000000..673a02b --- /dev/null +++ b/conformance/cases/spl2/where-stats.json @@ -0,0 +1,6 @@ +{ + "description": "the SPL2 subset lowers where and stats to the same IR as classic SPL", + "options": { + "spl_version": 2 + } +} diff --git a/conformance/cases/spl2/where-stats.spl b/conformance/cases/spl2/where-stats.spl new file mode 100644 index 0000000..49f4815 --- /dev/null +++ b/conformance/cases/spl2/where-stats.spl @@ -0,0 +1 @@ +from main | where status=500 | stats count() AS count BY host diff --git a/conformance/conformance_test.go b/conformance/conformance_test.go index c3bdd70..29263ab 100644 --- a/conformance/conformance_test.go +++ b/conformance/conformance_test.go @@ -37,9 +37,10 @@ type expectation struct { } type options struct { - Metric string `json:"metric,omitempty"` - Span string `json:"span,omitempty"` - Index string `json:"index,omitempty"` + Metric string `json:"metric,omitempty"` + Span string `json:"span,omitempty"` + Index string `json:"index,omitempty"` + SPLVersion int `json:"spl_version,omitempty"` } type targetExpect struct { @@ -247,6 +248,7 @@ func caseOptions(base string, exp expectation) (compiler.Options, error) { opts.Metric = exp.Options.Metric opts.Span = exp.Options.Span opts.Index = exp.Options.Index + opts.SPLVersion = exp.Options.SPLVersion } if exp.Mapping != "" { cfg, err := mapping.Load(filepath.Join(filepath.Dir(base), exp.Mapping)) @@ -274,6 +276,14 @@ func loadExpectation(t *testing.T, path string) expectation { if err := dec.Decode(&exp); err != nil { t.Fatalf("%s: %v", path, err) } + if exp.Options != nil { + switch exp.Options.SPLVersion { + case 0, compiler.SPLVersion1, compiler.SPLVersion2: + default: + t.Fatalf("%s: unsupported spl_version %d; supported versions: 1, 2", + path, exp.Options.SPLVersion) + } + } return exp } diff --git a/conformance/engines/README.md b/conformance/engines/README.md index e47168c..7807b4b 100644 --- a/conformance/engines/README.md +++ b/conformance/engines/README.md @@ -29,7 +29,9 @@ Engines already running are reused. START_ENGINES=0 ./conformance/engines/run.sh # also parse the SPL against a Splunk container (slow: several minutes) -SPLUNK_PASSWORD=changeme123 docker compose -f conformance/engines/docker-compose.yml --profile splunk up -d +SPLUNK_PASSWORD=changeme123 docker compose \ + -f conformance/engines/docker-compose.yml \ + -f conformance/engines/docker-compose.splunk.yml up -d SPLUNK=1 SPLUNK_PASSWORD=changeme123 ./conformance/engines/run.sh # alternate endpoints diff --git a/conformance/engines/docker-compose.splunk.yml b/conformance/engines/docker-compose.splunk.yml new file mode 100644 index 0000000..5eb6357 --- /dev/null +++ b/conformance/engines/docker-compose.splunk.yml @@ -0,0 +1,24 @@ +name: openspl-e2e + +# Optional reference oracle for SPL parsing. Start it alongside the engines: +# SPLUNK_PASSWORD= docker compose \ +# -f conformance/engines/docker-compose.yml \ +# -f conformance/engines/docker-compose.splunk.yml up -d +# +# SPLUNK_PASSWORD is required here: the Splunk image refuses to start without +# it, and keeping the file opt-in keeps the default engine start independent of +# it. +services: + splunk: + image: splunk/splunk:9.3 + environment: + SPLUNK_START_ARGS: --accept-license + SPLUNK_PASSWORD: ${SPLUNK_PASSWORD:?set SPLUNK_PASSWORD to start the Splunk oracle} + ports: + - "8000:8000" + - "8089:8089" + healthcheck: + test: ["CMD-SHELL", "curl -fsSk https://localhost:8089/services/server/health || exit 1"] + interval: 15s + timeout: 10s + retries: 60 diff --git a/conformance/engines/docker-compose.yml b/conformance/engines/docker-compose.yml index 67defde..1a6c27a 100644 --- a/conformance/engines/docker-compose.yml +++ b/conformance/engines/docker-compose.yml @@ -26,19 +26,7 @@ services: ports: - "9090:9090" - # Optional reference oracle for SPL parsing. Opt in with: - # SPLUNK_PASSWORD= docker compose --profile splunk up -d - splunk: - image: splunk/splunk:9.3 - profiles: ["splunk"] - environment: - SPLUNK_START_ARGS: --accept-license - SPLUNK_PASSWORD: ${SPLUNK_PASSWORD:?set SPLUNK_PASSWORD to use the splunk profile} - ports: - - "8000:8000" - - "8089:8089" - healthcheck: - test: ["CMD-SHELL", "curl -fsSk https://localhost:8089/services/server/health || exit 1"] - interval: 15s - timeout: 10s - retries: 60 +# The optional Splunk reference oracle lives in docker-compose.splunk.yml. It is +# a separate file because Compose interpolates every service it reads, even one +# behind a profile, so a required SPLUNK_PASSWORD there would break the default +# engine start. diff --git a/conformance/engines/run.sh b/conformance/engines/run.sh index c74951d..7666186 100755 --- a/conformance/engines/run.sh +++ b/conformance/engines/run.sh @@ -100,7 +100,9 @@ run_case() { bad "$name: engine rejected the query" return fi - if grep -q '"error"' "$outfile"; then + # Check the top-level field, not the raw text: a row value can be the + # word "error" (for example an eval result) without the engine failing. + if ! python3 -c 'import json,sys; sys.exit("error" in json.load(open(sys.argv[1])))' "$outfile"; then bad "$name: engine returned an error" cat "$outfile" return @@ -112,7 +114,7 @@ run_case() { bad "$name: engine rejected the query" return fi - if ! grep -q '"status":"success"' "$outfile"; then + if ! python3 -c 'import json,sys; sys.exit(json.load(open(sys.argv[1])).get("status") != "success")' "$outfile"; then bad "$name: engine returned an error" cat "$outfile" return diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 0af1f3f..35061ae 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -17,7 +17,7 @@ engines. Front-ends lower syntax into one IR; back-ends read only that IR. | Explainable failure | Every error and warning carries `line`, `column`, `offset`, a stable code, and a message. | | Target independence | Parsers never import emitters. Emitters never parse source syntax. | | Additive growth | A new language is a front-end; a new engine is a back-end; neither rewrites the other. | -| Zero supply chain | The CLI has no third-party Go modules. | +| Small supply chain | The binary links two third-party modules: the ANTLR Go parser runtime and the `golang.org/x/exp` package it uses; see [ADR 0004](adr/0004-antlr-parsers.md). | | Offline by default | Queries can contain sensitive identifiers; the process never sends them anywhere. | ## Package map @@ -26,8 +26,10 @@ engines. Front-ends lower syntax into one IR; back-ends read only that IR. |---|---|---| | `pkg/ast` | stdlib only | Parsers, emitters, mapping | | `pkg/diag` | `pkg/ast` | Targets | -| `pkg/parser/spl1` | `pkg/ast`, `pkg/diag` | ES\|QL, PromQL, mapping | -| `pkg/parser/spl2` | `pkg/ast`, `pkg/diag` | ES\|QL, PromQL, mapping | +| `pkg/parser/spl1` | `pkg/ast`, `pkg/diag`, `pkg/parser/commands`, `pkg/parser/internal/*`, generated `spl1/gen` | ES\|QL, PromQL, mapping | +| `pkg/parser/spl2` | `pkg/ast`, `pkg/diag`, `pkg/parser/commands`, `pkg/parser/internal/*`, generated `spl2/gen` | ES\|QL, PromQL, mapping, the SPL1 front-end | +| `pkg/parser/internal/antlrpos` | stdlib, ANTLR runtime, `pkg/ast` | Parsers, targets | +| `pkg/parser/internal/antlrsupport` | `pkg/ast`, `pkg/diag`, `pkg/parser/internal/antlrpos`, ANTLR runtime | Targets | | `pkg/mapping` | stdlib only | Queries | | `pkg/emitter/esql` | `pkg/ast`, `pkg/diag`, `pkg/mapping` | SPL syntax | | `pkg/emitter/promql` | `pkg/ast`, `pkg/diag`, `pkg/mapping` | SPL syntax | @@ -67,6 +69,38 @@ Expressions are deliberately small. A construct that cannot be represented faithfully becomes a positioned `unsupported-*` diagnostic rather than an untyped escape hatch. +## Generated parsers + +Both dialects are described by ANTLR 4 grammars and generated into Go at build +time by a maintainer, then committed: + +| Piece | Where | +|---|---| +| Classic SPL grammar | `pkg/parser/spl1/grammar/SPL1.g4` | +| SPL2 subset grammar | `pkg/parser/spl2/grammar/SPL2.g4` | +| Generated lexer, parser, visitor | `pkg/parser/spl1/gen`, `pkg/parser/spl2/gen` (never hand-edited) | +| Regeneration | `make generate` (Java 17); `make generate-check` in CI | + +The generated code is committed so `go build`, `go install`, Docker, and +release builds need neither Java nor the ANTLR jar. `.gitattributes` marks the +`gen/` trees as generated, so review focuses on the `.g4` files. + +Three small Go layers surround the generated parsers: + +| Layer | Responsibility | +|---|---| +| `antlrpos.SourceMap` | Converts ANTLR rune indexes to byte-based `ast.Pos`, slices source text for exact spellings, and exposes byte adjacency for wildcard and hyphen runs. | +| `antlrsupport` | Installs an error listener that records the first syntax error as a positioned `diag.Error`, aborts the parse, and maps grammar actions' aborts back to positions. | +| Stage driver (`parse.go`, `spl2.go`) | Lexes the whole input first, sequences stages, classifies command names, and lowers each stage immediately, so a semantic error in an earlier stage still beats a grammar error in a later one. | + +The visitor lowering lives in `build.go` in each front-end. It converts rule +contexts to IR nodes and owns the defaults and refusals the grammar leaves out +(for example aggregate-name normalization). + +`pkg/parser/internal/lexerparity` holds a test-only gate: it tokenizes one +corpus with both generated lexers and fails if the duplicated lexical rules +drift. + ## Semantic boundary: `search` vs `where` Classic SPL changes the meaning of the right-hand side depending on context: @@ -76,9 +110,13 @@ Classic SPL changes the meaning of the right-hand side depending on context: | `search host=web` | string literal `"web"` | | `where host=web` | field reference `web` | -The parser tracks this with a context flag (`searchLiterals`) and emits -`StringLit` or `FieldRef` accordingly. Getting this wrong would silently turn a -literal into a column reference, so it is covered by table-driven tests. +The grammar encodes this with two parallel rule sets: `search*` rules (literal +semantics) and `value*` rules (field semantics). The generator's ALL(*) +prediction cannot prune alternatives on semantic predicates, so tight-token +adjacency is first applied to the token stream in Go (`tight.go`), and the +rule position alone decides which side a word lands on. Getting this wrong +would silently turn a literal into a column reference, so it is covered by +table-driven stage and position tests and by the lexer-parity gate. Other classic-SPL behaviors encoded in the front-end: @@ -152,8 +190,11 @@ Exit codes are part of the contract: | Layer | Test type | |---|---| -| Lexer | Token and position tests | +| Lexer | Token and position tests; SPL1/SPL2 lexer-parity test | +| Generated code | `make generate-check` re-runs the generator and fails on any diff | | Parser | Stage shape, semantics, precedence, error codes | +| Fuzzing | `FuzzParseSPL1` and `FuzzParseSPL2`: arbitrary input is parsed or refused, never a panic | +| Performance | `BenchmarkParse` in each front-end | | Mapping | Defaults, strict JSON, label sanitization | | Emitters | Golden strings and diagnostic codes | | Conformance (offline) | `conformance/cases/**/*.spl` vs `.esql` / `.promql` goldens, plus diagnostics | @@ -161,12 +202,14 @@ Exit codes are part of the contract: ## Extending the compiler -1. **New SPL command:** add IR nodes if needed, lex/parse it, then update every - emitter or return an explicit unsupported diagnostic. +1. **New SPL command:** add IR nodes if needed, edit the `.g4`, run + `make generate`, implement the visitor method, then update every emitter or + return an explicit unsupported diagnostic. 2. **New target:** create `pkg/emitter/`, accept `*ast.Pipeline` and a mapping, return a query plus diagnostics. Register it in `pkg/compiler`. -3. **New source dialect:** create `pkg/parser/` and lower into the same - IR. Do not share parser internals unless the grammar is actually shared. +3. **New source dialect:** create `pkg/parser/` with its own grammar + and generated package, and lower into the same IR. Do not import another + front-end; share only `pkg/parser/internal` helpers. -See [ADRs](adr/) for the decisions behind Go, the unified IR, and the -"refuse rather than guess" policy. +See [ADRs](adr/) for the decisions behind Go, the unified IR, the ANTLR +parsers, and the "refuse rather than guess" policy. diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md index 049fc80..ed5b5aa 100644 --- a/docs/COMPATIBILITY.md +++ b/docs/COMPATIBILITY.md @@ -4,6 +4,35 @@ This page is the support contract for v0.1.x. A construct is either **exact**, **approximate** (emitted with a warning), or **refused** (positioned error). Nothing is silently rewritten. +## Input dialects + +Select the input dialect with `--spl-version 1|2` (default `1`) or +`compiler.Options.SPLVersion`. In the API, `0` and `1` both select classic SPL; +any other value is refused with `unsupported-spl-version` at 1:1. The CLI +accepts only `1` and `2` and exits with a usage error for anything else. The +compiler never falls back to classic SPL. + +| Version | Dialect | Status | +|---|---|---| +| `1` (and `0` in the API) | Classic Splunk SPL | ✅ Supported, see below | +| `2` | SPL2 subset | ✅ Supported: `from`, `where`, `stats` | + +The SPL2 subset differs from classic SPL in surface syntax and semantics: + +| Aspect | SPL2 subset | +|---|---| +| Pipeline start | Must be `from `; a leading pipe is not accepted | +| Dataset names | Plain index names, including `logs-*` and `logs-2024-01` | +| Namespaced datasets | ⛔ `unsupported-dataset` (`datamodel:…`, `lookup:…`) | +| Bare words | Field references on both sides of a comparison | +| Conditions | Explicit `AND` is required; there is no implicit AND | +| `stats` | Parenthesized aggregate calls; `distinct_count` normalizes to `dc` | +| Wildcards | Only in a dataset name; `where status=*` is `syntax` | +| Other commands | ⛔ `unsupported-command`, or `unknown-command` for a non-command word | + +`from main` lowers to the same IR as `index=main`, so index mapping, `FROM` +emission, and PromQL `job` matchers behave exactly as for classic SPL. + ## Commands | SPL command | Parser | ES\|QL | PromQL | @@ -97,7 +126,7 @@ over index filters is refused with `promql-unsupported-filter`. ## Refused SPL commands -Recognized but not implemented in v0.1: +Recognized but not implemented in v0.1 (classic SPL; in SPL2, `from` is the start of a pipeline): `append`, `appendcols`, `addtotals`, `analyzefields`, `anomalydetection`, `apply`, `associate`, `bucket`, `chart`, `cluster`, `collect`, `contingency`, @@ -129,7 +158,8 @@ They return `unsupported-command` with the command's source position. | `unknown-command` | Identifier that is not a known command | | `unsupported-subsearch` | `[ ... ]` subsearch | | `conflicting-time-bounds` | Same `earliest`/`latest` bound with different values | -| `spl2-not-implemented` | SPL2 front-end is a stub | +| `unsupported-dataset` | SPL2 dataset is namespaced and cannot become an index | +| `unsupported-spl-version` | Dialect version is not 1 or 2 | ### ES|QL emitter diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 03b3788..e6ef12d 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -11,7 +11,7 @@ languages — not a Splunk clone, not an Elasticsearch client, and not a model. | Refuse rather than guess | Missing semantics are errors with positions, not approximations. | | Evidence over claims | Every mapping gets a golden test and, where possible, an engine-level check. | | Offline | No telemetry, no accounts, no network in the translation path. | -| Boring dependencies | Go standard library only. | +| Boring dependencies | One parser runtime and its transitive helper, both pinned and recorded in [ADR 0004](adr/0004-antlr-parsers.md); nothing else third-party. | ## Status @@ -19,7 +19,7 @@ languages — not a Splunk clone, not an Elasticsearch client, and not a model. |---|---|---| | **0.1 — Foundation** | IR, SPL v1 parser, ES\|QL emitter, PromQL emitter, mapping, CLI, corpus, CI | ✅ Shipped | | **0.2 — Validation** | Docker harness for Splunk, Elasticsearch, Prometheus; parity fixtures | 🧪 In progress | -| **0.3 — SPL v2** | Separate grammar, typed expressions, `from` pipelines | 🗺️ Planned | +| **0.3 — SPL v2** | Separate grammar, `from` pipelines, `where`, `stats` | 🚧 Subset shipped | | **0.4 — Command coverage** | `dedup`, `top`, `rare`, `eventstats`, `streamstats`, `rename`, `fillnull` | 🗺️ Planned | | **0.5 — Migration tooling** | Batch mode, saved-search and dashboard extraction, diff reports | 💡 Proposed | | **1.0 — Stable contract** | Frozen diagnostic codes and flags, semantic versioning, signed releases | 🎯 Target | @@ -28,7 +28,7 @@ languages — not a Splunk clone, not an Elasticsearch client, and not a model. - [x] Unified IR (`pkg/ast`) - [x] Positioned diagnostics (`pkg/diag`) -- [x] Classic SPL lexer and parser +- [x] Classic SPL lexer and parser (ANTLR grammar, generated Go) - [x] `search`, `where`, `stats`, `timechart`, `eval`, `rex`, `table`, `fields`, `sort`, `head`, `bin` - [x] ES|QL emitter - [x] PromQL emitter with semantic refusal @@ -49,12 +49,17 @@ languages — not a Splunk clone, not an Elasticsearch client, and not a model. ## 0.3 — SPL v2 -- [ ] SPL2 lexer and grammar -- [ ] `from` sources, `where`, `select`, `eval`, `stats`, `timechart` +Shipped subset: `from`, `where`, `stats`, selected with `--spl-version 2`. + +- [x] SPL2 lexer and grammar (separate ANTLR grammar, generated Go) +- [x] `from` sources, `where`, `stats` +- [x] Shared IR nodes with classic SPL where semantics match +- [x] Distinct diagnostics for dialect differences (`unsupported-dataset`, + `unsupported-command`, `unknown-command`) +- [x] `--spl-version 1|2` (default: 1) +- [ ] `select`, `eval`, `sort`, `head`, `fields`, `table`, `timechart` - [ ] Typed expressions and function signatures -- [ ] Shared IR nodes with classic SPL where semantics match -- [ ] Distinct diagnostics for dialect differences -- [ ] `--spl-version 1|2` (default: auto-detect, then explicit) +- [ ] Namespaced datasets (data models, lookups) ## 0.4 — Broader command coverage diff --git a/docs/adr/0001-go-single-binary.md b/docs/adr/0001-go-single-binary.md index cbc76da..72b97b8 100644 --- a/docs/adr/0001-go-single-binary.md +++ b/docs/adr/0001-go-single-binary.md @@ -47,3 +47,7 @@ Negative: Keep the module graph empty. Any proposed dependency must justify why the standard library is insufficient. + +Amended by [ADR 0004](0004-antlr-parsers.md): the ANTLR Go runtime and its one +indirect module are allowed because parsing is expressed in ANTLR grammars. +Any dependency beyond those two still needs its own ADR. diff --git a/docs/adr/0004-antlr-parsers.md b/docs/adr/0004-antlr-parsers.md new file mode 100644 index 0000000..53ef81c --- /dev/null +++ b/docs/adr/0004-antlr-parsers.md @@ -0,0 +1,96 @@ +# ADR 0004 — Generate the SPL grammars with ANTLR + +| Field | Value | +|---|---| +| Status | Accepted | +| Date | 2026-10-26 | +| Deciders | OpenSPL maintainers | +| Amends | [ADR 0001](0001-go-single-binary.md) follow-up (empty module graph) | + +## Context + +OpenSPL began with a hand-written lexer and a hand-written recursive-descent +parser for classic SPL, about 1,370 lines together. The language is +context-sensitive in ways that are easy to get subtly wrong: implicit `AND` +between search terms, literal values on the right of a search comparison versus +field references in `where`, adjacency-sensitive wildcard and hyphen runs, and +case-insensitive keywords that remain usable as identifiers. Every new command +meant editing allocation-heavy parsing code by hand. + +SPL2 needs a second front-end. Duplicating the hand-written approach would +double the surface that can drift, and neither front-end would have a +declarative description a reviewer can check against the language rules. + +The maintainer requires all parsing to be expressed in ANTLR. + +## Decision + +Describe both dialects as ANTLR 4 grammars and generate Go parsers from them. + +| Item | Pinned value | +|---|---| +| Tool | ANTLR `4.13.2`, complete jar, SHA-256 `eae2dfa119a64327444672aff63e9ec35a20180dc5b8090b7a6ab85125df4d76` | +| Go runtime | `github.com/antlr4-go/antlr/v4 v4.13.1` | +| Indirect module | `golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842` (required by the runtime) | +| Grammars | `pkg/parser/spl1/grammar/SPL1.g4`, `pkg/parser/spl2/grammar/SPL2.g4` | +| Generated code | `pkg/parser/spl1/gen`, `pkg/parser/spl2/gen`, committed | +| Regeneration | `make generate` (`scripts/generate-parsers.sh`); CI runs `make generate-check` | + +The generated Go is committed. Building, installing, containerising, or +releasing OpenSPL needs neither Java nor the ANTLR jar; regeneration is a +maintainer task that requires Java 17 or newer. + +The grammars are the source of truth. Generated files carry a "DO NOT EDIT" +header and are never hand-edited; a change to parsing behaviour changes the +`.g4` file and regenerates. `.gitattributes` marks `pkg/parser/*/gen/**` as +generated so reviews focus on the grammar. + +## Consequences + +Positive: + +- Parsing rules are declared in one place per dialect, including the + context-sensitive boundaries, rather than spread across hand-written + recursive descent. +- Adding a command is a grammar rule plus a visitor method, not new + token-shuffling code. +- Stronger position guarantees: a source map converts ANTLR rune indexes to + OpenSPL's byte-based `ast.Pos`. +- ANTLR's error listener and bail strategy can preserve the existing + fail-fast contract without accepting ANTLR's own error text. + +Negative: + +- The module graph is no longer empty. ADR 0001's follow-up said to keep it + empty; this ADR supersedes that for exactly these two modules, and any + further dependency still needs its own ADR. +- A first build from source downloads the two modules into the Go module + cache. The shipped binary still makes no network calls, and generated code + is committed so ordinary builds never touch the network once the cache is + warm. +- Generated Go is large and repetitive. It is excluded from `go vet`'s + `unreachable` analyzer (upstream codegen emits a defensive `goto` after a + `return`); every other analyzer still runs on it. +- Regenerating requires Java 17, which contributors changing a grammar must + install. CI enforces that the committed output matches. + +## Alternatives considered + +| Option | Rejected because | +|---|---| +| Keep the hand-written parsers | The requirement is ANTLR, and a second dialect would double hand-written parsing code. | +| ANTLR with the grammar compiled at runtime | Would ship or require the jar and Java, contradicting the single-binary promise. | +| A parser generator with a pure-Go front-end (e.g. goyacc) | Does not meet the requirement, and lacks ANTLR's ALL(*) prediction for context-sensitive rules. | +| Vendoring the runtime | Adds a large tree to review; the module cache and `go.sum` give reproducible builds without it. | + +## Upgrade procedure + +1. Download the new complete jar from Maven Central and record its SHA-256 in + `scripts/antlr-.sha256`. +2. Bump the version in `scripts/generate-parsers.sh`. +3. Run `make generate`, then `make check`, `go test -race ./...`, and the + conformance suite. Goldens must not change. +4. Bump the runtime only to the matching v4 release; if the generated code + needs a symbol the pinned runtime lacks, pin both back together. +5. Commit the tool version, checksum, generated diff, and `go.mod`/`go.sum` in + one change. diff --git a/go.mod b/go.mod index 72fcfd2..df846a7 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,7 @@ module github.com/be-thomas/openspl go 1.24 + +require github.com/antlr4-go/antlr/v4 v4.13.1 + +require golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a4312cd --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= +github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index a11be0d..f20dcc1 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -11,6 +11,15 @@ import ( "github.com/be-thomas/openspl/pkg/emitter/promql" "github.com/be-thomas/openspl/pkg/mapping" "github.com/be-thomas/openspl/pkg/parser/spl1" + "github.com/be-thomas/openspl/pkg/parser/spl2" +) + +// SPL dialect versions accepted by ParseVersion and Options.SPLVersion. +const ( + // SPLVersion1 is classic Splunk SPL, the default. + SPLVersion1 = 1 + // SPLVersion2 is the supported SPL2 subset. + SPLVersion2 = 2 ) // Target names a supported back-end. @@ -46,6 +55,10 @@ type Options struct { Metric string Span string Mapping *mapping.Config + + // SPLVersion selects the input dialect: zero and 1 mean classic SPL, + // 2 means the SPL2 subset. ParseVersion refuses every other value. + SPLVersion int } // Result is a translation result. @@ -57,7 +70,7 @@ type Result struct { // Compile parses and translates a query in one call. func Compile(src string, target Target, opts Options) (*Result, *ast.Pipeline, error) { - p, err := spl1.Parse(src) + p, err := Parse(src, opts) if err != nil { return nil, nil, err } @@ -65,6 +78,26 @@ func Compile(src string, target Target, opts Options) (*Result, *ast.Pipeline, e return res, p, err } +// Parse parses src in the dialect selected by opts.SPLVersion. +func Parse(src string, opts Options) (*ast.Pipeline, error) { + return ParseVersion(src, opts.SPLVersion) +} + +// ParseVersion parses src with an explicit dialect version. Zero and 1 select +// classic SPL, 2 selects the SPL2 subset, and anything else is refused at 1:1 +// rather than silently treated as classic SPL. +func ParseVersion(src string, version int) (*ast.Pipeline, error) { + switch version { + case 0, SPLVersion1: + return spl1.Parse(src) + case SPLVersion2: + return spl2.Parse(src) + default: + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "unsupported-spl-version", + "unsupported SPL version %d; supported versions: 1, 2", version) + } +} + // Transpile translates an already-parsed pipeline. func Transpile(p *ast.Pipeline, target Target, opts Options) (*Result, error) { switch target { diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 8bed704..722356f 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -350,6 +350,59 @@ func TestPromQL(t *testing.T) { }) } +func TestParseVersion(t *testing.T) { + t.Run("zero and one are classic SPL", func(t *testing.T) { + for _, version := range []int{0, SPLVersion1} { + p, err := ParseVersion(`index=web status=500`, version) + if err != nil { + t.Fatalf("version %d: %v", version, err) + } + if len(p.Stages) != 1 { + t.Fatalf("version %d: got %d stages", version, len(p.Stages)) + } + } + }) + + t.Run("two is the SPL2 subset", func(t *testing.T) { + p, err := ParseVersion(`from main | where status=500 | stats count()`, SPLVersion2) + if err != nil { + t.Fatal(err) + } + if len(p.Stages) != 3 { + t.Fatalf("got %d stages, want 3", len(p.Stages)) + } + }) + + t.Run("classic SPL is not accepted as SPL2", func(t *testing.T) { + _, err := ParseVersion(`index=web | stats count`, SPLVersion2) + ds, ok := diag.FromError(err) + if !ok || len(ds) == 0 || ds[0].Code != "syntax" || + ds[0].Pos.Line != 1 || ds[0].Pos.Col != 1 { + t.Fatalf("error = %v, want syntax at 1:1", err) + } + }) + + t.Run("unsupported versions are refused at 1:1", func(t *testing.T) { + for _, version := range []int{-1, 3, 99} { + _, err := ParseVersion(`from main`, version) + ds, ok := diag.FromError(err) + if !ok || len(ds) == 0 || ds[0].Code != "unsupported-spl-version" || + ds[0].Pos.Line != 1 || ds[0].Pos.Col != 1 { + t.Fatalf("version %d: error = %v", version, err) + } + } + }) + + t.Run("compile selects the dialect from options", func(t *testing.T) { + res := mustCompile(t, `from main | stats count() AS n`, + ESQL, Options{SPLVersion: SPLVersion2}) + want := "FROM main\n| STATS n = COUNT(*)" + if res.Output != want { + t.Fatalf("output = %q, want %q", res.Output, want) + } + }) +} + func TestParseTarget(t *testing.T) { for _, name := range []string{"esql", "ESQL", "elastic", "elasticsearch"} { if got, err := ParseTarget(name); err != nil || got != ESQL { diff --git a/pkg/parser/commands/commands.go b/pkg/parser/commands/commands.go new file mode 100644 index 0000000..f9ec5cb --- /dev/null +++ b/pkg/parser/commands/commands.go @@ -0,0 +1,85 @@ +// Package commands holds the command-name tables each SPL front-end uses to +// classify a stage start. +// +// Classification happens before parsing so a recognized-but-unimplemented +// command produces a precise diagnostic instead of a confusing parse failure +// that treats the command as a search term. The tables are per dialect: SPL1 +// and the SPL2 subset know different command sets, and neither front-end +// imports the other. +package commands + +// spl1Implemented are the classic SPL commands the SPL1 front-end parses. +var spl1Implemented = map[string]bool{ + "search": true, + "where": true, + "stats": true, + "timechart": true, + "eval": true, + "rex": true, + "table": true, + "fields": true, + "sort": true, + "head": true, + "bin": true, +} + +// spl1Known are real classic SPL commands that SPL1 does not implement yet. +var spl1Known = map[string]bool{ + "append": true, "appendcols": true, "addtotals": true, "analyzefields": true, + "anomalydetection": true, "apply": true, "associate": true, "bucket": true, + "chart": true, "cluster": true, "collect": true, "contingency": true, + "correlate": true, "datamodel": true, "dbinspect": true, "dedup": true, + "delete": true, "diff": true, "entitlement": true, "eventcount": true, + "eventstats": true, "extract": true, "fieldformat": true, "fieldsummary": true, + "filldown": true, "fillnull": true, "findtypes": true, "fit": true, + "folderize": true, "foreach": true, "format": true, "from": true, + "geostats": true, "head": true, "highlight": true, "inputcsv": true, + "inputlookup": true, "iplocation": true, "join": true, "kmeans": true, + "kvform": true, "loadjob": true, "localize": true, "lookup": true, + "makecontinuous": true, "makeresults": true, "map": true, "mcollect": true, + "metadata": true, "metasearch": true, "ml": true, "mstats": true, + "multikmeans": true, "multisearch": true, "mvcombine": true, "mvexpand": true, + "nomv": true, "outlier": true, "outputcsv": true, "outputlookup": true, + "outputtext": true, "pivot": true, "predict": true, "rangemap": true, + "rare": true, "regex": true, "reltime": true, "rename": true, "replace": true, + "rest": true, "return": true, "reverse": true, "rex": true, "script": true, + "scrub": true, "search": true, "select": true, "selfjoin": true, + "sendemail": true, "set": true, "setfields": true, "spath": true, + "stats": true, "strcat": true, "streamstats": true, "table": true, + "tags": true, "tail": true, "timechart": true, "top": true, + "transaction": true, "transpose": true, "trendline": true, "tscollect": true, + "tstats": true, "typeahead": true, "typer": true, "union": true, + "uniq": true, "untable": true, "where": true, "x11": true, "xmlkv": true, + "xmlunescape": true, "xpath": true, +} + +// SPL1Implemented reports whether the SPL1 front-end implements a command. +func SPL1Implemented(name string) bool { return spl1Implemented[name] } + +// SPL1Known reports whether name is a real classic SPL command. +func SPL1Known(name string) bool { return spl1Known[name] } + +// spl2Implemented are the SPL2 commands in the supported subset. The pipeline +// itself always starts with `from`, which the front-end handles before it +// classifies a piped stage. +var spl2Implemented = map[string]bool{ + "from": true, + "where": true, + "stats": true, +} + +// spl2Known are SPL2 commands outside the supported subset. They are real +// commands, so they get `unsupported-command` instead of `unknown-command`. +var spl2Known = map[string]bool{ + "append": true, "dedup": true, "eval": true, "eventstats": true, + "expand": true, "fields": true, "head": true, "join": true, + "lookup": true, "multisearch": true, "rare": true, "rename": true, + "rex": true, "search": true, "sort": true, "streamstats": true, + "table": true, "timechart": true, "top": true, +} + +// SPL2Implemented reports whether the SPL2 front-end implements a command. +func SPL2Implemented(name string) bool { return spl2Implemented[name] } + +// SPL2Known reports whether name is a real SPL2 command. +func SPL2Known(name string) bool { return spl2Known[name] } diff --git a/pkg/parser/internal/antlrpos/sourcemap.go b/pkg/parser/internal/antlrpos/sourcemap.go new file mode 100644 index 0000000..ae4fe84 --- /dev/null +++ b/pkg/parser/internal/antlrpos/sourcemap.go @@ -0,0 +1,143 @@ +// Package antlrpos converts ANTLR token positions into the IR's byte-based +// positions. +// +// ANTLR's Go runtime indexes the input as a []rune, while pkg/ast reports +// 1-based lines, 1-based byte columns, and 0-based byte offsets. This package +// owns that conversion so the parser front-ends never do position arithmetic. +package antlrpos + +import ( + "unicode/utf8" + + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/ast" +) + +// SourceMap maps rune indexes in a source string to byte offsets and lines. +// +// It is built once per parse. Invalid UTF-8 bytes decode as one U+FFFD rune +// each, exactly as ANTLR's input stream does, so every token start and stop +// index has a byte offset. +type SourceMap struct { + src string + + // runeByte[r] is the byte offset of rune index r; it has one extra entry + // holding len(src). + runeByte []int + + // lineRune[i] is the rune index at which line i+1 starts, and lineByte + // the matching byte offset. Line 0 starts at 0. + lineRune []int + lineByte []int +} + +// New builds a source map for src. +func New(src string) *SourceMap { + m := &SourceMap{src: src} + m.runeByte = make([]int, 0, len(src)+1) + m.lineRune = []int{0} + m.lineByte = []int{0} + + for i := 0; i < len(src); { + m.runeByte = append(m.runeByte, i) + r, size := utf8.DecodeRuneInString(src[i:]) + if r == '\n' { + m.lineRune = append(m.lineRune, len(m.runeByte)) + m.lineByte = append(m.lineByte, i+size) + } + i += size + } + m.runeByte = append(m.runeByte, len(src)) + return m +} + +// RuneCount is the number of runes in the source. +func (m *SourceMap) RuneCount() int { return len(m.runeByte) - 1 } + +// ByteOffset converts a rune index to a byte offset, clamping to the source. +func (m *SourceMap) ByteOffset(runeIndex int) int { + if runeIndex <= 0 { + return 0 + } + if runeIndex >= len(m.runeByte) { + return len(m.src) + } + return m.runeByte[runeIndex] +} + +// Pos returns the IR position of a token's first character. The zero token and +// a nil token map to 1:1. +func (m *SourceMap) Pos(t antlr.Token) ast.Pos { + if t == nil { + return ast.Pos{Line: 1, Col: 1} + } + return m.PosAtOffset(m.ByteOffset(t.GetStart())) +} + +// PosAtOffset returns the position of a byte offset. +func (m *SourceMap) PosAtOffset(offset int) ast.Pos { + if offset < 0 { + offset = 0 + } + if offset > len(m.src) { + offset = len(m.src) + } + line := 1 + for i := 1; i < len(m.lineByte); i++ { + if m.lineByte[i] > offset { + break + } + line = i + 1 + } + col := offset - m.lineByte[line-1] + 1 + return ast.Pos{Line: line, Col: col, Offset: offset} +} + +// PosAt converts a 1-based line and 0-based rune column, the coordinate pair an +// ANTLR error listener receives, into an IR position. Out-of-range coordinates +// clamp to the nearest valid position so a diagnostic never reports 0:0. +func (m *SourceMap) PosAt(line, col int) ast.Pos { + if line < 1 { + line = 1 + } + if line > len(m.lineByte) { + line = len(m.lineByte) + } + runeIndex := m.lineRune[line-1] + col + if col < 0 { + runeIndex = m.lineRune[line-1] + } + if runeIndex > m.RuneCount() { + runeIndex = m.RuneCount() + } + return m.PosAtOffset(m.ByteOffset(runeIndex)) +} + +// Slice returns the source text covered by the run of tokens from first to +// last, inclusive. A nil or empty range yields "". +func (m *SourceMap) Slice(first, last antlr.Token) string { + if first == nil || last == nil { + return "" + } + start := m.ByteOffset(first.GetStart()) + stop := m.ByteOffset(last.GetStop() + 1) + if stop < start || stop > len(m.src) { + stop = len(m.src) + } + if start > stop { + return "" + } + return m.src[start:stop] +} + +// Adjacent reports whether b starts exactly where a ends. +func (m *SourceMap) Adjacent(a, b antlr.Token) bool { + if a == nil || b == nil { + return false + } + return a.GetStop()+1 == b.GetStart() +} + +// Source returns the mapped source text. +func (m *SourceMap) Source() string { return m.src } diff --git a/pkg/parser/internal/antlrsupport/listener.go b/pkg/parser/internal/antlrsupport/listener.go new file mode 100644 index 0000000..a948ee6 --- /dev/null +++ b/pkg/parser/internal/antlrsupport/listener.go @@ -0,0 +1,88 @@ +// Package antlrsupport turns ANTLR parse errors into positioned diagnostics. +// +// The SPL front-ends are fail-fast: the first syntax error ends the parse. +// ANTLR's stock error strategies recover and report several errors, and the +// ErrorStrategy interface carries an unexported method, so a strategy that +// bails cannot live outside the antlr package. Instead the listener records the +// first error as a diagnostic and panics with SyntaxAbort; the front-end +// recovers that panic in its entry point and returns the diagnostic. +package antlrsupport + +import ( + "fmt" + + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/ast" + "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" +) + +// SyntaxAbort is the panic value the listener raises for the first syntax +// error. Err is the diagnostic the front-end returns. +type SyntaxAbort struct { + Err *diag.Error +} + +// Listener is an antlr.ErrorListener that aborts on the first syntax error. +// +// Recognizer-level messages (ANTLR's own ambiguity and context-sensitivity +// reports) are ignored: they describe the grammar, not the query. +type Listener struct { + *antlr.DefaultErrorListener + + Map *antlrpos.SourceMap +} + +// New returns a listener that maps positions through m. +func New(m *antlrpos.SourceMap) *Listener { + return &Listener{DefaultErrorListener: antlr.NewDefaultErrorListener(), Map: m} +} + +// SyntaxError records the first syntax error and panics. Message wording is +// ours, not ANTLR's, so diagnostics stay readable and stable across grammar +// changes; the code and position are what callers depend on. +func (l *Listener) SyntaxError(_ antlr.Recognizer, offendingSymbol interface{}, line, column int, _ string, _ antlr.RecognitionException) { + pos := l.Map.PosAt(line, column) + message := "unexpected token" + if tok, ok := offendingSymbol.(antlr.Token); ok && tok != nil { + pos = l.Map.Pos(tok) + if tok.GetTokenType() == antlr.TokenEOF { + message = "unexpected end of query" + } else { + message = fmt.Sprintf("unexpected %q", tok.GetText()) + } + } + panic(SyntaxAbort{Err: diag.NewError(pos, "syntax", "%s", message)}) +} + +// TokenAbort is a panic value raised by generated parser code that must end +// the parse at a specific token. Generated grammar code cannot import this +// package, so it declares its own type with these methods; the interface +// assertion in Recover is structural. +// +// Actions are preferable to predicates for this: ANTLR copies an action into +// the generated code and runs it only when the alternative is actually parsed, +// while a predicate is evaluated speculatively during prediction. +type TokenAbort interface { + AbortToken() antlr.Token + AbortCode() string + AbortMessage() string +} + +// Recover returns the diagnostic carried by an abort panic, mapping a +// TokenAbort through m. Any other panic value is re-raised so real bugs stay +// visible. +func Recover(r interface{}, m *antlrpos.SourceMap) (*diag.Error, bool) { + switch abort := r.(type) { + case SyntaxAbort: + return abort.Err, true + case TokenAbort: + t := abort.AbortToken() + return diag.NewError(m.Pos(t), abort.AbortCode(), "%s", abort.AbortMessage()), true + } + panic(r) +} + +// Pos returns the position of a token, for front-end use. +func (l *Listener) Pos(t antlr.Token) ast.Pos { return l.Map.Pos(t) } diff --git a/pkg/parser/internal/lexerparity/doc.go b/pkg/parser/internal/lexerparity/doc.go new file mode 100644 index 0000000..924abe7 --- /dev/null +++ b/pkg/parser/internal/lexerparity/doc.go @@ -0,0 +1,12 @@ +// Package lexerparity holds the test that keeps the lexical rules duplicated in +// SPL1.g4 and SPL2.g4 from drifting apart. +// +// The Go target's grammar-import output crosses package boundaries awkwardly, +// so each combined grammar declares its own identifier, number, duration, +// string, operator, whitespace, and UNKNOWN rules. The two front-ends must +// tokenize a shared corpus identically, because a difference here would change +// expressions or dataset names between dialects for reasons that have nothing +// to do with either dialect's semantics. +// +// The package has no API and no non-test files beyond this one. +package lexerparity diff --git a/pkg/parser/internal/lexerparity/parity_test.go b/pkg/parser/internal/lexerparity/parity_test.go new file mode 100644 index 0000000..12ebbe5 --- /dev/null +++ b/pkg/parser/internal/lexerparity/parity_test.go @@ -0,0 +1,132 @@ +package lexerparity + +import ( + "fmt" + "testing" + + "github.com/antlr4-go/antlr/v4" + + spl1gen "github.com/be-thomas/openspl/pkg/parser/spl1/gen" + spl2gen "github.com/be-thomas/openspl/pkg/parser/spl2/gen" +) + +// tok is the parts of a token both lexers must agree on. The token type is +// compared through its symbolic name, because the two grammars declare +// different keyword sets and therefore number the shared rules differently. +type tok struct { + class string + text string + start int + stop int + line int + col int +} + +// corpus is lexical material only: identifiers, numbers, durations, strings, +// operators, whitespace, and characters no rule accepts. Words that are +// keywords in one dialect but not the other are excluded on purpose, because +// those differences are the dialects' business; the shared keyword spellings +// are included so their rules cannot drift. +var corpus = []struct { + name string + src string +}{ + {"identifiers", `_x @timestamp a.b a:b A1 x_y @@@ a.b:c`}, + {"numbers", `0 12 3.14 1e10 1E-3 1.5e+2 007 1.0`}, + {"durations", `1mon 2ms 3s 4m 5h 6d 7w 8y 1.5h 10mon`}, + {"number-letter adjacency", `1month 5monx 1e+foo 1.2.3 1. 1e 1e+ 1MON 1M`}, + {"strings", `"a b" 'a b' "a\"b" 'a\'b' "\\d+" "café" "東京" "" ''`}, + {"unterminated string", `"a\\"`}, + {"multiline string", "x=\"line\nbreak\" y"}, + {"operators", `== != <= >= = < > ! | , ( ) [ ] + - * / %`}, + {"unknown characters", `$ # ~ & ? ` + "`" + ` .`}, + {"adjacency", `logs-2024-01 web*prod *error* a** a-b a - b a- b a -b`}, + {"spaces and tabs", "a\tb c"}, + {"CRLF", "a\r\nb\r\nc"}, + {"multibyte around tokens", `a="café" b 東京 c`}, + {"shared keywords", `where stats by as and or not`}, +} + +func TestLexerParity(t *testing.T) { + for _, tc := range corpus { + t.Run(tc.name, func(t *testing.T) { + got1, got2 := lexSPL1(tc.src), lexSPL2(tc.src) + if len(got1) != len(got2) { + t.Fatalf("token count: SPL1 %d, SPL2 %d\nSPL1: %v\nSPL2: %v", + len(got1), len(got2), got1, got2) + } + for i := range got1 { + if got1[i] != got2[i] { + t.Errorf("token %d: SPL1 %+v, SPL2 %+v", i, got1[i], got2[i]) + } + } + }) + } +} + +// TestCorpusCoversEverySharedRule fails if a corpus entry is edited in a way +// that stops exercising a duplicated rule, which would let the parity test pass +// while a rule drifts untested. +func TestCorpusCoversEverySharedRule(t *testing.T) { + seen := make(map[string]bool) + for _, tc := range corpus { + for _, tk := range lexSPL1(tc.src) { + seen[tk.class] = true + } + } + + want := []string{ + "IDENT", "NUMBER", "DURATION", "STRING", + "EQ2", "NE", "LE", "GE", "EQ", "LT", "GT", "BANG", + "PIPE", "COMMA", "LPAREN", "RPAREN", "LBRACKET", "RBRACKET", + "PLUS", "MINUS", "STAR", "SLASH", "PERCENT", "UNKNOWN", + "WHERE", "STATS", "BY", "AS", "AND", "OR", "NOT", + } + for _, name := range want { + if !seen[name] { + t.Errorf("corpus does not produce a %s token", name) + } + } +} + +func lexSPL1(src string) []tok { + lx := spl1gen.NewSPL1Lexer(antlr.NewInputStream(src)) + lx.RemoveErrorListeners() + ts := antlr.NewCommonTokenStream(lx, antlr.TokenDefaultChannel) + ts.Fill() + return collect(ts.GetAllTokens(), lx.GetSymbolicNames()) +} + +func lexSPL2(src string) []tok { + lx := spl2gen.NewSPL2Lexer(antlr.NewInputStream(src)) + lx.RemoveErrorListeners() + ts := antlr.NewCommonTokenStream(lx, antlr.TokenDefaultChannel) + ts.Fill() + return collect(ts.GetAllTokens(), lx.GetSymbolicNames()) +} + +func collect(toks []antlr.Token, names []string) []tok { + out := make([]tok, 0, len(toks)) + for _, t := range toks { + out = append(out, tok{ + class: class(t, names), + text: t.GetText(), + start: t.GetStart(), + stop: t.GetStop(), + line: t.GetLine(), + col: t.GetColumn(), + }) + } + return out +} + +func class(t antlr.Token, names []string) string { + tt := t.GetTokenType() + if tt == antlr.TokenEOF { + return "EOF" + } + if tt > 0 && tt < len(names) { + return names[tt] + } + return fmt.Sprintf("token %d", tt) +} diff --git a/pkg/parser/spl1/bench_test.go b/pkg/parser/spl1/bench_test.go new file mode 100644 index 0000000..8acca7b --- /dev/null +++ b/pkg/parser/spl1/bench_test.go @@ -0,0 +1,19 @@ +package spl1 + +import "testing" + +// benchmarkQuery exercises a realistic pipeline: implicit search, a time +// bound, an aggregation, arithmetic, and row shaping. +const benchmarkQuery = `index=web earliest=-24h (status=500 OR status=503) host=api* ` + + `| stats count by host ` + + `| eval kb = bytes / 1024 ` + + `| sort limit=10 -kb | head 5` + +func BenchmarkParse(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := Parse(benchmarkQuery); err != nil { + b.Fatal(err) + } + } +} diff --git a/pkg/parser/spl1/build.go b/pkg/parser/spl1/build.go new file mode 100644 index 0000000..35a33ea --- /dev/null +++ b/pkg/parser/spl1/build.go @@ -0,0 +1,1103 @@ +package spl1 + +import ( + "fmt" + "strconv" + "strings" + + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/ast" + "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" + "github.com/be-thomas/openspl/pkg/parser/spl1/gen" +) + +// builder lowers parsed rule contexts into the IR. The grammar decides what +// the query means; the builder reproduces the hand parser's defaults, value +// shapes, positions, and deferred checks, and reports the operand errors the +// grammar deliberately leaves optional. +type builder struct { + m *antlrpos.SourceMap + toks []antlr.Token + parser *spl1gen.SPL1Parser +} + +func (b *builder) pos(t antlr.Token) ast.Pos { return b.m.Pos(t) } + +// text returns the source text of a rule context, sliced from the first to the +// last token so raw spellings, escapes, and wildcards survive untouched. +func (b *builder) text(ctx antlr.ParserRuleContext) string { + return b.m.Slice(ctx.GetStart(), ctx.GetStop()) +} + +// after returns the token that follows t in the stream. The parser has already +// fetched every token, so the index is stable even past the current position. +func (b *builder) after(t antlr.Token) antlr.Token { + if t == nil { + return nil + } + i := t.GetTokenIndex() + 1 + if i >= 0 && i < len(b.toks) { + return b.toks[i] + } + return t +} + +// missingOperand reports the first token after an operator whose operand is +// absent, which is where the hand parser fails. +func (b *builder) missingOperand(operator antlr.Token) *diag.Error { + t := b.after(operator) + return diag.NewError(b.pos(t), "syntax", + "expected an expression, found %s", b.describe(t)) +} + +func (b *builder) describe(t antlr.Token) string { + if t == nil || t.GetTokenType() == antlr.TokenEOF { + return "end of query" + } + if tok, err := convertToken(b.m, t); err == nil { + return tok.describe() + } + return fmt.Sprintf("%q", t.GetText()) +} + +// --- stages --------------------------------------------------------------- + +func (b *builder) searchStage(ctx spl1gen.IStageSearchContext) (ast.Stage, error) { + expr, err := b.searchExpr(ctx.SearchExpr()) + if err != nil { + return nil, err + } + st := &ast.SearchStage{Expr: expr, Pos: b.pos(ctx.GetStart())} + if err := extractTimeBounds(st); err != nil { + return nil, err + } + return st, nil +} + +func (b *builder) command(ctx spl1gen.IStageCommandContext) (ast.Stage, error) { + return b.commandBody(ctx.Command()) +} + +func (b *builder) commandBody(ctx spl1gen.ICommandContext) (ast.Stage, error) { + switch c := ctx.(type) { + case *spl1gen.CmdSearchContext: + var expr ast.Expr + if c.SearchExpr() != nil { + var err error + expr, err = b.searchExpr(c.SearchExpr()) + if err != nil { + return nil, err + } + } + st := &ast.SearchStage{Expr: expr, Pos: b.pos(c.GetStart())} + if err := extractTimeBounds(st); err != nil { + return nil, err + } + return st, nil + + case *spl1gen.CmdWhereContext: + var expr ast.Expr + if c.ValueExpr() != nil { + var err error + expr, err = b.valueExpr(c.ValueExpr()) + if err != nil { + return nil, err + } + } + st := &ast.SearchStage{Expr: expr, Pos: b.pos(c.GetStart())} + if err := extractTimeBounds(st); err != nil { + return nil, err + } + return st, nil + + case *spl1gen.CmdStatsContext: + aggs, err := b.aggList(c.AggList()) + if err != nil { + return nil, err + } + var by []ast.Expr + if c.ByClause() != nil { + by, err = b.byClause(c.ByClause()) + if err != nil { + return nil, err + } + } + return &ast.StatsStage{Aggs: aggs, By: by, Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.CmdTimechartContext: + return b.timechart(c.GetStart(), c.TimechartBody()) + + case *spl1gen.CmdEvalContext: + var assignments []ast.Assignment + for _, a := range c.AllAssignment() { + expr, err := b.valueExpr(a.ValueExpr()) + if err != nil { + return nil, err + } + assignments = append(assignments, ast.Assignment{ + Name: a.IdentLike().GetStart().GetText(), + Expr: expr, + Pos: b.pos(a.IdentLike().GetStart()), + }) + } + return &ast.EvalStage{Assignments: assignments, Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.CmdRexContext: + field := "_raw" + if c.RexField() != nil { + field = c.RexField().IdentLike().GetStart().GetText() + } + pattern := decodeString(c.STRING().GetSymbol().GetText()) + return &ast.RexStage{Field: field, Pattern: pattern, Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.CmdTableContext: + var fields []string + wildcard := false + for _, item := range c.AllTableItem() { + switch { + case item.COMMA() != nil: + case item.Star() != nil: + wildcard = true + case item.IdentLike() != nil: + fields = append(fields, item.IdentLike().GetStart().GetText()) + } + } + if len(fields) == 0 && !wildcard { + return nil, diag.NewError(b.pos(c.GetStart()), "syntax", + "table requires at least one field") + } + return &ast.TableStage{Fields: fields, Wildcard: wildcard, Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.CmdFieldsContext: + exclude := c.FieldsSign() != nil && c.FieldsSign().Minus() != nil + var include, excludeFields []string + for _, item := range c.AllFieldsItem() { + if item.IdentLike() == nil { + continue // a separating comma + } + name := item.IdentLike().GetStart().GetText() + if exclude { + excludeFields = append(excludeFields, name) + } else { + include = append(include, name) + } + } + if len(include) == 0 && len(excludeFields) == 0 { + return nil, diag.NewError(b.pos(c.GetStart()), "syntax", + "fields requires at least one field") + } + return &ast.FieldsStage{Include: include, Exclude: excludeFields, Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.CmdSortContext: + return b.sort(c.GetStart(), c.SortBody()) + + case *spl1gen.CmdHeadContext: + count, countSet := 10, false + if c.LimitArg() != nil { + n, err := b.limitArg(c.LimitArg(), "head limit", "head count") + if err != nil { + return nil, err + } + count, countSet = n, true + } + return &ast.HeadStage{Count: count, CountSet: countSet, Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.CmdBinContext: + return b.bin(c.GetStart(), c.AllBinItem()) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized command") +} + +func (b *builder) timechart(cmd antlr.Token, body spl1gen.ITimechartBodyContext) (ast.Stage, error) { + span := "" + var aggs []ast.Aggregate + var by []ast.Expr + var err error + + switch c := body.(type) { + case *spl1gen.TcSpanFirstContext: + span = b.spanValue(c.TimechartSpan().SpanAssign().SpanValue()) + aggs, err = b.aggList(c.AggList()) + if err != nil { + return nil, err + } + if c.ByClause() != nil { + by, err = b.byClause(c.ByClause()) + if err != nil { + return nil, err + } + } + case *spl1gen.TcAggFirstContext: + aggs, err = b.aggListNotSpan(c.AggListNotSpan()) + if err != nil { + return nil, err + } + if c.ByClause() != nil { + by, err = b.byClause(c.ByClause()) + if err != nil { + return nil, err + } + } + } + return &ast.TimechartStage{Aggs: aggs, By: by, Span: span, Pos: b.pos(cmd)}, nil +} + +func (b *builder) aggList(ctx spl1gen.IAggListContext) ([]ast.Aggregate, error) { + var out []ast.Aggregate + for _, a := range ctx.AllAgg() { + agg, err := b.aggregate(a) + if err != nil { + return nil, err + } + out = append(out, agg) + } + return out, nil +} + +func (b *builder) aggListNotSpan(ctx spl1gen.IAggListNotSpanContext) ([]ast.Aggregate, error) { + var out []ast.Aggregate + first := ctx.AggNotSpan() + head, err := b.aggregateNotSpan(first) + if err != nil { + return nil, err + } + out = append(out, head) + for _, a := range ctx.AllAgg() { + agg, err := b.aggregate(a) + if err != nil { + return nil, err + } + out = append(out, agg) + } + return out, nil +} + +func (b *builder) aggregate(ctx spl1gen.IAggContext) (ast.Aggregate, error) { + return b.aggregateParts(ctx.IdentLike().GetStart(), ctx.LPAREN() != nil, + ctx.ValueExpr(), ctx.AliasClause()) +} + +func (b *builder) aggregateNotSpan(ctx spl1gen.IAggNotSpanContext) (ast.Aggregate, error) { + return b.aggregateParts(ctx.IdentLikeNotSpan().GetStart(), ctx.LPAREN() != nil, + ctx.ValueExpr(), ctx.AliasClause()) +} + +func (b *builder) aggregateParts(fnTok antlr.Token, parenthesized bool, + arg spl1gen.IValueExprContext, alias spl1gen.IAliasClauseContext) (ast.Aggregate, error) { + + agg := ast.Aggregate{ + Func: strings.ToLower(fnTok.GetText()), + Pos: b.pos(fnTok), + } + if parenthesized && arg != nil { + expr, err := b.valueExpr(arg) + if err != nil { + return ast.Aggregate{}, err + } + agg.Arg = expr + } + if alias != nil { + agg.Alias = alias.IdentLike().GetStart().GetText() + } + return agg, nil +} + +func (b *builder) byClause(ctx spl1gen.IByClauseContext) ([]ast.Expr, error) { + var out []ast.Expr + for _, fe := range ctx.FieldExprList().AllFieldExpr() { + if star := fe.Star(); star != nil { + out = append(out, &ast.WildcardLit{Pos: b.pos(star.GetStart())}) + continue + } + tok := fe.IdentLike().GetStart() + out = append(out, &ast.FieldRef{Name: tok.GetText(), Pos: b.pos(tok)}) + } + return out, nil +} + +func (b *builder) spanValue(ctx spl1gen.ISpanValueContext) string { + if d := ctx.DURATION(); d != nil { + return d.GetSymbol().GetText() + } + return ctx.IdentLike().GetStart().GetText() +} + +func (b *builder) sort(cmd antlr.Token, body spl1gen.ISortBodyContext) (ast.Stage, error) { + limit := 0 + var fields []ast.SortField + + switch c := body.(type) { + case *spl1gen.SortLimitContext: + n, err := b.limitArg(c.LimitArg(), "sort limit", "sort limit") + if err != nil { + return nil, err + } + limit = n + items, err := b.sortItems(c.AllSortItem()) + if err != nil { + return nil, err + } + fields = items + case *spl1gen.SortFirstFieldContext: + first, err := b.sortFirstItem(c.SortFirstItem()) + if err != nil { + return nil, err + } + if first != nil { + fields = append(fields, *first) + } + items, err := b.sortItems(c.AllSortItem()) + if err != nil { + return nil, err + } + fields = append(fields, items...) + } + + if len(fields) == 0 && limit == 0 { + return nil, diag.NewError(b.pos(cmd), "syntax", "sort requires at least one field") + } + return &ast.SortStage{Fields: fields, Limit: limit, Pos: b.pos(cmd)}, nil +} + +func (b *builder) sortFirstItem(ctx spl1gen.ISortFirstItemContext) (*ast.SortField, error) { + if ctx.COMMA() != nil { + return nil, nil + } + // A sign rules out the `limit` keyword reading, so `sort -limit` is a + // descending sort on a field named `limit` and lands in the sign + // alternative rather than in sortField. + if word := ctx.IdentLike(); word != nil { + tok := word.GetStart() + return &ast.SortField{ + Name: tok.GetText(), + Desc: ctx.Sign() != nil && ctx.Sign().Minus() != nil, + }, nil + } + return b.sortField(ctx.SortField(), ctx.Sign()), nil +} + +func (b *builder) sortField(ctx spl1gen.ISortFieldContext, sign spl1gen.ISignContext) *ast.SortField { + tok := ctx.IdentLikeNotLimit().GetStart() + return &ast.SortField{Name: tok.GetText(), Desc: sign != nil && sign.Minus() != nil} +} + +func (b *builder) sortItems(items []spl1gen.ISortItemContext) ([]ast.SortField, error) { + var out []ast.SortField + for _, item := range items { + if item.IdentLike() == nil { + continue // a separating comma + } + tok := item.IdentLike().GetStart() + out = append(out, ast.SortField{ + Name: tok.GetText(), + Desc: item.Sign() != nil && item.Sign().Minus() != nil, + }) + } + return out, nil +} + +func (b *builder) limitArg(ctx spl1gen.ILimitArgContext, whatKeyword, whatNumber string) (int, error) { + switch c := ctx.(type) { + case *spl1gen.LimitKeywordContext: + return b.nonNegativeInt(c.LimitTail().Number().GetStart(), whatKeyword) + case *spl1gen.LimitNumberContext: + return b.nonNegativeInt(c.Number().GetStart(), whatNumber) + } + return 0, nil +} + +func (b *builder) nonNegativeInt(tok antlr.Token, what string) (int, error) { + n, err := strconv.Atoi(tok.GetText()) + if err != nil || n < 0 { + return 0, diag.NewError(b.pos(tok), "syntax", + "expected a non-negative integer for %s, found %q", what, tok.GetText()) + } + return n, nil +} + +// bin lowers the items the grammar accepted. The single-field rule is enforced +// by the grammar itself (binFieldSeen), so a second field has already been +// refused at its own token by the time this runs. +func (b *builder) bin(cmd antlr.Token, items []spl1gen.IBinItemContext) (ast.Stage, error) { + field, span := "", "" + for _, item := range items { + switch c := item.(type) { + case *spl1gen.BinSpanItemContext: + span = b.spanValue(c.SpanAssign().SpanValue()) + case *spl1gen.BinFieldItemContext: + field = c.BinField().IdentLikeNotSpan().GetStart().GetText() + } + } + if field == "" { + return nil, diag.NewError(b.pos(cmd), "syntax", "bin requires a field") + } + if span == "" { + return nil, diag.NewError(b.pos(cmd), "syntax", "bin requires span=") + } + return &ast.BinStage{Field: field, Span: span, Pos: b.pos(cmd)}, nil +} + +// --- search expressions: comparison RHS words are literal values ---------- + +func (b *builder) searchExpr(ctx spl1gen.ISearchExprContext) (ast.Expr, error) { + left, err := b.searchAnd(ctx.SearchAnd()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllSearchOrTail() { + orTok := tail.OR().GetSymbol() + if tail.SearchAnd() == nil { + return nil, b.missingOperand(orTok) + } + right, err := b.searchAnd(tail.SearchAnd()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "or", Left: left, Right: right, Pos: b.pos(orTok)} + } + return left, nil +} + +func (b *builder) searchAnd(ctx spl1gen.ISearchAndContext) (ast.Expr, error) { + left, err := b.searchNot(ctx.SearchNot()) + if err != nil { + return nil, err + } + for _, part := range ctx.AllSearchAndPart() { + switch p := part.(type) { + case *spl1gen.SAndExplicitContext: + andTok := p.AND().GetSymbol() + if p.SearchNot() == nil { + return nil, b.missingOperand(andTok) + } + right, err := b.searchNot(p.SearchNot()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: b.pos(andTok)} + case *spl1gen.SAndImplicitContext: + right, err := b.searchNot(p.SearchNot()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: left.Position()} + } + } + return left, nil +} + +func (b *builder) searchNot(ctx spl1gen.ISearchNotContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.SNotUnaryContext: + opTok := notOperator(c.NOT(), c.BANG()) + if c.SearchNot() == nil { + return nil, b.missingOperand(opTok) + } + operand, err := b.searchNot(c.SearchNot()) + if err != nil { + return nil, err + } + return &ast.UnaryExpr{Op: "not", Operand: operand, Pos: b.pos(opTok)}, nil + case *spl1gen.SNotPrimaryContext: + return b.searchComparison(c.SearchComparison()) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +func (b *builder) searchComparison(ctx spl1gen.ISearchComparisonContext) (ast.Expr, error) { + left, err := b.searchAdditive(ctx.SearchAdditive()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllSearchComparisonTail() { + opTok := tail.ComparisonOp().GetStart() + if tail.SearchOperand() == nil { + return nil, b.missingOperand(opTok) + } + right, err := b.searchOperand(tail.SearchOperand()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{ + Op: comparisonOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) searchOperand(ctx spl1gen.ISearchOperandContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.SOpStringContext: + tok := c.STRING().GetSymbol() + return &ast.StringLit{Value: decodeString(tok.GetText()), Pos: b.pos(tok)}, nil + case *spl1gen.SOpValueContext: + return &ast.StringLit{Value: b.text(c), Pos: b.pos(c.GetStart())}, nil + case *spl1gen.SOpExprContext: + return b.searchOperandExpr(c.SearchOperandExpr()) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +func (b *builder) searchAdditive(ctx spl1gen.ISearchAdditiveContext) (ast.Expr, error) { + left, err := b.searchMultiplicative(ctx.SearchMultiplicative()) + if err != nil { + return nil, err + } + return b.applySearchAddTails(left, ctx.AllSearchAddTail()) +} + +func (b *builder) searchMultiplicative(ctx spl1gen.ISearchMultiplicativeContext) (ast.Expr, error) { + left, err := b.searchUnary(ctx.SearchUnary()) + if err != nil { + return nil, err + } + return b.applySearchMulTails(left, ctx.AllSearchMulTail()) +} + +// searchOperandExpr lowers the expression reading of a comparison RHS. Its +// first operand is an operand that cannot begin a value run; the operator +// tails are the ordinary search tails. +func (b *builder) searchOperandExpr(ctx spl1gen.ISearchOperandExprContext) (ast.Expr, error) { + left, err := b.searchOperandUnary(ctx.SearchOperandUnary()) + if err != nil { + return nil, err + } + left, err = b.applySearchMulTails(left, ctx.AllSearchMulTail()) + if err != nil { + return nil, err + } + return b.applySearchAddTails(left, ctx.AllSearchAddTail()) +} + +func (b *builder) searchOperandUnary(ctx spl1gen.ISearchOperandUnaryContext) (ast.Expr, error) { + var signTok antlr.Token + switch { + case ctx.MINUS() != nil: + signTok = ctx.MINUS().GetSymbol() + case ctx.PLUS() != nil: + signTok = ctx.PLUS().GetSymbol() + default: + return b.searchOperandPrimary(ctx.SearchOperandPrimary()) + } + if ctx.SearchUnary() == nil { + return nil, b.missingOperand(signTok) + } + operand, err := b.searchUnary(ctx.SearchUnary()) + if err != nil { + return nil, err + } + if isMinusToken(signTok) { + return &ast.UnaryExpr{Op: "-", Operand: operand, Pos: b.pos(signTok)}, nil + } + return operand, nil +} + +func (b *builder) searchOperandPrimary(ctx spl1gen.ISearchOperandPrimaryContext) (ast.Expr, error) { + tok := ctx.GetStart() + switch tok.GetTokenType() { + case spl1gen.SPL1ParserLPAREN: + return b.searchExpr(ctx.SearchExpr()) + case spl1gen.SPL1ParserDURATION: + return &ast.DurationLit{Raw: tok.GetText(), Pos: b.pos(tok)}, nil + case spl1gen.SPL1ParserNUMBER: + value, err := strconv.ParseFloat(tok.GetText(), 64) + if err != nil { + return nil, diag.NewError(b.pos(tok), "syntax", "invalid number %q", tok.GetText()) + } + return &ast.NumberLit{Raw: tok.GetText(), Value: value, Pos: b.pos(tok)}, nil + case spl1gen.SPL1ParserSTAR: + return &ast.WildcardLit{Pos: b.pos(tok)}, nil + case spl1gen.SPL1ParserLBRACKET: + return nil, unsupportedSubsearch(b.pos(tok)) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +func (b *builder) applySearchAddTails(left ast.Expr, tails []spl1gen.ISearchAddTailContext) (ast.Expr, error) { + for _, tail := range tails { + opTok := tail.AddOp().GetStart() + if tail.SearchMultiplicative() == nil { + return nil, b.missingOperand(opTok) + } + right, err := b.searchMultiplicative(tail.SearchMultiplicative()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{ + Op: additiveOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) applySearchMulTails(left ast.Expr, tails []spl1gen.ISearchMulTailContext) (ast.Expr, error) { + for _, tail := range tails { + opTok := tail.SearchMulOp().GetStart() + if tail.SearchUnary() == nil { + return nil, b.missingOperand(opTok) + } + right, err := b.searchUnary(tail.SearchUnary()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{ + Op: multiplicativeOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) searchUnary(ctx spl1gen.ISearchUnaryContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.SUnarySignContext: + signTok := c.Sign().GetStart() + operand, err := b.searchUnary(c.SearchUnary()) + if err != nil { + return nil, err + } + if isMinusToken(signTok) { + return &ast.UnaryExpr{Op: "-", Operand: operand, Pos: b.pos(signTok)}, nil + } + return operand, nil + case *spl1gen.SUnaryPrimaryContext: + return b.searchPrimary(c.SearchPrimary()) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +func (b *builder) searchPrimary(ctx spl1gen.ISearchPrimaryContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.SPrimParenContext: + return b.searchExpr(c.SearchExpr()) + + case *spl1gen.SPrimStringContext: + tok := c.STRING().GetSymbol() + pos := b.pos(tok) + value := decodeString(tok.GetText()) + if b.comparisonAhead(tok) { + return &ast.FieldRef{Name: value, Pos: pos}, nil + } + return &ast.SearchTerm{Value: value, Pos: pos}, nil + + case *spl1gen.SPrimWordContext: + word := c.ExprWord().GetStart() + if b.comparisonAhead(word) { + return &ast.FieldRef{Name: word.GetText(), Pos: b.pos(word)}, nil + } + return &ast.SearchTerm{Value: b.text(c), Pos: b.pos(word)}, nil + + case *spl1gen.SPrimNumberContext: + tok := c.Number().GetStart() + value, err := strconv.ParseFloat(tok.GetText(), 64) + if err != nil { + return nil, diag.NewError(b.pos(tok), "syntax", "invalid number %q", tok.GetText()) + } + return &ast.NumberLit{Raw: tok.GetText(), Value: value, Pos: b.pos(tok)}, nil + + case *spl1gen.SPrimDurationContext: + tok := c.DURATION().GetSymbol() + return &ast.DurationLit{Raw: tok.GetText(), Pos: b.pos(tok)}, nil + + case *spl1gen.SPrimStarRunContext: + return &ast.SearchTerm{Value: b.text(c), Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.SPrimStarContext: + return &ast.WildcardLit{Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.SPrimSubsearchContext: + return nil, unsupportedSubsearch(b.pos(c.GetStart())) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +// comparisonAhead mirrors the hand parser's comparisonAhead(1): the token +// immediately after a word or string decides whether it names a field. +func (b *builder) comparisonAhead(t antlr.Token) bool { + switch b.after(t).GetTokenType() { + case spl1gen.SPL1ParserEQ2, spl1gen.SPL1ParserEQ, spl1gen.SPL1ParserNE, + spl1gen.SPL1ParserLT, spl1gen.SPL1ParserLE, spl1gen.SPL1ParserGT, + spl1gen.SPL1ParserGE: + return true + } + return false +} + +// --- value expressions: bare words are field references ------------------- + +func (b *builder) valueExpr(ctx spl1gen.IValueExprContext) (ast.Expr, error) { + left, err := b.valueAnd(ctx.ValueAnd()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllValueOrTail() { + orTok := tail.OR().GetSymbol() + if tail.ValueAnd() == nil { + return nil, b.missingOperand(orTok) + } + right, err := b.valueAnd(tail.ValueAnd()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "or", Left: left, Right: right, Pos: b.pos(orTok)} + } + return left, nil +} + +func (b *builder) valueAnd(ctx spl1gen.IValueAndContext) (ast.Expr, error) { + left, err := b.valueNot(ctx.ValueNot()) + if err != nil { + return nil, err + } + for _, part := range ctx.AllValueAndPart() { + switch p := part.(type) { + case *spl1gen.VAndExplicitContext: + andTok := p.AND().GetSymbol() + if p.ValueNot() == nil { + return nil, b.missingOperand(andTok) + } + right, err := b.valueNot(p.ValueNot()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: b.pos(andTok)} + case *spl1gen.VAndImplicitContext: + right, err := b.valueNot(p.ValueNot()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: left.Position()} + } + } + return left, nil +} + +func (b *builder) valueNot(ctx spl1gen.IValueNotContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.VNotUnaryContext: + opTok := notOperator(c.NOT(), c.BANG()) + if c.ValueNot() == nil { + return nil, b.missingOperand(opTok) + } + operand, err := b.valueNot(c.ValueNot()) + if err != nil { + return nil, err + } + return &ast.UnaryExpr{Op: "not", Operand: operand, Pos: b.pos(opTok)}, nil + case *spl1gen.VNotPrimaryContext: + return b.valueComparison(c.ValueComparison()) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +func (b *builder) valueComparison(ctx spl1gen.IValueComparisonContext) (ast.Expr, error) { + left, err := b.valueAdd(ctx.ValueAdd()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllValueComparisonTail() { + opTok := tail.ComparisonOp().GetStart() + if tail.ValueAdd() == nil { + return nil, b.missingOperand(opTok) + } + right, err := b.valueAdd(tail.ValueAdd()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{ + Op: comparisonOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) valueAdd(ctx spl1gen.IValueAddContext) (ast.Expr, error) { + left, err := b.valueMul(ctx.ValueMul()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllValueAddTail() { + opTok := tail.AddOp().GetStart() + if tail.ValueMul() == nil { + return nil, b.missingOperand(opTok) + } + right, err := b.valueMul(tail.ValueMul()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{ + Op: additiveOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) valueMul(ctx spl1gen.IValueMulContext) (ast.Expr, error) { + left, err := b.valueUnary(ctx.ValueUnary()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllValueMulTail() { + opTok := tail.MulOp().GetStart() + if tail.ValueUnary() == nil { + return nil, b.missingOperand(opTok) + } + right, err := b.valueUnary(tail.ValueUnary()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{ + Op: multiplicativeOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) valueUnary(ctx spl1gen.IValueUnaryContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.VUnarySignContext: + signTok := c.Sign().GetStart() + operand, err := b.valueUnary(c.ValueUnary()) + if err != nil { + return nil, err + } + if isMinusToken(signTok) { + return &ast.UnaryExpr{Op: "-", Operand: operand, Pos: b.pos(signTok)}, nil + } + return operand, nil + case *spl1gen.VUnaryPrimaryContext: + return b.valuePrimary(c.ValuePrimary()) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +func (b *builder) valuePrimary(ctx spl1gen.IValuePrimaryContext) (ast.Expr, error) { + switch c := ctx.(type) { + case *spl1gen.VPrimParenContext: + return b.valueExpr(c.ValueExpr()) + + case *spl1gen.VPrimCallContext: + name := c.ExprWord().GetStart() + args := make([]ast.Expr, 0, len(c.AllValueExpr())) + for _, arg := range c.AllValueExpr() { + expr, err := b.valueExpr(arg) + if err != nil { + return nil, err + } + args = append(args, expr) + } + return &ast.CallExpr{Name: name.GetText(), Args: args, Pos: b.pos(name)}, nil + + case *spl1gen.VPrimWordContext: + tok := c.ExprWord().GetStart() + return &ast.FieldRef{Name: tok.GetText(), Pos: b.pos(tok)}, nil + + case *spl1gen.VPrimStringContext: + tok := c.STRING().GetSymbol() + return &ast.StringLit{Value: decodeString(tok.GetText()), Pos: b.pos(tok)}, nil + + case *spl1gen.VPrimNumberContext: + tok := c.Number().GetStart() + value, err := strconv.ParseFloat(tok.GetText(), 64) + if err != nil { + return nil, diag.NewError(b.pos(tok), "syntax", "invalid number %q", tok.GetText()) + } + return &ast.NumberLit{Raw: tok.GetText(), Value: value, Pos: b.pos(tok)}, nil + + case *spl1gen.VPrimDurationContext: + tok := c.DURATION().GetSymbol() + return &ast.DurationLit{Raw: tok.GetText(), Pos: b.pos(tok)}, nil + + case *spl1gen.VPrimStarContext: + return &ast.WildcardLit{Pos: b.pos(c.GetStart())}, nil + + case *spl1gen.VPrimSubsearchContext: + return nil, unsupportedSubsearch(b.pos(c.GetStart())) + } + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "syntax", "unrecognized expression") +} + +// --- helpers -------------------------------------------------------------- + +func unsupportedSubsearch(pos ast.Pos) *diag.Error { + return diag.NewError(pos, "unsupported-subsearch", "subsearches are not implemented yet") +} + +func notOperator(not antlr.TerminalNode, bang antlr.TerminalNode) antlr.Token { + if not != nil { + return not.GetSymbol() + } + return bang.GetSymbol() +} + +func comparisonOperator(t int) string { + switch t { + case spl1gen.SPL1ParserEQ2, spl1gen.SPL1ParserEQ: + return "=" + case spl1gen.SPL1ParserNE: + return "!=" + case spl1gen.SPL1ParserLT: + return "<" + case spl1gen.SPL1ParserLE: + return "<=" + case spl1gen.SPL1ParserGT: + return ">" + case spl1gen.SPL1ParserGE: + return ">=" + } + return "" +} + +func additiveOperator(t int) string { + if isMinusTokenType(t) { + return "-" + } + return "+" +} + +func multiplicativeOperator(t int) string { + switch t { + // STAR_TERM is a multiplication operator in value position: the driver + // retypes every star that touches the preceding word, and `eval x=a*b` + // multiplies even though the star is glued to `a`. Only the term rules + // treat that spelling as part of a search term. + case spl1gen.SPL1ParserSTAR, spl1gen.SPL1ParserSTAR_TIGHT, + spl1gen.SPL1ParserSTAR_TERM, spl1gen.SPL1ParserSTAR_OP: + return "*" + case spl1gen.SPL1ParserSLASH: + return "/" + case spl1gen.SPL1ParserPERCENT: + return "%" + } + return "" +} + +// isMinusToken reports whether tok is a minus, in either spelling. The driver +// retypes a minus that begins a value run as MINUS_TIGHT, so operator code has +// to accept both. +func isMinusToken(tok antlr.Token) bool { return isMinusTokenType(tok.GetTokenType()) } + +func isMinusTokenType(t int) bool { + return t == spl1gen.SPL1ParserMINUS || t == spl1gen.SPL1ParserMINUS_TIGHT +} + +// extractTimeBounds lifts `earliest=` and `latest=` out of the search +// expression and into dedicated IR fields. Splunk treats them as global +// search-time modifiers, so they are lifted out of AND and OR branches alike. +func extractTimeBounds(st *ast.SearchStage) error { + if st.Expr == nil { + return nil + } + expr, err := stripTimeBounds(st.Expr, st) + if err != nil { + return err + } + st.Expr = expr + return nil +} + +func stripTimeBounds(e ast.Expr, st *ast.SearchStage) (ast.Expr, error) { + if u, ok := e.(*ast.UnaryExpr); ok && u.Op == "not" { + inner, err := stripTimeBounds(u.Operand, st) + if err != nil { + return nil, err + } + if inner == nil { + return nil, nil + } + u.Operand = inner + return u, nil + } + b, ok := e.(*ast.BinaryExpr) + if !ok { + return e, nil + } + if b.Op == "and" || b.Op == "or" { + left, err := stripTimeBounds(b.Left, st) + if err != nil { + return nil, err + } + right, err := stripTimeBounds(b.Right, st) + if err != nil { + return nil, err + } + // A lifted bound is TRUE in the row expression. TRUE OR X is TRUE, + // so an OR branch cannot fall back to its sibling; TRUE AND X is X. + if b.Op == "or" { + if left == nil || right == nil { + return nil, nil + } + } else { + if left == nil { + return right, nil + } + if right == nil { + return left, nil + } + } + b.Left, b.Right = left, right + return b, nil + } + if b.Op != "=" { + return e, nil + } + field, ok := b.Left.(*ast.FieldRef) + if !ok { + return e, nil + } + name := strings.ToLower(field.Name) + if name != "earliest" && name != "latest" { + return e, nil + } + raw, ok := timeValue(b.Right) + if !ok { + return e, nil + } + current := &st.Earliest + if name == "latest" { + current = &st.Latest + } + if *current != "" && *current != raw { + return nil, diag.NewError(b.Pos, "conflicting-time-bounds", + "conflicting %s bounds %q and %q", name, *current, raw) + } + *current = raw + return nil, nil +} + +func timeValue(e ast.Expr) (string, bool) { + switch v := e.(type) { + case *ast.StringLit: + return v.Value, true + case *ast.NumberLit: + return v.Raw, true + case *ast.DurationLit: + return v.Raw, true + case *ast.UnaryExpr: + if v.Op == "-" { + if d, ok := v.Operand.(*ast.DurationLit); ok { + return "-" + d.Raw, true + } + } + } + return "", false +} diff --git a/pkg/parser/spl1/fuzz_test.go b/pkg/parser/spl1/fuzz_test.go new file mode 100644 index 0000000..187d7ee --- /dev/null +++ b/pkg/parser/spl1/fuzz_test.go @@ -0,0 +1,94 @@ +package spl1 + +import ( + "strings" + "testing" + "unicode/utf8" + + "github.com/be-thomas/openspl/pkg/diag" +) + +// FuzzParseSPL1 checks the front-end's contract for arbitrary input: it +// returns either a pipeline or a *diag.Error carrying at least one positioned +// diagnostic. A panic, an unpositioned error, or a nil pipeline with a nil +// error is a failure. The seed corpus is the interesting part of the language, +// because random bytes mostly exercise the invalid-token pass. +func FuzzParseSPL1(f *testing.F) { + seeds := []string{ + `index=web status=500 | stats count by host`, + `search error timeout`, + `search "quoted phrase" host=web*`, + `index=a OR index=b OR index=c | fields - _raw`, + `earliest=-24h (status=500 OR status=503)`, + `| stats count`, + `|`, + ` `, + `index=web host=*-* status=200-299`, + `index=web | eval kb=bytes/1024 | sort limit=10 -kb | head 5`, + `index=web earliest=-24h | timechart span=5m count by host`, + `index=web | rex field=_raw "(?\w+)"`, + `index=web | bin span=1h _time | stats count by _time`, + `index=web | table host, source`, + `index=web | where a=1 AND b=2`, + `index=web | stats dc(host) AS users BY status`, + `msg="東京" host=web`, + "index=web\r\n| stats count\r\n", + `host=a+b`, + `a [search b]`, + `join [search x]`, + `index=web | search index=c status=500`, + `5month 1mo 1e+foo`, + `"unterminated`, + `stats count,`, + `sort limit 1.5`, + } + for _, s := range seeds { + f.Add(s) + } + + f.Fuzz(func(t *testing.T, src string) { + // Keep the corpus bounded: the point is parser shape, not a stress test. + if len(src) > 1<<16 || !utf8.ValidString(src) { + t.Skip() + } + + p, err := Parse(src) + if err != nil { + assertDiagError(t, src, err) + return + } + if p == nil { + t.Fatalf("Parse(%q) returned no pipeline and no error", src) + } + if len(p.Stages) == 0 { + t.Fatalf("Parse(%q) returned an empty pipeline", src) + } + for _, s := range p.Stages { + if pos := s.Position(); pos.Line < 1 || pos.Col < 1 || pos.Offset < 0 { + t.Fatalf("Parse(%q) produced stage position %+v", src, pos) + } + } + }) +} + +// assertDiagError requires a positioned *diag.Error. The parser is expected to +// report invalid input rather than fail in a way the caller cannot print. +func assertDiagError(t *testing.T, src string, err error) { + t.Helper() + + ds, ok := diag.FromError(err) + if !ok { + t.Fatalf("Parse(%q) returned %T %v, want *diag.Error", src, err, err) + } + if len(ds) == 0 { + t.Fatalf("Parse(%q) returned an empty diagnostic list", src) + } + for _, d := range ds { + if d.Pos.Line < 1 || d.Pos.Col < 1 || d.Pos.Offset < 0 { + t.Fatalf("Parse(%q) produced diagnostic %+v at %+v", src, d, d.Pos) + } + if d.Code == "" || strings.TrimSpace(d.Code) != d.Code { + t.Fatalf("Parse(%q) produced diagnostic with code %q", src, d.Code) + } + } +} diff --git a/pkg/parser/spl1/gen/spl1_base_visitor.go b/pkg/parser/spl1/gen/spl1_base_visitor.go new file mode 100644 index 0000000..318f9f0 --- /dev/null +++ b/pkg/parser/spl1/gen/spl1_base_visitor.go @@ -0,0 +1,464 @@ +// Code generated from pkg/parser/spl1/grammar/SPL1.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl1gen // SPL1 +import "github.com/antlr4-go/antlr/v4" + +type BaseSPL1Visitor struct { + *antlr.BaseParseTreeVisitor +} + +func (v *BaseSPL1Visitor) VisitStageCommand(ctx *StageCommandContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitStageSearch(ctx *StageSearchContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitStageEnd(ctx *StageEndContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdSearch(ctx *CmdSearchContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdWhere(ctx *CmdWhereContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdStats(ctx *CmdStatsContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdTimechart(ctx *CmdTimechartContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdEval(ctx *CmdEvalContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdRex(ctx *CmdRexContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdTable(ctx *CmdTableContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdFields(ctx *CmdFieldsContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdSort(ctx *CmdSortContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdHead(ctx *CmdHeadContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitCmdBin(ctx *CmdBinContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchExpr(ctx *SearchExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchOrTail(ctx *SearchOrTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchAnd(ctx *SearchAndContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSAndExplicit(ctx *SAndExplicitContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSAndImplicit(ctx *SAndImplicitContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSNotUnary(ctx *SNotUnaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSNotPrimary(ctx *SNotPrimaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchComparison(ctx *SearchComparisonContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchComparisonTail(ctx *SearchComparisonTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSOpString(ctx *SOpStringContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSOpValue(ctx *SOpValueContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSOpExpr(ctx *SOpExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchOperandValue(ctx *SearchOperandValueContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitRhsTail(ctx *RhsTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchOperandExpr(ctx *SearchOperandExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchOperandUnary(ctx *SearchOperandUnaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchOperandPrimary(ctx *SearchOperandPrimaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchAdditive(ctx *SearchAdditiveContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchAddTail(ctx *SearchAddTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchMultiplicative(ctx *SearchMultiplicativeContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchMulTail(ctx *SearchMulTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSUnarySign(ctx *SUnarySignContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSUnaryPrimary(ctx *SUnaryPrimaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimParen(ctx *SPrimParenContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimString(ctx *SPrimStringContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimWord(ctx *SPrimWordContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimNumber(ctx *SPrimNumberContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimDuration(ctx *SPrimDurationContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimStarRun(ctx *SPrimStarRunContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimStar(ctx *SPrimStarContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSPrimSubsearch(ctx *SPrimSubsearchContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchTermTail(ctx *SearchTermTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueExpr(ctx *ValueExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueOrTail(ctx *ValueOrTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueAnd(ctx *ValueAndContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVAndExplicit(ctx *VAndExplicitContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVAndImplicit(ctx *VAndImplicitContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVNotUnary(ctx *VNotUnaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVNotPrimary(ctx *VNotPrimaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueComparison(ctx *ValueComparisonContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueComparisonTail(ctx *ValueComparisonTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueAdd(ctx *ValueAddContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueAddTail(ctx *ValueAddTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueMul(ctx *ValueMulContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitValueMulTail(ctx *ValueMulTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVUnarySign(ctx *VUnarySignContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVUnaryPrimary(ctx *VUnaryPrimaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimParen(ctx *VPrimParenContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimCall(ctx *VPrimCallContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimWord(ctx *VPrimWordContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimString(ctx *VPrimStringContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimNumber(ctx *VPrimNumberContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimDuration(ctx *VPrimDurationContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimStar(ctx *VPrimStarContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitVPrimSubsearch(ctx *VPrimSubsearchContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSubsearch(ctx *SubsearchContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAbsentOperand(ctx *AbsentOperandContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitComparisonOp(ctx *ComparisonOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitOperandStar(ctx *OperandStarContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitStar(ctx *StarContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitMinus(ctx *MinusContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitNumber(ctx *NumberContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAddOp(ctx *AddOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitMulOp(ctx *MulOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSearchMulOp(ctx *SearchMulOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSign(ctx *SignContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitIdentLike(ctx *IdentLikeContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitExprWord(ctx *ExprWordContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAggList(ctx *AggListContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAgg(ctx *AggContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAggListNotSpan(ctx *AggListNotSpanContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAggNotSpan(ctx *AggNotSpanContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAliasClause(ctx *AliasClauseContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitByClause(ctx *ByClauseContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitTcSpanFirst(ctx *TcSpanFirstContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitTcAggFirst(ctx *TcAggFirstContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitTimechartSpan(ctx *TimechartSpanContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSpanAssign(ctx *SpanAssignContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitRexField(ctx *RexFieldContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitFieldExprList(ctx *FieldExprListContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitFieldExpr(ctx *FieldExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitAssignment(ctx *AssignmentContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSpanValue(ctx *SpanValueContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitTableItem(ctx *TableItemContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitFieldsSign(ctx *FieldsSignContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitFieldsItem(ctx *FieldsItemContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSortLimit(ctx *SortLimitContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSortFirstField(ctx *SortFirstFieldContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSortEmpty(ctx *SortEmptyContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSortItem(ctx *SortItemContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSortFirstItem(ctx *SortFirstItemContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitSortField(ctx *SortFieldContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitLimitKeyword(ctx *LimitKeywordContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitLimitNumber(ctx *LimitNumberContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitLimitTail(ctx *LimitTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitBinSpanItem(ctx *BinSpanItemContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitBinFieldItem(ctx *BinFieldItemContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitBinField(ctx *BinFieldContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitIdentLikeNotSpan(ctx *IdentLikeNotSpanContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL1Visitor) VisitIdentLikeNotLimit(ctx *IdentLikeNotLimitContext) interface{} { + return v.VisitChildren(ctx) +} diff --git a/pkg/parser/spl1/gen/spl1_lexer.go b/pkg/parser/spl1/gen/spl1_lexer.go new file mode 100644 index 0000000..e40e8ac --- /dev/null +++ b/pkg/parser/spl1/gen/spl1_lexer.go @@ -0,0 +1,311 @@ +// Code generated from pkg/parser/spl1/grammar/SPL1.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl1gen + +import ( + "fmt" + "github.com/antlr4-go/antlr/v4" + "sync" + "unicode" +) + +// Suppress unused import error +var _ = fmt.Printf +var _ = sync.Once{} +var _ = unicode.IsLetter + +type SPL1Lexer struct { + *antlr.BaseLexer + channelNames []string + modeNames []string + // TODO: EOF string +} + +var SPL1LexerLexerStaticData struct { + once sync.Once + serializedATN []int32 + ChannelNames []string + ModeNames []string + LiteralNames []string + SymbolicNames []string + RuleNames []string + PredictionContextCache *antlr.PredictionContextCache + atn *antlr.ATN + decisionToDFA []*antlr.DFA +} + +func spl1lexerLexerInit() { + staticData := &SPL1LexerLexerStaticData + staticData.ChannelNames = []string{ + "DEFAULT_TOKEN_CHANNEL", "HIDDEN", + } + staticData.ModeNames = []string{ + "DEFAULT_MODE", + } + staticData.LiteralNames = []string{ + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "'=='", "'!='", "'<='", "'>='", "'='", "'<'", + "'>'", "'!'", "'|'", "','", "'('", "')'", "'['", "']'", "'+'", "'-'", + "'*'", "'/'", "'%'", + } + staticData.SymbolicNames = []string{ + "", "SEARCH", "WHERE", "STATS", "TIMECHART", "EVAL", "REX", "TABLE", + "FIELDS", "SORT", "HEAD", "BIN", "BY", "AS", "SPAN", "LIMIT", "FIELD", + "AND", "OR", "NOT", "DURATION", "NUMBER", "STRING", "IDENT", "EQ2", + "NE", "LE", "GE", "EQ", "LT", "GT", "BANG", "PIPE", "COMMA", "LPAREN", + "RPAREN", "LBRACKET", "RBRACKET", "PLUS", "MINUS", "STAR", "SLASH", + "PERCENT", "WS", "UNKNOWN", + } + staticData.RuleNames = []string{ + "SEARCH", "WHERE", "STATS", "TIMECHART", "EVAL", "REX", "TABLE", "FIELDS", + "SORT", "HEAD", "BIN", "BY", "AS", "SPAN", "LIMIT", "FIELD", "AND", + "OR", "NOT", "DURATION", "NUMBER", "STRING", "DQ_BODY", "SQ_BODY", "IDENT", + "EQ2", "NE", "LE", "GE", "EQ", "LT", "GT", "BANG", "PIPE", "COMMA", + "LPAREN", "RPAREN", "LBRACKET", "RBRACKET", "PLUS", "MINUS", "STAR", + "SLASH", "PERCENT", "WS", "UNKNOWN", "DIGITS", "EXPONENT", "UNIT", + } + staticData.PredictionContextCache = antlr.NewPredictionContextCache() + staticData.serializedATN = []int32{ + 4, 0, 44, 342, 6, -1, 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, 2, + 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, + 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, + 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, + 2, 47, 7, 47, 2, 48, 7, 48, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, + 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, + 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, + 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, + 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, + 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, + 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, + 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, + 1, 18, 1, 19, 1, 19, 1, 19, 3, 19, 202, 8, 19, 1, 19, 3, 19, 205, 8, 19, + 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 3, 20, 212, 8, 20, 1, 20, 3, 20, 215, + 8, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 3, 21, 225, + 8, 21, 1, 22, 4, 22, 228, 8, 22, 11, 22, 12, 22, 229, 1, 22, 1, 22, 4, + 22, 234, 8, 22, 11, 22, 12, 22, 235, 1, 22, 1, 22, 5, 22, 240, 8, 22, 10, + 22, 12, 22, 243, 9, 22, 1, 23, 4, 23, 246, 8, 23, 11, 23, 12, 23, 247, + 1, 23, 1, 23, 4, 23, 252, 8, 23, 11, 23, 12, 23, 253, 1, 23, 1, 23, 5, + 23, 258, 8, 23, 10, 23, 12, 23, 261, 9, 23, 1, 24, 1, 24, 5, 24, 265, 8, + 24, 10, 24, 12, 24, 268, 9, 24, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, + 1, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, + 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 1, 34, 1, 35, 1, 35, 1, 36, + 1, 36, 1, 37, 1, 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 40, 1, 40, 1, 41, 1, + 41, 1, 42, 1, 42, 1, 43, 1, 43, 1, 44, 4, 44, 313, 8, 44, 11, 44, 12, 44, + 314, 1, 44, 1, 44, 1, 45, 1, 45, 1, 46, 4, 46, 322, 8, 46, 11, 46, 12, + 46, 323, 1, 47, 1, 47, 3, 47, 328, 8, 47, 1, 47, 4, 47, 331, 8, 47, 11, + 47, 12, 47, 332, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 3, 48, 341, + 8, 48, 0, 0, 49, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, + 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, + 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 0, 47, 0, 49, 23, 51, 24, 53, 25, + 55, 26, 57, 27, 59, 28, 61, 29, 63, 30, 65, 31, 67, 32, 69, 33, 71, 34, + 73, 35, 75, 36, 77, 37, 79, 38, 81, 39, 83, 40, 85, 41, 87, 42, 89, 43, + 91, 44, 93, 0, 95, 0, 97, 0, 1, 0, 28, 2, 0, 83, 83, 115, 115, 2, 0, 69, + 69, 101, 101, 2, 0, 65, 65, 97, 97, 2, 0, 82, 82, 114, 114, 2, 0, 67, 67, + 99, 99, 2, 0, 72, 72, 104, 104, 2, 0, 87, 87, 119, 119, 2, 0, 84, 84, 116, + 116, 2, 0, 73, 73, 105, 105, 2, 0, 77, 77, 109, 109, 2, 0, 86, 86, 118, + 118, 2, 0, 76, 76, 108, 108, 2, 0, 88, 88, 120, 120, 2, 0, 66, 66, 98, + 98, 2, 0, 70, 70, 102, 102, 2, 0, 68, 68, 100, 100, 2, 0, 79, 79, 111, + 111, 2, 0, 78, 78, 110, 110, 2, 0, 89, 89, 121, 121, 2, 0, 80, 80, 112, + 112, 2, 0, 34, 34, 92, 92, 2, 0, 39, 39, 92, 92, 3, 0, 64, 90, 95, 95, + 97, 122, 5, 0, 46, 46, 48, 58, 64, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, + 13, 32, 32, 1, 0, 48, 57, 2, 0, 43, 43, 45, 45, 6, 0, 100, 100, 104, 104, + 109, 109, 115, 115, 119, 119, 121, 121, 358, 0, 1, 1, 0, 0, 0, 0, 3, 1, + 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, + 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, + 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, + 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, + 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, + 0, 0, 43, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, + 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, + 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, + 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 0, 75, 1, 0, 0, 0, 0, + 77, 1, 0, 0, 0, 0, 79, 1, 0, 0, 0, 0, 81, 1, 0, 0, 0, 0, 83, 1, 0, 0, 0, + 0, 85, 1, 0, 0, 0, 0, 87, 1, 0, 0, 0, 0, 89, 1, 0, 0, 0, 0, 91, 1, 0, 0, + 0, 1, 99, 1, 0, 0, 0, 3, 106, 1, 0, 0, 0, 5, 112, 1, 0, 0, 0, 7, 118, 1, + 0, 0, 0, 9, 128, 1, 0, 0, 0, 11, 133, 1, 0, 0, 0, 13, 137, 1, 0, 0, 0, + 15, 143, 1, 0, 0, 0, 17, 150, 1, 0, 0, 0, 19, 155, 1, 0, 0, 0, 21, 160, + 1, 0, 0, 0, 23, 164, 1, 0, 0, 0, 25, 167, 1, 0, 0, 0, 27, 170, 1, 0, 0, + 0, 29, 175, 1, 0, 0, 0, 31, 181, 1, 0, 0, 0, 33, 187, 1, 0, 0, 0, 35, 191, + 1, 0, 0, 0, 37, 194, 1, 0, 0, 0, 39, 198, 1, 0, 0, 0, 41, 208, 1, 0, 0, + 0, 43, 224, 1, 0, 0, 0, 45, 241, 1, 0, 0, 0, 47, 259, 1, 0, 0, 0, 49, 262, + 1, 0, 0, 0, 51, 269, 1, 0, 0, 0, 53, 272, 1, 0, 0, 0, 55, 275, 1, 0, 0, + 0, 57, 278, 1, 0, 0, 0, 59, 281, 1, 0, 0, 0, 61, 283, 1, 0, 0, 0, 63, 285, + 1, 0, 0, 0, 65, 287, 1, 0, 0, 0, 67, 289, 1, 0, 0, 0, 69, 291, 1, 0, 0, + 0, 71, 293, 1, 0, 0, 0, 73, 295, 1, 0, 0, 0, 75, 297, 1, 0, 0, 0, 77, 299, + 1, 0, 0, 0, 79, 301, 1, 0, 0, 0, 81, 303, 1, 0, 0, 0, 83, 305, 1, 0, 0, + 0, 85, 307, 1, 0, 0, 0, 87, 309, 1, 0, 0, 0, 89, 312, 1, 0, 0, 0, 91, 318, + 1, 0, 0, 0, 93, 321, 1, 0, 0, 0, 95, 325, 1, 0, 0, 0, 97, 340, 1, 0, 0, + 0, 99, 100, 7, 0, 0, 0, 100, 101, 7, 1, 0, 0, 101, 102, 7, 2, 0, 0, 102, + 103, 7, 3, 0, 0, 103, 104, 7, 4, 0, 0, 104, 105, 7, 5, 0, 0, 105, 2, 1, + 0, 0, 0, 106, 107, 7, 6, 0, 0, 107, 108, 7, 5, 0, 0, 108, 109, 7, 1, 0, + 0, 109, 110, 7, 3, 0, 0, 110, 111, 7, 1, 0, 0, 111, 4, 1, 0, 0, 0, 112, + 113, 7, 0, 0, 0, 113, 114, 7, 7, 0, 0, 114, 115, 7, 2, 0, 0, 115, 116, + 7, 7, 0, 0, 116, 117, 7, 0, 0, 0, 117, 6, 1, 0, 0, 0, 118, 119, 7, 7, 0, + 0, 119, 120, 7, 8, 0, 0, 120, 121, 7, 9, 0, 0, 121, 122, 7, 1, 0, 0, 122, + 123, 7, 4, 0, 0, 123, 124, 7, 5, 0, 0, 124, 125, 7, 2, 0, 0, 125, 126, + 7, 3, 0, 0, 126, 127, 7, 7, 0, 0, 127, 8, 1, 0, 0, 0, 128, 129, 7, 1, 0, + 0, 129, 130, 7, 10, 0, 0, 130, 131, 7, 2, 0, 0, 131, 132, 7, 11, 0, 0, + 132, 10, 1, 0, 0, 0, 133, 134, 7, 3, 0, 0, 134, 135, 7, 1, 0, 0, 135, 136, + 7, 12, 0, 0, 136, 12, 1, 0, 0, 0, 137, 138, 7, 7, 0, 0, 138, 139, 7, 2, + 0, 0, 139, 140, 7, 13, 0, 0, 140, 141, 7, 11, 0, 0, 141, 142, 7, 1, 0, + 0, 142, 14, 1, 0, 0, 0, 143, 144, 7, 14, 0, 0, 144, 145, 7, 8, 0, 0, 145, + 146, 7, 1, 0, 0, 146, 147, 7, 11, 0, 0, 147, 148, 7, 15, 0, 0, 148, 149, + 7, 0, 0, 0, 149, 16, 1, 0, 0, 0, 150, 151, 7, 0, 0, 0, 151, 152, 7, 16, + 0, 0, 152, 153, 7, 3, 0, 0, 153, 154, 7, 7, 0, 0, 154, 18, 1, 0, 0, 0, + 155, 156, 7, 5, 0, 0, 156, 157, 7, 1, 0, 0, 157, 158, 7, 2, 0, 0, 158, + 159, 7, 15, 0, 0, 159, 20, 1, 0, 0, 0, 160, 161, 7, 13, 0, 0, 161, 162, + 7, 8, 0, 0, 162, 163, 7, 17, 0, 0, 163, 22, 1, 0, 0, 0, 164, 165, 7, 13, + 0, 0, 165, 166, 7, 18, 0, 0, 166, 24, 1, 0, 0, 0, 167, 168, 7, 2, 0, 0, + 168, 169, 7, 0, 0, 0, 169, 26, 1, 0, 0, 0, 170, 171, 7, 0, 0, 0, 171, 172, + 7, 19, 0, 0, 172, 173, 7, 2, 0, 0, 173, 174, 7, 17, 0, 0, 174, 28, 1, 0, + 0, 0, 175, 176, 7, 11, 0, 0, 176, 177, 7, 8, 0, 0, 177, 178, 7, 9, 0, 0, + 178, 179, 7, 8, 0, 0, 179, 180, 7, 7, 0, 0, 180, 30, 1, 0, 0, 0, 181, 182, + 7, 14, 0, 0, 182, 183, 7, 8, 0, 0, 183, 184, 7, 1, 0, 0, 184, 185, 7, 11, + 0, 0, 185, 186, 7, 15, 0, 0, 186, 32, 1, 0, 0, 0, 187, 188, 7, 2, 0, 0, + 188, 189, 7, 17, 0, 0, 189, 190, 7, 15, 0, 0, 190, 34, 1, 0, 0, 0, 191, + 192, 7, 16, 0, 0, 192, 193, 7, 3, 0, 0, 193, 36, 1, 0, 0, 0, 194, 195, + 7, 17, 0, 0, 195, 196, 7, 16, 0, 0, 196, 197, 7, 7, 0, 0, 197, 38, 1, 0, + 0, 0, 198, 201, 3, 93, 46, 0, 199, 200, 5, 46, 0, 0, 200, 202, 3, 93, 46, + 0, 201, 199, 1, 0, 0, 0, 201, 202, 1, 0, 0, 0, 202, 204, 1, 0, 0, 0, 203, + 205, 3, 95, 47, 0, 204, 203, 1, 0, 0, 0, 204, 205, 1, 0, 0, 0, 205, 206, + 1, 0, 0, 0, 206, 207, 3, 97, 48, 0, 207, 40, 1, 0, 0, 0, 208, 211, 3, 93, + 46, 0, 209, 210, 5, 46, 0, 0, 210, 212, 3, 93, 46, 0, 211, 209, 1, 0, 0, + 0, 211, 212, 1, 0, 0, 0, 212, 214, 1, 0, 0, 0, 213, 215, 3, 95, 47, 0, + 214, 213, 1, 0, 0, 0, 214, 215, 1, 0, 0, 0, 215, 42, 1, 0, 0, 0, 216, 217, + 5, 34, 0, 0, 217, 218, 3, 45, 22, 0, 218, 219, 5, 34, 0, 0, 219, 225, 1, + 0, 0, 0, 220, 221, 5, 39, 0, 0, 221, 222, 3, 47, 23, 0, 222, 223, 5, 39, + 0, 0, 223, 225, 1, 0, 0, 0, 224, 216, 1, 0, 0, 0, 224, 220, 1, 0, 0, 0, + 225, 44, 1, 0, 0, 0, 226, 228, 5, 92, 0, 0, 227, 226, 1, 0, 0, 0, 228, + 229, 1, 0, 0, 0, 229, 227, 1, 0, 0, 0, 229, 230, 1, 0, 0, 0, 230, 231, + 1, 0, 0, 0, 231, 240, 5, 34, 0, 0, 232, 234, 5, 92, 0, 0, 233, 232, 1, + 0, 0, 0, 234, 235, 1, 0, 0, 0, 235, 233, 1, 0, 0, 0, 235, 236, 1, 0, 0, + 0, 236, 237, 1, 0, 0, 0, 237, 240, 8, 20, 0, 0, 238, 240, 8, 20, 0, 0, + 239, 227, 1, 0, 0, 0, 239, 233, 1, 0, 0, 0, 239, 238, 1, 0, 0, 0, 240, + 243, 1, 0, 0, 0, 241, 239, 1, 0, 0, 0, 241, 242, 1, 0, 0, 0, 242, 46, 1, + 0, 0, 0, 243, 241, 1, 0, 0, 0, 244, 246, 5, 92, 0, 0, 245, 244, 1, 0, 0, + 0, 246, 247, 1, 0, 0, 0, 247, 245, 1, 0, 0, 0, 247, 248, 1, 0, 0, 0, 248, + 249, 1, 0, 0, 0, 249, 258, 5, 39, 0, 0, 250, 252, 5, 92, 0, 0, 251, 250, + 1, 0, 0, 0, 252, 253, 1, 0, 0, 0, 253, 251, 1, 0, 0, 0, 253, 254, 1, 0, + 0, 0, 254, 255, 1, 0, 0, 0, 255, 258, 8, 21, 0, 0, 256, 258, 8, 21, 0, + 0, 257, 245, 1, 0, 0, 0, 257, 251, 1, 0, 0, 0, 257, 256, 1, 0, 0, 0, 258, + 261, 1, 0, 0, 0, 259, 257, 1, 0, 0, 0, 259, 260, 1, 0, 0, 0, 260, 48, 1, + 0, 0, 0, 261, 259, 1, 0, 0, 0, 262, 266, 7, 22, 0, 0, 263, 265, 7, 23, + 0, 0, 264, 263, 1, 0, 0, 0, 265, 268, 1, 0, 0, 0, 266, 264, 1, 0, 0, 0, + 266, 267, 1, 0, 0, 0, 267, 50, 1, 0, 0, 0, 268, 266, 1, 0, 0, 0, 269, 270, + 5, 61, 0, 0, 270, 271, 5, 61, 0, 0, 271, 52, 1, 0, 0, 0, 272, 273, 5, 33, + 0, 0, 273, 274, 5, 61, 0, 0, 274, 54, 1, 0, 0, 0, 275, 276, 5, 60, 0, 0, + 276, 277, 5, 61, 0, 0, 277, 56, 1, 0, 0, 0, 278, 279, 5, 62, 0, 0, 279, + 280, 5, 61, 0, 0, 280, 58, 1, 0, 0, 0, 281, 282, 5, 61, 0, 0, 282, 60, + 1, 0, 0, 0, 283, 284, 5, 60, 0, 0, 284, 62, 1, 0, 0, 0, 285, 286, 5, 62, + 0, 0, 286, 64, 1, 0, 0, 0, 287, 288, 5, 33, 0, 0, 288, 66, 1, 0, 0, 0, + 289, 290, 5, 124, 0, 0, 290, 68, 1, 0, 0, 0, 291, 292, 5, 44, 0, 0, 292, + 70, 1, 0, 0, 0, 293, 294, 5, 40, 0, 0, 294, 72, 1, 0, 0, 0, 295, 296, 5, + 41, 0, 0, 296, 74, 1, 0, 0, 0, 297, 298, 5, 91, 0, 0, 298, 76, 1, 0, 0, + 0, 299, 300, 5, 93, 0, 0, 300, 78, 1, 0, 0, 0, 301, 302, 5, 43, 0, 0, 302, + 80, 1, 0, 0, 0, 303, 304, 5, 45, 0, 0, 304, 82, 1, 0, 0, 0, 305, 306, 5, + 42, 0, 0, 306, 84, 1, 0, 0, 0, 307, 308, 5, 47, 0, 0, 308, 86, 1, 0, 0, + 0, 309, 310, 5, 37, 0, 0, 310, 88, 1, 0, 0, 0, 311, 313, 7, 24, 0, 0, 312, + 311, 1, 0, 0, 0, 313, 314, 1, 0, 0, 0, 314, 312, 1, 0, 0, 0, 314, 315, + 1, 0, 0, 0, 315, 316, 1, 0, 0, 0, 316, 317, 6, 44, 0, 0, 317, 90, 1, 0, + 0, 0, 318, 319, 9, 0, 0, 0, 319, 92, 1, 0, 0, 0, 320, 322, 7, 25, 0, 0, + 321, 320, 1, 0, 0, 0, 322, 323, 1, 0, 0, 0, 323, 321, 1, 0, 0, 0, 323, + 324, 1, 0, 0, 0, 324, 94, 1, 0, 0, 0, 325, 327, 7, 1, 0, 0, 326, 328, 7, + 26, 0, 0, 327, 326, 1, 0, 0, 0, 327, 328, 1, 0, 0, 0, 328, 330, 1, 0, 0, + 0, 329, 331, 7, 25, 0, 0, 330, 329, 1, 0, 0, 0, 331, 332, 1, 0, 0, 0, 332, + 330, 1, 0, 0, 0, 332, 333, 1, 0, 0, 0, 333, 96, 1, 0, 0, 0, 334, 335, 5, + 109, 0, 0, 335, 336, 5, 111, 0, 0, 336, 341, 5, 110, 0, 0, 337, 338, 5, + 109, 0, 0, 338, 341, 5, 115, 0, 0, 339, 341, 7, 27, 0, 0, 340, 334, 1, + 0, 0, 0, 340, 337, 1, 0, 0, 0, 340, 339, 1, 0, 0, 0, 341, 98, 1, 0, 0, + 0, 20, 0, 201, 204, 211, 214, 224, 229, 235, 239, 241, 247, 253, 257, 259, + 266, 314, 323, 327, 332, 340, 1, 6, 0, 0, + } + deserializer := antlr.NewATNDeserializer(nil) + staticData.atn = deserializer.Deserialize(staticData.serializedATN) + atn := staticData.atn + staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) + decisionToDFA := staticData.decisionToDFA + for index, state := range atn.DecisionToState { + decisionToDFA[index] = antlr.NewDFA(state, index) + } +} + +// SPL1LexerInit initializes any static state used to implement SPL1Lexer. By default the +// static state used to implement the lexer is lazily initialized during the first call to +// NewSPL1Lexer(). You can call this function if you wish to initialize the static state ahead +// of time. +func SPL1LexerInit() { + staticData := &SPL1LexerLexerStaticData + staticData.once.Do(spl1lexerLexerInit) +} + +// NewSPL1Lexer produces a new lexer instance for the optional input antlr.CharStream. +func NewSPL1Lexer(input antlr.CharStream) *SPL1Lexer { + SPL1LexerInit() + l := new(SPL1Lexer) + l.BaseLexer = antlr.NewBaseLexer(input) + staticData := &SPL1LexerLexerStaticData + l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) + l.channelNames = staticData.ChannelNames + l.modeNames = staticData.ModeNames + l.RuleNames = staticData.RuleNames + l.LiteralNames = staticData.LiteralNames + l.SymbolicNames = staticData.SymbolicNames + l.GrammarFileName = "SPL1.g4" + // TODO: l.EOF = antlr.TokenEOF + + return l +} + +// SPL1Lexer tokens. +const ( + SPL1LexerSEARCH = 1 + SPL1LexerWHERE = 2 + SPL1LexerSTATS = 3 + SPL1LexerTIMECHART = 4 + SPL1LexerEVAL = 5 + SPL1LexerREX = 6 + SPL1LexerTABLE = 7 + SPL1LexerFIELDS = 8 + SPL1LexerSORT = 9 + SPL1LexerHEAD = 10 + SPL1LexerBIN = 11 + SPL1LexerBY = 12 + SPL1LexerAS = 13 + SPL1LexerSPAN = 14 + SPL1LexerLIMIT = 15 + SPL1LexerFIELD = 16 + SPL1LexerAND = 17 + SPL1LexerOR = 18 + SPL1LexerNOT = 19 + SPL1LexerDURATION = 20 + SPL1LexerNUMBER = 21 + SPL1LexerSTRING = 22 + SPL1LexerIDENT = 23 + SPL1LexerEQ2 = 24 + SPL1LexerNE = 25 + SPL1LexerLE = 26 + SPL1LexerGE = 27 + SPL1LexerEQ = 28 + SPL1LexerLT = 29 + SPL1LexerGT = 30 + SPL1LexerBANG = 31 + SPL1LexerPIPE = 32 + SPL1LexerCOMMA = 33 + SPL1LexerLPAREN = 34 + SPL1LexerRPAREN = 35 + SPL1LexerLBRACKET = 36 + SPL1LexerRBRACKET = 37 + SPL1LexerPLUS = 38 + SPL1LexerMINUS = 39 + SPL1LexerSTAR = 40 + SPL1LexerSLASH = 41 + SPL1LexerPERCENT = 42 + SPL1LexerWS = 43 + SPL1LexerUNKNOWN = 44 +) diff --git a/pkg/parser/spl1/gen/spl1_parser.go b/pkg/parser/spl1/gen/spl1_parser.go new file mode 100644 index 0000000..8d8265d --- /dev/null +++ b/pkg/parser/spl1/gen/spl1_parser.go @@ -0,0 +1,16295 @@ +// Code generated from pkg/parser/spl1/grammar/SPL1.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl1gen // SPL1 +import ( + "fmt" + "strconv" + "sync" + + "github.com/antlr4-go/antlr/v4" +) + +// Suppress unused import errors +var _ = fmt.Printf +var _ = strconv.Itoa +var _ = sync.Once{} + +type SPL1Parser struct { + *antlr.BaseParser +} + +var SPL1ParserStaticData struct { + once sync.Once + serializedATN []int32 + LiteralNames []string + SymbolicNames []string + RuleNames []string + PredictionContextCache *antlr.PredictionContextCache + atn *antlr.ATN + decisionToDFA []*antlr.DFA +} + +func spl1ParserInit() { + staticData := &SPL1ParserStaticData + staticData.LiteralNames = []string{ + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "'=='", "'!='", "'<='", "'>='", "'='", "'<'", + "'>'", "'!'", "'|'", "','", "'('", "')'", "'['", "']'", "'+'", "'-'", + "'*'", "'/'", "'%'", + } + staticData.SymbolicNames = []string{ + "", "SEARCH", "WHERE", "STATS", "TIMECHART", "EVAL", "REX", "TABLE", + "FIELDS", "SORT", "HEAD", "BIN", "BY", "AS", "SPAN", "LIMIT", "FIELD", + "AND", "OR", "NOT", "DURATION", "NUMBER", "STRING", "IDENT", "EQ2", + "NE", "LE", "GE", "EQ", "LT", "GT", "BANG", "PIPE", "COMMA", "LPAREN", + "RPAREN", "LBRACKET", "RBRACKET", "PLUS", "MINUS", "STAR", "SLASH", + "PERCENT", "WS", "UNKNOWN", "NUMBER_TIGHT", "STAR_TIGHT", "MINUS_TIGHT", + "STAR_TERM", "STAR_OP", "NOT_WORD", + } + staticData.RuleNames = []string{ + "stageCommand", "stageSearch", "stageEnd", "command", "searchExpr", + "searchOrTail", "searchAnd", "searchAndPart", "searchNot", "searchComparison", + "searchComparisonTail", "searchOperand", "searchOperandValue", "rhsTail", + "searchOperandExpr", "searchOperandUnary", "searchOperandPrimary", "searchAdditive", + "searchAddTail", "searchMultiplicative", "searchMulTail", "searchUnary", + "searchPrimary", "searchTermTail", "valueExpr", "valueOrTail", "valueAnd", + "valueAndPart", "valueNot", "valueComparison", "valueComparisonTail", + "valueAdd", "valueAddTail", "valueMul", "valueMulTail", "valueUnary", + "valuePrimary", "subsearch", "absentOperand", "comparisonOp", "operandStar", + "star", "minus", "number", "addOp", "mulOp", "searchMulOp", "sign", + "identLike", "exprWord", "aggList", "agg", "aggListNotSpan", "aggNotSpan", + "aliasClause", "byClause", "timechartBody", "timechartSpan", "spanAssign", + "rexField", "fieldExprList", "fieldExpr", "assignment", "spanValue", + "tableItem", "fieldsSign", "fieldsItem", "sortBody", "sortItem", "sortFirstItem", + "sortField", "limitArg", "limitTail", "binItem", "binField", "identLikeNotSpan", + "identLikeNotLimit", + } + staticData.PredictionContextCache = antlr.NewPredictionContextCache() + staticData.serializedATN = []int32{ + 4, 1, 50, 748, 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, 2, 31, 7, + 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, + 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, + 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, + 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, + 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 2, 57, 7, 57, + 2, 58, 7, 58, 2, 59, 7, 59, 2, 60, 7, 60, 2, 61, 7, 61, 2, 62, 7, 62, 2, + 63, 7, 63, 2, 64, 7, 64, 2, 65, 7, 65, 2, 66, 7, 66, 2, 67, 7, 67, 2, 68, + 7, 68, 2, 69, 7, 69, 2, 70, 7, 70, 2, 71, 7, 71, 2, 72, 7, 72, 2, 73, 7, + 73, 2, 74, 7, 74, 2, 75, 7, 75, 2, 76, 7, 76, 1, 0, 1, 0, 1, 0, 1, 1, 1, + 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 165, 8, 3, 1, 3, 1, 3, 3, 3, 169, + 8, 3, 1, 3, 1, 3, 1, 3, 3, 3, 174, 8, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, + 1, 3, 5, 3, 182, 8, 3, 10, 3, 12, 3, 185, 9, 3, 1, 3, 1, 3, 3, 3, 189, + 8, 3, 1, 3, 1, 3, 1, 3, 5, 3, 194, 8, 3, 10, 3, 12, 3, 197, 9, 3, 1, 3, + 1, 3, 3, 3, 201, 8, 3, 1, 3, 5, 3, 204, 8, 3, 10, 3, 12, 3, 207, 9, 3, + 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 213, 8, 3, 1, 3, 1, 3, 5, 3, 217, 8, 3, 10, + 3, 12, 3, 220, 9, 3, 3, 3, 222, 8, 3, 1, 4, 1, 4, 5, 4, 226, 8, 4, 10, + 4, 12, 4, 229, 9, 4, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 235, 8, 5, 1, 6, 1, + 6, 5, 6, 239, 8, 6, 10, 6, 12, 6, 242, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 3, + 7, 248, 8, 7, 1, 7, 1, 7, 3, 7, 252, 8, 7, 1, 8, 1, 8, 1, 8, 3, 8, 257, + 8, 8, 1, 8, 3, 8, 260, 8, 8, 1, 9, 1, 9, 5, 9, 264, 8, 9, 10, 9, 12, 9, + 267, 9, 9, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 273, 8, 10, 1, 11, 1, 11, + 1, 11, 3, 11, 278, 8, 11, 1, 12, 1, 12, 5, 12, 282, 8, 12, 10, 12, 12, + 12, 285, 9, 12, 1, 12, 1, 12, 5, 12, 289, 8, 12, 10, 12, 12, 12, 292, 9, + 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 3, 12, 301, 8, 12, + 3, 12, 303, 8, 12, 1, 12, 5, 12, 306, 8, 12, 10, 12, 12, 12, 309, 9, 12, + 1, 12, 1, 12, 1, 12, 3, 12, 314, 8, 12, 1, 12, 5, 12, 317, 8, 12, 10, 12, + 12, 12, 320, 9, 12, 3, 12, 322, 8, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, + 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 3, 13, 335, 8, 13, 3, 13, 337, + 8, 13, 1, 14, 1, 14, 5, 14, 341, 8, 14, 10, 14, 12, 14, 344, 9, 14, 1, + 14, 5, 14, 347, 8, 14, 10, 14, 12, 14, 350, 9, 14, 1, 15, 1, 15, 1, 15, + 3, 15, 355, 8, 15, 1, 15, 3, 15, 358, 8, 15, 1, 16, 1, 16, 1, 16, 1, 16, + 1, 16, 1, 16, 1, 16, 1, 16, 3, 16, 368, 8, 16, 1, 17, 1, 17, 5, 17, 372, + 8, 17, 10, 17, 12, 17, 375, 9, 17, 1, 18, 1, 18, 1, 18, 1, 18, 3, 18, 381, + 8, 18, 1, 19, 1, 19, 5, 19, 385, 8, 19, 10, 19, 12, 19, 388, 9, 19, 1, + 20, 1, 20, 1, 20, 1, 20, 3, 20, 394, 8, 20, 1, 21, 1, 21, 1, 21, 3, 21, + 399, 8, 21, 1, 21, 3, 21, 402, 8, 21, 1, 22, 1, 22, 1, 22, 1, 22, 1, 22, + 1, 22, 1, 22, 5, 22, 411, 8, 22, 10, 22, 12, 22, 414, 9, 22, 1, 22, 1, + 22, 1, 22, 1, 22, 1, 22, 4, 22, 421, 8, 22, 11, 22, 12, 22, 422, 1, 22, + 1, 22, 3, 22, 427, 8, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 3, + 23, 435, 8, 23, 1, 24, 1, 24, 5, 24, 439, 8, 24, 10, 24, 12, 24, 442, 9, + 24, 1, 25, 1, 25, 1, 25, 1, 25, 3, 25, 448, 8, 25, 1, 26, 1, 26, 5, 26, + 452, 8, 26, 10, 26, 12, 26, 455, 9, 26, 1, 27, 1, 27, 1, 27, 1, 27, 3, + 27, 461, 8, 27, 1, 27, 1, 27, 3, 27, 465, 8, 27, 1, 28, 1, 28, 1, 28, 3, + 28, 470, 8, 28, 1, 28, 3, 28, 473, 8, 28, 1, 29, 1, 29, 5, 29, 477, 8, + 29, 10, 29, 12, 29, 480, 9, 29, 1, 30, 1, 30, 1, 30, 1, 30, 3, 30, 486, + 8, 30, 1, 31, 1, 31, 5, 31, 490, 8, 31, 10, 31, 12, 31, 493, 9, 31, 1, + 32, 1, 32, 1, 32, 1, 32, 3, 32, 499, 8, 32, 1, 33, 1, 33, 5, 33, 503, 8, + 33, 10, 33, 12, 33, 506, 9, 33, 1, 34, 1, 34, 1, 34, 1, 34, 3, 34, 512, + 8, 34, 1, 35, 1, 35, 1, 35, 3, 35, 517, 8, 35, 1, 35, 3, 35, 520, 8, 35, + 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 5, + 36, 532, 8, 36, 10, 36, 12, 36, 535, 9, 36, 3, 36, 537, 8, 36, 1, 36, 1, + 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 1, 36, 3, 36, 547, 8, 36, 1, 37, + 1, 37, 1, 37, 5, 37, 552, 8, 37, 10, 37, 12, 37, 555, 9, 37, 1, 38, 1, + 38, 1, 38, 1, 39, 1, 39, 1, 40, 1, 40, 1, 41, 1, 41, 3, 41, 566, 8, 41, + 1, 42, 1, 42, 1, 43, 1, 43, 1, 44, 1, 44, 3, 44, 574, 8, 44, 1, 45, 1, + 45, 1, 45, 3, 45, 579, 8, 45, 1, 46, 1, 46, 1, 47, 1, 47, 3, 47, 585, 8, + 47, 1, 48, 1, 48, 1, 49, 1, 49, 1, 50, 1, 50, 1, 50, 5, 50, 594, 8, 50, + 10, 50, 12, 50, 597, 9, 50, 1, 51, 1, 51, 1, 51, 3, 51, 602, 8, 51, 1, + 51, 3, 51, 605, 8, 51, 1, 51, 3, 51, 608, 8, 51, 1, 52, 1, 52, 1, 52, 5, + 52, 613, 8, 52, 10, 52, 12, 52, 616, 9, 52, 1, 53, 1, 53, 1, 53, 3, 53, + 621, 8, 53, 1, 53, 3, 53, 624, 8, 53, 1, 53, 3, 53, 627, 8, 53, 1, 54, + 1, 54, 1, 54, 1, 55, 1, 55, 1, 55, 1, 56, 1, 56, 1, 56, 1, 56, 3, 56, 639, + 8, 56, 1, 56, 1, 56, 3, 56, 643, 8, 56, 3, 56, 645, 8, 56, 1, 57, 1, 57, + 1, 57, 1, 58, 1, 58, 1, 58, 1, 59, 1, 59, 1, 59, 1, 59, 1, 59, 1, 60, 1, + 60, 1, 60, 1, 60, 5, 60, 662, 8, 60, 10, 60, 12, 60, 665, 9, 60, 1, 61, + 1, 61, 3, 61, 669, 8, 61, 1, 62, 1, 62, 1, 62, 1, 62, 1, 63, 1, 63, 3, + 63, 677, 8, 63, 1, 64, 1, 64, 1, 64, 3, 64, 682, 8, 64, 1, 65, 1, 65, 3, + 65, 686, 8, 65, 1, 66, 1, 66, 3, 66, 690, 8, 66, 1, 67, 1, 67, 5, 67, 694, + 8, 67, 10, 67, 12, 67, 697, 9, 67, 1, 67, 1, 67, 5, 67, 701, 8, 67, 10, + 67, 12, 67, 704, 9, 67, 1, 67, 3, 67, 707, 8, 67, 1, 68, 1, 68, 3, 68, + 711, 8, 68, 1, 68, 3, 68, 714, 8, 68, 1, 69, 1, 69, 1, 69, 1, 69, 1, 69, + 3, 69, 721, 8, 69, 1, 70, 1, 70, 1, 71, 1, 71, 1, 71, 1, 71, 3, 71, 729, + 8, 71, 1, 72, 1, 72, 1, 72, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 1, 73, 3, + 73, 740, 8, 73, 1, 74, 1, 74, 1, 75, 1, 75, 1, 76, 1, 76, 1, 76, 0, 0, + 77, 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, 62, 64, 66, 68, 70, + 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, + 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, + 136, 138, 140, 142, 144, 146, 148, 150, 152, 0, 13, 1, 1, 32, 32, 2, 0, + 19, 19, 31, 31, 1, 0, 38, 39, 4, 1, 24, 30, 32, 33, 35, 35, 37, 37, 1, + 0, 24, 30, 3, 0, 40, 40, 46, 46, 48, 48, 2, 0, 39, 39, 47, 47, 2, 0, 21, + 21, 45, 45, 3, 0, 40, 42, 46, 46, 49, 49, 3, 0, 1, 19, 23, 23, 50, 50, + 3, 0, 1, 18, 23, 23, 50, 50, 3, 0, 1, 13, 15, 19, 23, 23, 4, 0, 1, 14, + 16, 19, 23, 23, 50, 50, 802, 0, 154, 1, 0, 0, 0, 2, 157, 1, 0, 0, 0, 4, + 160, 1, 0, 0, 0, 6, 221, 1, 0, 0, 0, 8, 223, 1, 0, 0, 0, 10, 230, 1, 0, + 0, 0, 12, 236, 1, 0, 0, 0, 14, 251, 1, 0, 0, 0, 16, 259, 1, 0, 0, 0, 18, + 261, 1, 0, 0, 0, 20, 268, 1, 0, 0, 0, 22, 277, 1, 0, 0, 0, 24, 321, 1, + 0, 0, 0, 26, 336, 1, 0, 0, 0, 28, 338, 1, 0, 0, 0, 30, 357, 1, 0, 0, 0, + 32, 367, 1, 0, 0, 0, 34, 369, 1, 0, 0, 0, 36, 376, 1, 0, 0, 0, 38, 382, + 1, 0, 0, 0, 40, 389, 1, 0, 0, 0, 42, 401, 1, 0, 0, 0, 44, 426, 1, 0, 0, + 0, 46, 434, 1, 0, 0, 0, 48, 436, 1, 0, 0, 0, 50, 443, 1, 0, 0, 0, 52, 449, + 1, 0, 0, 0, 54, 464, 1, 0, 0, 0, 56, 472, 1, 0, 0, 0, 58, 474, 1, 0, 0, + 0, 60, 481, 1, 0, 0, 0, 62, 487, 1, 0, 0, 0, 64, 494, 1, 0, 0, 0, 66, 500, + 1, 0, 0, 0, 68, 507, 1, 0, 0, 0, 70, 519, 1, 0, 0, 0, 72, 546, 1, 0, 0, + 0, 74, 548, 1, 0, 0, 0, 76, 556, 1, 0, 0, 0, 78, 559, 1, 0, 0, 0, 80, 561, + 1, 0, 0, 0, 82, 565, 1, 0, 0, 0, 84, 567, 1, 0, 0, 0, 86, 569, 1, 0, 0, + 0, 88, 573, 1, 0, 0, 0, 90, 578, 1, 0, 0, 0, 92, 580, 1, 0, 0, 0, 94, 584, + 1, 0, 0, 0, 96, 586, 1, 0, 0, 0, 98, 588, 1, 0, 0, 0, 100, 590, 1, 0, 0, + 0, 102, 598, 1, 0, 0, 0, 104, 609, 1, 0, 0, 0, 106, 617, 1, 0, 0, 0, 108, + 628, 1, 0, 0, 0, 110, 631, 1, 0, 0, 0, 112, 644, 1, 0, 0, 0, 114, 646, + 1, 0, 0, 0, 116, 649, 1, 0, 0, 0, 118, 652, 1, 0, 0, 0, 120, 657, 1, 0, + 0, 0, 122, 668, 1, 0, 0, 0, 124, 670, 1, 0, 0, 0, 126, 676, 1, 0, 0, 0, + 128, 681, 1, 0, 0, 0, 130, 685, 1, 0, 0, 0, 132, 689, 1, 0, 0, 0, 134, + 706, 1, 0, 0, 0, 136, 713, 1, 0, 0, 0, 138, 720, 1, 0, 0, 0, 140, 722, + 1, 0, 0, 0, 142, 728, 1, 0, 0, 0, 144, 730, 1, 0, 0, 0, 146, 739, 1, 0, + 0, 0, 148, 741, 1, 0, 0, 0, 150, 743, 1, 0, 0, 0, 152, 745, 1, 0, 0, 0, + 154, 155, 3, 6, 3, 0, 155, 156, 3, 4, 2, 0, 156, 1, 1, 0, 0, 0, 157, 158, + 3, 8, 4, 0, 158, 159, 3, 4, 2, 0, 159, 3, 1, 0, 0, 0, 160, 161, 7, 0, 0, + 0, 161, 5, 1, 0, 0, 0, 162, 164, 5, 1, 0, 0, 163, 165, 3, 8, 4, 0, 164, + 163, 1, 0, 0, 0, 164, 165, 1, 0, 0, 0, 165, 222, 1, 0, 0, 0, 166, 168, + 5, 2, 0, 0, 167, 169, 3, 48, 24, 0, 168, 167, 1, 0, 0, 0, 168, 169, 1, + 0, 0, 0, 169, 222, 1, 0, 0, 0, 170, 171, 5, 3, 0, 0, 171, 173, 3, 100, + 50, 0, 172, 174, 3, 110, 55, 0, 173, 172, 1, 0, 0, 0, 173, 174, 1, 0, 0, + 0, 174, 222, 1, 0, 0, 0, 175, 176, 5, 4, 0, 0, 176, 222, 3, 112, 56, 0, + 177, 178, 5, 5, 0, 0, 178, 183, 3, 124, 62, 0, 179, 180, 5, 33, 0, 0, 180, + 182, 3, 124, 62, 0, 181, 179, 1, 0, 0, 0, 182, 185, 1, 0, 0, 0, 183, 181, + 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 222, 1, 0, 0, 0, 185, 183, 1, 0, + 0, 0, 186, 188, 5, 6, 0, 0, 187, 189, 3, 118, 59, 0, 188, 187, 1, 0, 0, + 0, 188, 189, 1, 0, 0, 0, 189, 190, 1, 0, 0, 0, 190, 222, 5, 22, 0, 0, 191, + 195, 5, 7, 0, 0, 192, 194, 3, 128, 64, 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, 222, 1, 0, + 0, 0, 197, 195, 1, 0, 0, 0, 198, 200, 5, 8, 0, 0, 199, 201, 3, 130, 65, + 0, 200, 199, 1, 0, 0, 0, 200, 201, 1, 0, 0, 0, 201, 205, 1, 0, 0, 0, 202, + 204, 3, 132, 66, 0, 203, 202, 1, 0, 0, 0, 204, 207, 1, 0, 0, 0, 205, 203, + 1, 0, 0, 0, 205, 206, 1, 0, 0, 0, 206, 222, 1, 0, 0, 0, 207, 205, 1, 0, + 0, 0, 208, 209, 5, 9, 0, 0, 209, 222, 3, 134, 67, 0, 210, 212, 5, 10, 0, + 0, 211, 213, 3, 142, 71, 0, 212, 211, 1, 0, 0, 0, 212, 213, 1, 0, 0, 0, + 213, 222, 1, 0, 0, 0, 214, 218, 5, 11, 0, 0, 215, 217, 3, 146, 73, 0, 216, + 215, 1, 0, 0, 0, 217, 220, 1, 0, 0, 0, 218, 216, 1, 0, 0, 0, 218, 219, + 1, 0, 0, 0, 219, 222, 1, 0, 0, 0, 220, 218, 1, 0, 0, 0, 221, 162, 1, 0, + 0, 0, 221, 166, 1, 0, 0, 0, 221, 170, 1, 0, 0, 0, 221, 175, 1, 0, 0, 0, + 221, 177, 1, 0, 0, 0, 221, 186, 1, 0, 0, 0, 221, 191, 1, 0, 0, 0, 221, + 198, 1, 0, 0, 0, 221, 208, 1, 0, 0, 0, 221, 210, 1, 0, 0, 0, 221, 214, + 1, 0, 0, 0, 222, 7, 1, 0, 0, 0, 223, 227, 3, 12, 6, 0, 224, 226, 3, 10, + 5, 0, 225, 224, 1, 0, 0, 0, 226, 229, 1, 0, 0, 0, 227, 225, 1, 0, 0, 0, + 227, 228, 1, 0, 0, 0, 228, 9, 1, 0, 0, 0, 229, 227, 1, 0, 0, 0, 230, 231, + 4, 5, 0, 0, 231, 234, 5, 18, 0, 0, 232, 235, 3, 12, 6, 0, 233, 235, 3, + 76, 38, 0, 234, 232, 1, 0, 0, 0, 234, 233, 1, 0, 0, 0, 235, 11, 1, 0, 0, + 0, 236, 240, 3, 16, 8, 0, 237, 239, 3, 14, 7, 0, 238, 237, 1, 0, 0, 0, + 239, 242, 1, 0, 0, 0, 240, 238, 1, 0, 0, 0, 240, 241, 1, 0, 0, 0, 241, + 13, 1, 0, 0, 0, 242, 240, 1, 0, 0, 0, 243, 244, 4, 7, 1, 0, 244, 247, 5, + 17, 0, 0, 245, 248, 3, 16, 8, 0, 246, 248, 3, 76, 38, 0, 247, 245, 1, 0, + 0, 0, 247, 246, 1, 0, 0, 0, 248, 252, 1, 0, 0, 0, 249, 250, 4, 7, 2, 0, + 250, 252, 3, 16, 8, 0, 251, 243, 1, 0, 0, 0, 251, 249, 1, 0, 0, 0, 252, + 15, 1, 0, 0, 0, 253, 256, 7, 1, 0, 0, 254, 257, 3, 16, 8, 0, 255, 257, + 3, 76, 38, 0, 256, 254, 1, 0, 0, 0, 256, 255, 1, 0, 0, 0, 257, 260, 1, + 0, 0, 0, 258, 260, 3, 18, 9, 0, 259, 253, 1, 0, 0, 0, 259, 258, 1, 0, 0, + 0, 260, 17, 1, 0, 0, 0, 261, 265, 3, 34, 17, 0, 262, 264, 3, 20, 10, 0, + 263, 262, 1, 0, 0, 0, 264, 267, 1, 0, 0, 0, 265, 263, 1, 0, 0, 0, 265, + 266, 1, 0, 0, 0, 266, 19, 1, 0, 0, 0, 267, 265, 1, 0, 0, 0, 268, 269, 4, + 10, 3, 0, 269, 272, 3, 78, 39, 0, 270, 273, 3, 22, 11, 0, 271, 273, 3, + 76, 38, 0, 272, 270, 1, 0, 0, 0, 272, 271, 1, 0, 0, 0, 273, 21, 1, 0, 0, + 0, 274, 278, 5, 22, 0, 0, 275, 278, 3, 24, 12, 0, 276, 278, 3, 28, 14, + 0, 277, 274, 1, 0, 0, 0, 277, 275, 1, 0, 0, 0, 277, 276, 1, 0, 0, 0, 278, + 23, 1, 0, 0, 0, 279, 283, 3, 96, 48, 0, 280, 282, 3, 26, 13, 0, 281, 280, + 1, 0, 0, 0, 282, 285, 1, 0, 0, 0, 283, 281, 1, 0, 0, 0, 283, 284, 1, 0, + 0, 0, 284, 322, 1, 0, 0, 0, 285, 283, 1, 0, 0, 0, 286, 290, 5, 45, 0, 0, + 287, 289, 3, 26, 13, 0, 288, 287, 1, 0, 0, 0, 289, 292, 1, 0, 0, 0, 290, + 288, 1, 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 322, 1, 0, 0, 0, 292, 290, + 1, 0, 0, 0, 293, 302, 5, 46, 0, 0, 294, 303, 3, 96, 48, 0, 295, 303, 3, + 86, 43, 0, 296, 300, 3, 84, 42, 0, 297, 301, 3, 96, 48, 0, 298, 301, 3, + 86, 43, 0, 299, 301, 3, 82, 41, 0, 300, 297, 1, 0, 0, 0, 300, 298, 1, 0, + 0, 0, 300, 299, 1, 0, 0, 0, 301, 303, 1, 0, 0, 0, 302, 294, 1, 0, 0, 0, + 302, 295, 1, 0, 0, 0, 302, 296, 1, 0, 0, 0, 303, 307, 1, 0, 0, 0, 304, + 306, 3, 26, 13, 0, 305, 304, 1, 0, 0, 0, 306, 309, 1, 0, 0, 0, 307, 305, + 1, 0, 0, 0, 307, 308, 1, 0, 0, 0, 308, 322, 1, 0, 0, 0, 309, 307, 1, 0, + 0, 0, 310, 313, 5, 47, 0, 0, 311, 314, 3, 96, 48, 0, 312, 314, 3, 82, 41, + 0, 313, 311, 1, 0, 0, 0, 313, 312, 1, 0, 0, 0, 314, 318, 1, 0, 0, 0, 315, + 317, 3, 26, 13, 0, 316, 315, 1, 0, 0, 0, 317, 320, 1, 0, 0, 0, 318, 316, + 1, 0, 0, 0, 318, 319, 1, 0, 0, 0, 319, 322, 1, 0, 0, 0, 320, 318, 1, 0, + 0, 0, 321, 279, 1, 0, 0, 0, 321, 286, 1, 0, 0, 0, 321, 293, 1, 0, 0, 0, + 321, 310, 1, 0, 0, 0, 322, 25, 1, 0, 0, 0, 323, 324, 4, 13, 4, 0, 324, + 337, 3, 82, 41, 0, 325, 326, 4, 13, 5, 0, 326, 337, 3, 96, 48, 0, 327, + 328, 4, 13, 6, 0, 328, 337, 3, 86, 43, 0, 329, 330, 4, 13, 7, 0, 330, 334, + 3, 84, 42, 0, 331, 335, 3, 96, 48, 0, 332, 335, 3, 86, 43, 0, 333, 335, + 3, 82, 41, 0, 334, 331, 1, 0, 0, 0, 334, 332, 1, 0, 0, 0, 334, 333, 1, + 0, 0, 0, 335, 337, 1, 0, 0, 0, 336, 323, 1, 0, 0, 0, 336, 325, 1, 0, 0, + 0, 336, 327, 1, 0, 0, 0, 336, 329, 1, 0, 0, 0, 337, 27, 1, 0, 0, 0, 338, + 342, 3, 30, 15, 0, 339, 341, 3, 40, 20, 0, 340, 339, 1, 0, 0, 0, 341, 344, + 1, 0, 0, 0, 342, 340, 1, 0, 0, 0, 342, 343, 1, 0, 0, 0, 343, 348, 1, 0, + 0, 0, 344, 342, 1, 0, 0, 0, 345, 347, 3, 36, 18, 0, 346, 345, 1, 0, 0, + 0, 347, 350, 1, 0, 0, 0, 348, 346, 1, 0, 0, 0, 348, 349, 1, 0, 0, 0, 349, + 29, 1, 0, 0, 0, 350, 348, 1, 0, 0, 0, 351, 354, 7, 2, 0, 0, 352, 355, 3, + 42, 21, 0, 353, 355, 3, 76, 38, 0, 354, 352, 1, 0, 0, 0, 354, 353, 1, 0, + 0, 0, 355, 358, 1, 0, 0, 0, 356, 358, 3, 32, 16, 0, 357, 351, 1, 0, 0, + 0, 357, 356, 1, 0, 0, 0, 358, 31, 1, 0, 0, 0, 359, 360, 5, 34, 0, 0, 360, + 361, 3, 8, 4, 0, 361, 362, 5, 35, 0, 0, 362, 368, 1, 0, 0, 0, 363, 368, + 5, 20, 0, 0, 364, 368, 5, 21, 0, 0, 365, 368, 5, 40, 0, 0, 366, 368, 3, + 74, 37, 0, 367, 359, 1, 0, 0, 0, 367, 363, 1, 0, 0, 0, 367, 364, 1, 0, + 0, 0, 367, 365, 1, 0, 0, 0, 367, 366, 1, 0, 0, 0, 368, 33, 1, 0, 0, 0, + 369, 373, 3, 38, 19, 0, 370, 372, 3, 36, 18, 0, 371, 370, 1, 0, 0, 0, 372, + 375, 1, 0, 0, 0, 373, 371, 1, 0, 0, 0, 373, 374, 1, 0, 0, 0, 374, 35, 1, + 0, 0, 0, 375, 373, 1, 0, 0, 0, 376, 377, 4, 18, 8, 0, 377, 380, 3, 88, + 44, 0, 378, 381, 3, 38, 19, 0, 379, 381, 3, 76, 38, 0, 380, 378, 1, 0, + 0, 0, 380, 379, 1, 0, 0, 0, 381, 37, 1, 0, 0, 0, 382, 386, 3, 42, 21, 0, + 383, 385, 3, 40, 20, 0, 384, 383, 1, 0, 0, 0, 385, 388, 1, 0, 0, 0, 386, + 384, 1, 0, 0, 0, 386, 387, 1, 0, 0, 0, 387, 39, 1, 0, 0, 0, 388, 386, 1, + 0, 0, 0, 389, 390, 4, 20, 9, 0, 390, 393, 3, 92, 46, 0, 391, 394, 3, 42, + 21, 0, 392, 394, 3, 76, 38, 0, 393, 391, 1, 0, 0, 0, 393, 392, 1, 0, 0, + 0, 394, 41, 1, 0, 0, 0, 395, 398, 3, 94, 47, 0, 396, 399, 3, 42, 21, 0, + 397, 399, 3, 76, 38, 0, 398, 396, 1, 0, 0, 0, 398, 397, 1, 0, 0, 0, 399, + 402, 1, 0, 0, 0, 400, 402, 3, 44, 22, 0, 401, 395, 1, 0, 0, 0, 401, 400, + 1, 0, 0, 0, 402, 43, 1, 0, 0, 0, 403, 404, 5, 34, 0, 0, 404, 405, 3, 8, + 4, 0, 405, 406, 5, 35, 0, 0, 406, 427, 1, 0, 0, 0, 407, 427, 5, 22, 0, + 0, 408, 412, 3, 98, 49, 0, 409, 411, 3, 46, 23, 0, 410, 409, 1, 0, 0, 0, + 411, 414, 1, 0, 0, 0, 412, 410, 1, 0, 0, 0, 412, 413, 1, 0, 0, 0, 413, + 427, 1, 0, 0, 0, 414, 412, 1, 0, 0, 0, 415, 427, 3, 86, 43, 0, 416, 427, + 5, 20, 0, 0, 417, 418, 4, 22, 10, 0, 418, 420, 3, 82, 41, 0, 419, 421, + 3, 46, 23, 0, 420, 419, 1, 0, 0, 0, 421, 422, 1, 0, 0, 0, 422, 420, 1, + 0, 0, 0, 422, 423, 1, 0, 0, 0, 423, 427, 1, 0, 0, 0, 424, 427, 3, 80, 40, + 0, 425, 427, 3, 74, 37, 0, 426, 403, 1, 0, 0, 0, 426, 407, 1, 0, 0, 0, + 426, 408, 1, 0, 0, 0, 426, 415, 1, 0, 0, 0, 426, 416, 1, 0, 0, 0, 426, + 417, 1, 0, 0, 0, 426, 424, 1, 0, 0, 0, 426, 425, 1, 0, 0, 0, 427, 45, 1, + 0, 0, 0, 428, 429, 4, 23, 11, 0, 429, 435, 5, 48, 0, 0, 430, 431, 4, 23, + 12, 0, 431, 435, 3, 96, 48, 0, 432, 433, 4, 23, 13, 0, 433, 435, 3, 86, + 43, 0, 434, 428, 1, 0, 0, 0, 434, 430, 1, 0, 0, 0, 434, 432, 1, 0, 0, 0, + 435, 47, 1, 0, 0, 0, 436, 440, 3, 52, 26, 0, 437, 439, 3, 50, 25, 0, 438, + 437, 1, 0, 0, 0, 439, 442, 1, 0, 0, 0, 440, 438, 1, 0, 0, 0, 440, 441, + 1, 0, 0, 0, 441, 49, 1, 0, 0, 0, 442, 440, 1, 0, 0, 0, 443, 444, 4, 25, + 14, 0, 444, 447, 5, 18, 0, 0, 445, 448, 3, 52, 26, 0, 446, 448, 3, 76, + 38, 0, 447, 445, 1, 0, 0, 0, 447, 446, 1, 0, 0, 0, 448, 51, 1, 0, 0, 0, + 449, 453, 3, 56, 28, 0, 450, 452, 3, 54, 27, 0, 451, 450, 1, 0, 0, 0, 452, + 455, 1, 0, 0, 0, 453, 451, 1, 0, 0, 0, 453, 454, 1, 0, 0, 0, 454, 53, 1, + 0, 0, 0, 455, 453, 1, 0, 0, 0, 456, 457, 4, 27, 15, 0, 457, 460, 5, 17, + 0, 0, 458, 461, 3, 56, 28, 0, 459, 461, 3, 76, 38, 0, 460, 458, 1, 0, 0, + 0, 460, 459, 1, 0, 0, 0, 461, 465, 1, 0, 0, 0, 462, 463, 4, 27, 16, 0, + 463, 465, 3, 56, 28, 0, 464, 456, 1, 0, 0, 0, 464, 462, 1, 0, 0, 0, 465, + 55, 1, 0, 0, 0, 466, 469, 7, 1, 0, 0, 467, 470, 3, 56, 28, 0, 468, 470, + 3, 76, 38, 0, 469, 467, 1, 0, 0, 0, 469, 468, 1, 0, 0, 0, 470, 473, 1, + 0, 0, 0, 471, 473, 3, 58, 29, 0, 472, 466, 1, 0, 0, 0, 472, 471, 1, 0, + 0, 0, 473, 57, 1, 0, 0, 0, 474, 478, 3, 62, 31, 0, 475, 477, 3, 60, 30, + 0, 476, 475, 1, 0, 0, 0, 477, 480, 1, 0, 0, 0, 478, 476, 1, 0, 0, 0, 478, + 479, 1, 0, 0, 0, 479, 59, 1, 0, 0, 0, 480, 478, 1, 0, 0, 0, 481, 482, 4, + 30, 17, 0, 482, 485, 3, 78, 39, 0, 483, 486, 3, 62, 31, 0, 484, 486, 3, + 76, 38, 0, 485, 483, 1, 0, 0, 0, 485, 484, 1, 0, 0, 0, 486, 61, 1, 0, 0, + 0, 487, 491, 3, 66, 33, 0, 488, 490, 3, 64, 32, 0, 489, 488, 1, 0, 0, 0, + 490, 493, 1, 0, 0, 0, 491, 489, 1, 0, 0, 0, 491, 492, 1, 0, 0, 0, 492, + 63, 1, 0, 0, 0, 493, 491, 1, 0, 0, 0, 494, 495, 4, 32, 18, 0, 495, 498, + 3, 88, 44, 0, 496, 499, 3, 66, 33, 0, 497, 499, 3, 76, 38, 0, 498, 496, + 1, 0, 0, 0, 498, 497, 1, 0, 0, 0, 499, 65, 1, 0, 0, 0, 500, 504, 3, 70, + 35, 0, 501, 503, 3, 68, 34, 0, 502, 501, 1, 0, 0, 0, 503, 506, 1, 0, 0, + 0, 504, 502, 1, 0, 0, 0, 504, 505, 1, 0, 0, 0, 505, 67, 1, 0, 0, 0, 506, + 504, 1, 0, 0, 0, 507, 508, 4, 34, 19, 0, 508, 511, 3, 90, 45, 0, 509, 512, + 3, 70, 35, 0, 510, 512, 3, 76, 38, 0, 511, 509, 1, 0, 0, 0, 511, 510, 1, + 0, 0, 0, 512, 69, 1, 0, 0, 0, 513, 516, 3, 94, 47, 0, 514, 517, 3, 70, + 35, 0, 515, 517, 3, 76, 38, 0, 516, 514, 1, 0, 0, 0, 516, 515, 1, 0, 0, + 0, 517, 520, 1, 0, 0, 0, 518, 520, 3, 72, 36, 0, 519, 513, 1, 0, 0, 0, + 519, 518, 1, 0, 0, 0, 520, 71, 1, 0, 0, 0, 521, 522, 5, 34, 0, 0, 522, + 523, 3, 48, 24, 0, 523, 524, 5, 35, 0, 0, 524, 547, 1, 0, 0, 0, 525, 526, + 4, 36, 20, 0, 526, 527, 3, 98, 49, 0, 527, 536, 5, 34, 0, 0, 528, 533, + 3, 48, 24, 0, 529, 530, 5, 33, 0, 0, 530, 532, 3, 48, 24, 0, 531, 529, + 1, 0, 0, 0, 532, 535, 1, 0, 0, 0, 533, 531, 1, 0, 0, 0, 533, 534, 1, 0, + 0, 0, 534, 537, 1, 0, 0, 0, 535, 533, 1, 0, 0, 0, 536, 528, 1, 0, 0, 0, + 536, 537, 1, 0, 0, 0, 537, 538, 1, 0, 0, 0, 538, 539, 5, 35, 0, 0, 539, + 547, 1, 0, 0, 0, 540, 547, 3, 98, 49, 0, 541, 547, 5, 22, 0, 0, 542, 547, + 3, 86, 43, 0, 543, 547, 5, 20, 0, 0, 544, 547, 3, 80, 40, 0, 545, 547, + 3, 74, 37, 0, 546, 521, 1, 0, 0, 0, 546, 525, 1, 0, 0, 0, 546, 540, 1, + 0, 0, 0, 546, 541, 1, 0, 0, 0, 546, 542, 1, 0, 0, 0, 546, 543, 1, 0, 0, + 0, 546, 544, 1, 0, 0, 0, 546, 545, 1, 0, 0, 0, 547, 73, 1, 0, 0, 0, 548, + 549, 5, 36, 0, 0, 549, 553, 6, 37, -1, 0, 550, 552, 8, 0, 0, 0, 551, 550, + 1, 0, 0, 0, 552, 555, 1, 0, 0, 0, 553, 551, 1, 0, 0, 0, 553, 554, 1, 0, + 0, 0, 554, 75, 1, 0, 0, 0, 555, 553, 1, 0, 0, 0, 556, 557, 6, 38, -1, 0, + 557, 558, 7, 3, 0, 0, 558, 77, 1, 0, 0, 0, 559, 560, 7, 4, 0, 0, 560, 79, + 1, 0, 0, 0, 561, 562, 7, 5, 0, 0, 562, 81, 1, 0, 0, 0, 563, 566, 3, 80, + 40, 0, 564, 566, 5, 49, 0, 0, 565, 563, 1, 0, 0, 0, 565, 564, 1, 0, 0, + 0, 566, 83, 1, 0, 0, 0, 567, 568, 7, 6, 0, 0, 568, 85, 1, 0, 0, 0, 569, + 570, 7, 7, 0, 0, 570, 87, 1, 0, 0, 0, 571, 574, 5, 38, 0, 0, 572, 574, + 3, 84, 42, 0, 573, 571, 1, 0, 0, 0, 573, 572, 1, 0, 0, 0, 574, 89, 1, 0, + 0, 0, 575, 579, 3, 82, 41, 0, 576, 579, 5, 41, 0, 0, 577, 579, 5, 42, 0, + 0, 578, 575, 1, 0, 0, 0, 578, 576, 1, 0, 0, 0, 578, 577, 1, 0, 0, 0, 579, + 91, 1, 0, 0, 0, 580, 581, 7, 8, 0, 0, 581, 93, 1, 0, 0, 0, 582, 585, 3, + 84, 42, 0, 583, 585, 5, 38, 0, 0, 584, 582, 1, 0, 0, 0, 584, 583, 1, 0, + 0, 0, 585, 95, 1, 0, 0, 0, 586, 587, 7, 9, 0, 0, 587, 97, 1, 0, 0, 0, 588, + 589, 7, 10, 0, 0, 589, 99, 1, 0, 0, 0, 590, 595, 3, 102, 51, 0, 591, 592, + 5, 33, 0, 0, 592, 594, 3, 102, 51, 0, 593, 591, 1, 0, 0, 0, 594, 597, 1, + 0, 0, 0, 595, 593, 1, 0, 0, 0, 595, 596, 1, 0, 0, 0, 596, 101, 1, 0, 0, + 0, 597, 595, 1, 0, 0, 0, 598, 604, 3, 96, 48, 0, 599, 601, 5, 34, 0, 0, + 600, 602, 3, 48, 24, 0, 601, 600, 1, 0, 0, 0, 601, 602, 1, 0, 0, 0, 602, + 603, 1, 0, 0, 0, 603, 605, 5, 35, 0, 0, 604, 599, 1, 0, 0, 0, 604, 605, + 1, 0, 0, 0, 605, 607, 1, 0, 0, 0, 606, 608, 3, 108, 54, 0, 607, 606, 1, + 0, 0, 0, 607, 608, 1, 0, 0, 0, 608, 103, 1, 0, 0, 0, 609, 614, 3, 106, + 53, 0, 610, 611, 5, 33, 0, 0, 611, 613, 3, 102, 51, 0, 612, 610, 1, 0, + 0, 0, 613, 616, 1, 0, 0, 0, 614, 612, 1, 0, 0, 0, 614, 615, 1, 0, 0, 0, + 615, 105, 1, 0, 0, 0, 616, 614, 1, 0, 0, 0, 617, 623, 3, 150, 75, 0, 618, + 620, 5, 34, 0, 0, 619, 621, 3, 48, 24, 0, 620, 619, 1, 0, 0, 0, 620, 621, + 1, 0, 0, 0, 621, 622, 1, 0, 0, 0, 622, 624, 5, 35, 0, 0, 623, 618, 1, 0, + 0, 0, 623, 624, 1, 0, 0, 0, 624, 626, 1, 0, 0, 0, 625, 627, 3, 108, 54, + 0, 626, 625, 1, 0, 0, 0, 626, 627, 1, 0, 0, 0, 627, 107, 1, 0, 0, 0, 628, + 629, 5, 13, 0, 0, 629, 630, 3, 96, 48, 0, 630, 109, 1, 0, 0, 0, 631, 632, + 5, 12, 0, 0, 632, 633, 3, 120, 60, 0, 633, 111, 1, 0, 0, 0, 634, 635, 4, + 56, 21, 0, 635, 636, 3, 114, 57, 0, 636, 638, 3, 100, 50, 0, 637, 639, + 3, 110, 55, 0, 638, 637, 1, 0, 0, 0, 638, 639, 1, 0, 0, 0, 639, 645, 1, + 0, 0, 0, 640, 642, 3, 104, 52, 0, 641, 643, 3, 110, 55, 0, 642, 641, 1, + 0, 0, 0, 642, 643, 1, 0, 0, 0, 643, 645, 1, 0, 0, 0, 644, 634, 1, 0, 0, + 0, 644, 640, 1, 0, 0, 0, 645, 113, 1, 0, 0, 0, 646, 647, 5, 14, 0, 0, 647, + 648, 3, 116, 58, 0, 648, 115, 1, 0, 0, 0, 649, 650, 5, 28, 0, 0, 650, 651, + 3, 126, 63, 0, 651, 117, 1, 0, 0, 0, 652, 653, 4, 59, 22, 0, 653, 654, + 5, 16, 0, 0, 654, 655, 5, 28, 0, 0, 655, 656, 3, 96, 48, 0, 656, 119, 1, + 0, 0, 0, 657, 663, 3, 122, 61, 0, 658, 659, 5, 33, 0, 0, 659, 662, 3, 122, + 61, 0, 660, 662, 3, 122, 61, 0, 661, 658, 1, 0, 0, 0, 661, 660, 1, 0, 0, + 0, 662, 665, 1, 0, 0, 0, 663, 661, 1, 0, 0, 0, 663, 664, 1, 0, 0, 0, 664, + 121, 1, 0, 0, 0, 665, 663, 1, 0, 0, 0, 666, 669, 3, 96, 48, 0, 667, 669, + 3, 82, 41, 0, 668, 666, 1, 0, 0, 0, 668, 667, 1, 0, 0, 0, 669, 123, 1, + 0, 0, 0, 670, 671, 3, 96, 48, 0, 671, 672, 5, 28, 0, 0, 672, 673, 3, 48, + 24, 0, 673, 125, 1, 0, 0, 0, 674, 677, 5, 20, 0, 0, 675, 677, 3, 96, 48, + 0, 676, 674, 1, 0, 0, 0, 676, 675, 1, 0, 0, 0, 677, 127, 1, 0, 0, 0, 678, + 682, 5, 33, 0, 0, 679, 682, 3, 82, 41, 0, 680, 682, 3, 96, 48, 0, 681, + 678, 1, 0, 0, 0, 681, 679, 1, 0, 0, 0, 681, 680, 1, 0, 0, 0, 682, 129, + 1, 0, 0, 0, 683, 686, 3, 84, 42, 0, 684, 686, 5, 38, 0, 0, 685, 683, 1, + 0, 0, 0, 685, 684, 1, 0, 0, 0, 686, 131, 1, 0, 0, 0, 687, 690, 5, 33, 0, + 0, 688, 690, 3, 96, 48, 0, 689, 687, 1, 0, 0, 0, 689, 688, 1, 0, 0, 0, + 690, 133, 1, 0, 0, 0, 691, 695, 3, 142, 71, 0, 692, 694, 3, 136, 68, 0, + 693, 692, 1, 0, 0, 0, 694, 697, 1, 0, 0, 0, 695, 693, 1, 0, 0, 0, 695, + 696, 1, 0, 0, 0, 696, 707, 1, 0, 0, 0, 697, 695, 1, 0, 0, 0, 698, 702, + 3, 138, 69, 0, 699, 701, 3, 136, 68, 0, 700, 699, 1, 0, 0, 0, 701, 704, + 1, 0, 0, 0, 702, 700, 1, 0, 0, 0, 702, 703, 1, 0, 0, 0, 703, 707, 1, 0, + 0, 0, 704, 702, 1, 0, 0, 0, 705, 707, 1, 0, 0, 0, 706, 691, 1, 0, 0, 0, + 706, 698, 1, 0, 0, 0, 706, 705, 1, 0, 0, 0, 707, 135, 1, 0, 0, 0, 708, + 714, 5, 33, 0, 0, 709, 711, 3, 94, 47, 0, 710, 709, 1, 0, 0, 0, 710, 711, + 1, 0, 0, 0, 711, 712, 1, 0, 0, 0, 712, 714, 3, 96, 48, 0, 713, 708, 1, + 0, 0, 0, 713, 710, 1, 0, 0, 0, 714, 137, 1, 0, 0, 0, 715, 721, 5, 33, 0, + 0, 716, 717, 3, 94, 47, 0, 717, 718, 3, 96, 48, 0, 718, 721, 1, 0, 0, 0, + 719, 721, 3, 140, 70, 0, 720, 715, 1, 0, 0, 0, 720, 716, 1, 0, 0, 0, 720, + 719, 1, 0, 0, 0, 721, 139, 1, 0, 0, 0, 722, 723, 3, 152, 76, 0, 723, 141, + 1, 0, 0, 0, 724, 725, 4, 71, 23, 0, 725, 726, 5, 15, 0, 0, 726, 729, 3, + 144, 72, 0, 727, 729, 3, 86, 43, 0, 728, 724, 1, 0, 0, 0, 728, 727, 1, + 0, 0, 0, 729, 143, 1, 0, 0, 0, 730, 731, 5, 28, 0, 0, 731, 732, 3, 86, + 43, 0, 732, 145, 1, 0, 0, 0, 733, 734, 4, 73, 24, 0, 734, 735, 5, 14, 0, + 0, 735, 740, 3, 116, 58, 0, 736, 737, 3, 148, 74, 0, 737, 738, 6, 73, -1, + 0, 738, 740, 1, 0, 0, 0, 739, 733, 1, 0, 0, 0, 739, 736, 1, 0, 0, 0, 740, + 147, 1, 0, 0, 0, 741, 742, 3, 150, 75, 0, 742, 149, 1, 0, 0, 0, 743, 744, + 7, 11, 0, 0, 744, 151, 1, 0, 0, 0, 745, 746, 7, 12, 0, 0, 746, 153, 1, + 0, 0, 0, 95, 164, 168, 173, 183, 188, 195, 200, 205, 212, 218, 221, 227, + 234, 240, 247, 251, 256, 259, 265, 272, 277, 283, 290, 300, 302, 307, 313, + 318, 321, 334, 336, 342, 348, 354, 357, 367, 373, 380, 386, 393, 398, 401, + 412, 422, 426, 434, 440, 447, 453, 460, 464, 469, 472, 478, 485, 491, 498, + 504, 511, 516, 519, 533, 536, 546, 553, 565, 573, 578, 584, 595, 601, 604, + 607, 614, 620, 623, 626, 638, 642, 644, 661, 663, 668, 676, 681, 685, 689, + 695, 702, 706, 710, 713, 720, 728, 739, + } + deserializer := antlr.NewATNDeserializer(nil) + staticData.atn = deserializer.Deserialize(staticData.serializedATN) + atn := staticData.atn + staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) + decisionToDFA := staticData.decisionToDFA + for index, state := range atn.DecisionToState { + decisionToDFA[index] = antlr.NewDFA(state, index) + } +} + +// SPL1ParserInit initializes any static state used to implement SPL1Parser. By default the +// static state used to implement the parser is lazily initialized during the first call to +// NewSPL1Parser(). You can call this function if you wish to initialize the static state ahead +// of time. +func SPL1ParserInit() { + staticData := &SPL1ParserStaticData + staticData.once.Do(spl1ParserInit) +} + +// NewSPL1Parser produces a new parser instance for the optional input antlr.TokenStream. +func NewSPL1Parser(input antlr.TokenStream) *SPL1Parser { + SPL1ParserInit() + this := new(SPL1Parser) + this.BaseParser = antlr.NewBaseParser(input) + staticData := &SPL1ParserStaticData + this.Interpreter = antlr.NewParserATNSimulator(this, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) + this.RuleNames = staticData.RuleNames + this.LiteralNames = staticData.LiteralNames + this.SymbolicNames = staticData.SymbolicNames + this.GrammarFileName = "SPL1.g4" + + return this +} + +// Note that '@members' cannot be changed now, but this should have been 'globals' +// If you are looking to have variables for each instance, use '@structmembers' + +// la returns the token type at lookahead k. +func (p *SPL1Parser) la(k int) int { return p.GetTokenStream().LA(k) } + +// tok returns the token at lookahead k; k may be negative. +func (p *SPL1Parser) tok(k int) antlr.Token { return p.GetTokenStream().LT(k) } + +// at reports whether the current token has type t. +func (p *SPL1Parser) at(t int) bool { return p.la(1) == t } + +// isIdentLike reports whether token type t is accepted by identLike. +func (p *SPL1Parser) isIdentLike(t int) bool { + switch t { + case SPL1ParserIDENT, SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, + SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, + SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, + SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, + SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, + SPL1ParserNOT_WORD: + return true + } + return false +} + +// touches reports whether the tokens at k and k+1 are adjacent in the source. +// Token offsets are rune indexes, so this is exact. +func (p *SPL1Parser) touches(k int) bool { + a, b := p.tok(k), p.tok(k+1) + if a == nil || b == nil { + return false + } + return a.GetStop()+1 == b.GetStart() +} + +// touchingPrev reports whether the current token starts exactly where the +// last consumed token ended. +func (p *SPL1Parser) touchingPrev() bool { + prev, cur := p.tok(-1), p.tok(1) + if prev == nil || cur == nil { + return false + } + return prev.GetStop()+1 == cur.GetStart() +} + +// startsTerm is the implicit-AND boundary. Every word starts a term except +// the conjunction and clause keywords, matching the hand parser. Tight tokens +// are the same spellings as their plain forms, so they start a term too. +func (p *SPL1Parser) startsTerm() bool { + t := p.la(1) + switch t { + case SPL1ParserAND, SPL1ParserOR, SPL1ParserBY, SPL1ParserAS: + return false + case SPL1ParserSTAR_OP: + // A star with an operand on its left multiplies; it never starts an + // implicit-AND term. + return false + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM: + // After a completed operand a star multiplies; it starts a new + // implicit-AND term only where no operand precedes it (`where * a`). + // Without this, `where (a*)` parses as `a AND TRUE` instead of + // reporting the missing operand after the star. + return !p.prevEndsOperand() + case SPL1ParserSTRING, SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT, + SPL1ParserDURATION, SPL1ParserLPAREN, SPL1ParserLBRACKET: + return true + } + return p.isIdentLike(t) +} + +// prevEndsOperand reports whether the last consumed token can end an operand, +// so a following star is a multiplication operator. The token stream is the +// tight one, so a retyped star still reads as a star. +func (p *SPL1Parser) prevEndsOperand() bool { + prev := p.tok(-1) + if prev == nil { + return false + } + switch t := prev.GetTokenType(); t { + case SPL1ParserSTRING, SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT, + SPL1ParserDURATION, SPL1ParserRPAREN, SPL1ParserRBRACKET, + SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM: + return true + default: + return p.isIdentLike(t) + } +} + +// isStar, isNumber, and isMinus accept every spelling of a token, wherever the +// term, value-run, and operator distinctions do not matter. +func (p *SPL1Parser) isStar(t int) bool { + return t == SPL1ParserSTAR || t == SPL1ParserSTAR_TIGHT || + t == SPL1ParserSTAR_TERM +} + +func (p *SPL1Parser) isNumber(t int) bool { + return t == SPL1ParserNUMBER || t == SPL1ParserNUMBER_TIGHT +} + +func (p *SPL1Parser) isMinus(t int) bool { + return t == SPL1ParserMINUS || t == SPL1ParserMINUS_TIGHT +} + +// callAhead reports whether an identifier is followed by '('. Adjacency is +// not required: `eval x=lower (msg)` is a call. +func (p *SPL1Parser) callAhead() bool { return p.la(2) == SPL1ParserLPAREN } + +// atNot, atCompare, atAdd, and atMul report whether the current token is an +// operator of that kind. The binary and unary rules gate on them so the +// parser commits to the operator and blames the missing operand after it, +// which is where the hand parser reports. +func (p *SPL1Parser) atNot() bool { return p.at(SPL1ParserNOT) || p.at(SPL1ParserBANG) } + +func (p *SPL1Parser) atCompare() bool { + switch p.la(1) { + case SPL1ParserEQ2, SPL1ParserEQ, SPL1ParserNE, SPL1ParserLT, SPL1ParserLE, + SPL1ParserGT, SPL1ParserGE: + return true + } + return false +} + +func (p *SPL1Parser) atAdd() bool { + return p.at(SPL1ParserPLUS) || p.at(SPL1ParserMINUS) || p.at(SPL1ParserMINUS_TIGHT) +} + +func (p *SPL1Parser) atMul() bool { + t := p.la(1) + return t == SPL1ParserSTAR_OP || p.isStar(t) || + t == SPL1ParserSLASH || t == SPL1ParserPERCENT +} + +// atSearchMul is atMul for term position, where an adjacent STAR is part of +// the preceding term (`error*`) rather than a multiplication operator. +func (p *SPL1Parser) atSearchMul() bool { + t := p.la(1) + return t == SPL1ParserSTAR || t == SPL1ParserSTAR_TIGHT || + t == SPL1ParserSTAR_OP || + t == SPL1ParserSLASH || t == SPL1ParserPERCENT +} + +// parseAbort is the panic value for a grammar action that ends the parse at a +// token. The front-end recovers it structurally and maps the token through its +// SourceMap; generated code cannot import the front-end, so the methods below +// are the whole contract. +type parseAbort struct { + token antlr.Token + code string + message string +} + +func (a parseAbort) AbortToken() antlr.Token { return a.token } +func (a parseAbort) AbortCode() string { return a.code } +func (a parseAbort) AbortMessage() string { return a.message } + +// abortMissingOperand ends the parse at the token where an operand was +// required, which is where the hand parser fails. +func (p *SPL1Parser) abortMissingOperand() { + t := p.tok(1) + message := "expected an expression, found end of query" + if t != nil && t.GetTokenType() != antlr.TokenEOF { + message = "expected an expression, found " + fmt.Sprintf("%q", t.GetText()) + } + panic(parseAbort{token: t, code: "syntax", message: message}) +} + +// binFieldSeen refuses a second `bin` field at that field's token, before the +// rest of the stage is parsed. The hand parser reports the extra field in +// source order, so a later grammar error must not be able to overtake it. The +// completed siblings live in the enclosing command context's children. +func (p *SPL1Parser) binFieldSeen() { + t := p.tok(-1) + cur := p.GetParserRuleContext() + parent := cur.GetParent() + if t == nil || parent == nil { + return + } + for _, child := range parent.GetChildren() { + prev, ok := child.(*BinFieldItemContext) + if !ok || prev == cur { + continue + } + panic(parseAbort{ + token: t, + code: "syntax", + message: fmt.Sprintf("bin accepts exactly one field; found %q after %q", + t.GetText(), prev.BinField().GetStart().GetText()), + }) + } +} + +// abortSubsearch refuses a subsearch at its opening bracket, before the rest of +// the stage is parsed, matching the hand parser's fail-fast priority. +func (p *SPL1Parser) abortSubsearch() { + panic(parseAbort{ + token: p.tok(-1), + code: "unsupported-subsearch", + message: "subsearches are not supported", + }) +} + +// termStarRun reports whether a '*' begins a tight free-text wildcard run +// such as `*error*`, as opposed to a bare wildcard. +func (p *SPL1Parser) termStarRun() bool { + if !p.isStar(p.la(1)) || !p.touches(1) { + return false + } + return p.isIdentLike(p.la(2)) || p.isNumber(p.la(2)) +} + +// hyphenTail reports whether a '-' continues a value run: it must touch the +// previous component and be followed, without a space, by a word, number, or +// wildcard. +func (p *SPL1Parser) hyphenTail() bool { + return p.touchingPrev() && p.touches(1) && + (p.isIdentLike(p.la(2)) || p.isNumber(p.la(2)) || p.isStar(p.la(2))) +} + +// SPL1Parser tokens. +const ( + SPL1ParserEOF = antlr.TokenEOF + SPL1ParserSEARCH = 1 + SPL1ParserWHERE = 2 + SPL1ParserSTATS = 3 + SPL1ParserTIMECHART = 4 + SPL1ParserEVAL = 5 + SPL1ParserREX = 6 + SPL1ParserTABLE = 7 + SPL1ParserFIELDS = 8 + SPL1ParserSORT = 9 + SPL1ParserHEAD = 10 + SPL1ParserBIN = 11 + SPL1ParserBY = 12 + SPL1ParserAS = 13 + SPL1ParserSPAN = 14 + SPL1ParserLIMIT = 15 + SPL1ParserFIELD = 16 + SPL1ParserAND = 17 + SPL1ParserOR = 18 + SPL1ParserNOT = 19 + SPL1ParserDURATION = 20 + SPL1ParserNUMBER = 21 + SPL1ParserSTRING = 22 + SPL1ParserIDENT = 23 + SPL1ParserEQ2 = 24 + SPL1ParserNE = 25 + SPL1ParserLE = 26 + SPL1ParserGE = 27 + SPL1ParserEQ = 28 + SPL1ParserLT = 29 + SPL1ParserGT = 30 + SPL1ParserBANG = 31 + SPL1ParserPIPE = 32 + SPL1ParserCOMMA = 33 + SPL1ParserLPAREN = 34 + SPL1ParserRPAREN = 35 + SPL1ParserLBRACKET = 36 + SPL1ParserRBRACKET = 37 + SPL1ParserPLUS = 38 + SPL1ParserMINUS = 39 + SPL1ParserSTAR = 40 + SPL1ParserSLASH = 41 + SPL1ParserPERCENT = 42 + SPL1ParserWS = 43 + SPL1ParserUNKNOWN = 44 + SPL1ParserNUMBER_TIGHT = 45 + SPL1ParserSTAR_TIGHT = 46 + SPL1ParserMINUS_TIGHT = 47 + SPL1ParserSTAR_TERM = 48 + SPL1ParserSTAR_OP = 49 + SPL1ParserNOT_WORD = 50 +) + +// SPL1Parser rules. +const ( + SPL1ParserRULE_stageCommand = 0 + SPL1ParserRULE_stageSearch = 1 + SPL1ParserRULE_stageEnd = 2 + SPL1ParserRULE_command = 3 + SPL1ParserRULE_searchExpr = 4 + SPL1ParserRULE_searchOrTail = 5 + SPL1ParserRULE_searchAnd = 6 + SPL1ParserRULE_searchAndPart = 7 + SPL1ParserRULE_searchNot = 8 + SPL1ParserRULE_searchComparison = 9 + SPL1ParserRULE_searchComparisonTail = 10 + SPL1ParserRULE_searchOperand = 11 + SPL1ParserRULE_searchOperandValue = 12 + SPL1ParserRULE_rhsTail = 13 + SPL1ParserRULE_searchOperandExpr = 14 + SPL1ParserRULE_searchOperandUnary = 15 + SPL1ParserRULE_searchOperandPrimary = 16 + SPL1ParserRULE_searchAdditive = 17 + SPL1ParserRULE_searchAddTail = 18 + SPL1ParserRULE_searchMultiplicative = 19 + SPL1ParserRULE_searchMulTail = 20 + SPL1ParserRULE_searchUnary = 21 + SPL1ParserRULE_searchPrimary = 22 + SPL1ParserRULE_searchTermTail = 23 + SPL1ParserRULE_valueExpr = 24 + SPL1ParserRULE_valueOrTail = 25 + SPL1ParserRULE_valueAnd = 26 + SPL1ParserRULE_valueAndPart = 27 + SPL1ParserRULE_valueNot = 28 + SPL1ParserRULE_valueComparison = 29 + SPL1ParserRULE_valueComparisonTail = 30 + SPL1ParserRULE_valueAdd = 31 + SPL1ParserRULE_valueAddTail = 32 + SPL1ParserRULE_valueMul = 33 + SPL1ParserRULE_valueMulTail = 34 + SPL1ParserRULE_valueUnary = 35 + SPL1ParserRULE_valuePrimary = 36 + SPL1ParserRULE_subsearch = 37 + SPL1ParserRULE_absentOperand = 38 + SPL1ParserRULE_comparisonOp = 39 + SPL1ParserRULE_operandStar = 40 + SPL1ParserRULE_star = 41 + SPL1ParserRULE_minus = 42 + SPL1ParserRULE_number = 43 + SPL1ParserRULE_addOp = 44 + SPL1ParserRULE_mulOp = 45 + SPL1ParserRULE_searchMulOp = 46 + SPL1ParserRULE_sign = 47 + SPL1ParserRULE_identLike = 48 + SPL1ParserRULE_exprWord = 49 + SPL1ParserRULE_aggList = 50 + SPL1ParserRULE_agg = 51 + SPL1ParserRULE_aggListNotSpan = 52 + SPL1ParserRULE_aggNotSpan = 53 + SPL1ParserRULE_aliasClause = 54 + SPL1ParserRULE_byClause = 55 + SPL1ParserRULE_timechartBody = 56 + SPL1ParserRULE_timechartSpan = 57 + SPL1ParserRULE_spanAssign = 58 + SPL1ParserRULE_rexField = 59 + SPL1ParserRULE_fieldExprList = 60 + SPL1ParserRULE_fieldExpr = 61 + SPL1ParserRULE_assignment = 62 + SPL1ParserRULE_spanValue = 63 + SPL1ParserRULE_tableItem = 64 + SPL1ParserRULE_fieldsSign = 65 + SPL1ParserRULE_fieldsItem = 66 + SPL1ParserRULE_sortBody = 67 + SPL1ParserRULE_sortItem = 68 + SPL1ParserRULE_sortFirstItem = 69 + SPL1ParserRULE_sortField = 70 + SPL1ParserRULE_limitArg = 71 + SPL1ParserRULE_limitTail = 72 + SPL1ParserRULE_binItem = 73 + SPL1ParserRULE_binField = 74 + SPL1ParserRULE_identLikeNotSpan = 75 + SPL1ParserRULE_identLikeNotLimit = 76 +) + +// IStageCommandContext is an interface to support dynamic dispatch. +type IStageCommandContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Command() ICommandContext + StageEnd() IStageEndContext + + // IsStageCommandContext differentiates from other interfaces. + IsStageCommandContext() +} + +type StageCommandContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageCommandContext() *StageCommandContext { + var p = new(StageCommandContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_stageCommand + return p +} + +func InitEmptyStageCommandContext(p *StageCommandContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_stageCommand +} + +func (*StageCommandContext) IsStageCommandContext() {} + +func NewStageCommandContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageCommandContext { + var p = new(StageCommandContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_stageCommand + + return p +} + +func (s *StageCommandContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageCommandContext) Command() ICommandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ICommandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ICommandContext) +} + +func (s *StageCommandContext) StageEnd() IStageEndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStageEndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStageEndContext) +} + +func (s *StageCommandContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageCommandContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageCommandContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitStageCommand(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) StageCommand() (localctx IStageCommandContext) { + localctx = NewStageCommandContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 0, SPL1ParserRULE_stageCommand) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(154) + p.Command() + } + { + p.SetState(155) + p.StageEnd() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IStageSearchContext is an interface to support dynamic dispatch. +type IStageSearchContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchExpr() ISearchExprContext + StageEnd() IStageEndContext + + // IsStageSearchContext differentiates from other interfaces. + IsStageSearchContext() +} + +type StageSearchContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageSearchContext() *StageSearchContext { + var p = new(StageSearchContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_stageSearch + return p +} + +func InitEmptyStageSearchContext(p *StageSearchContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_stageSearch +} + +func (*StageSearchContext) IsStageSearchContext() {} + +func NewStageSearchContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageSearchContext { + var p = new(StageSearchContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_stageSearch + + return p +} + +func (s *StageSearchContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageSearchContext) SearchExpr() ISearchExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchExprContext) +} + +func (s *StageSearchContext) StageEnd() IStageEndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStageEndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStageEndContext) +} + +func (s *StageSearchContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageSearchContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageSearchContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitStageSearch(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) StageSearch() (localctx IStageSearchContext) { + localctx = NewStageSearchContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 2, SPL1ParserRULE_stageSearch) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(157) + p.SearchExpr() + } + { + p.SetState(158) + p.StageEnd() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IStageEndContext is an interface to support dynamic dispatch. +type IStageEndContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + PIPE() antlr.TerminalNode + EOF() antlr.TerminalNode + + // IsStageEndContext differentiates from other interfaces. + IsStageEndContext() +} + +type StageEndContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageEndContext() *StageEndContext { + var p = new(StageEndContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_stageEnd + return p +} + +func InitEmptyStageEndContext(p *StageEndContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_stageEnd +} + +func (*StageEndContext) IsStageEndContext() {} + +func NewStageEndContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageEndContext { + var p = new(StageEndContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_stageEnd + + return p +} + +func (s *StageEndContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageEndContext) PIPE() antlr.TerminalNode { + return s.GetToken(SPL1ParserPIPE, 0) +} + +func (s *StageEndContext) EOF() antlr.TerminalNode { + return s.GetToken(SPL1ParserEOF, 0) +} + +func (s *StageEndContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageEndContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageEndContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitStageEnd(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) StageEnd() (localctx IStageEndContext) { + localctx = NewStageEndContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 4, SPL1ParserRULE_stageEnd) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(160) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL1ParserEOF || _la == SPL1ParserPIPE) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ICommandContext is an interface to support dynamic dispatch. +type ICommandContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsCommandContext differentiates from other interfaces. + IsCommandContext() +} + +type CommandContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyCommandContext() *CommandContext { + var p = new(CommandContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_command + return p +} + +func InitEmptyCommandContext(p *CommandContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_command +} + +func (*CommandContext) IsCommandContext() {} + +func NewCommandContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *CommandContext { + var p = new(CommandContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_command + + return p +} + +func (s *CommandContext) GetParser() antlr.Parser { return s.parser } + +func (s *CommandContext) CopyAll(ctx *CommandContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *CommandContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CommandContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type CmdFieldsContext struct { + CommandContext +} + +func NewCmdFieldsContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdFieldsContext { + var p = new(CmdFieldsContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdFieldsContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdFieldsContext) FIELDS() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELDS, 0) +} + +func (s *CmdFieldsContext) FieldsSign() IFieldsSignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFieldsSignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IFieldsSignContext) +} + +func (s *CmdFieldsContext) AllFieldsItem() []IFieldsItemContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IFieldsItemContext); ok { + len++ + } + } + + tst := make([]IFieldsItemContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IFieldsItemContext); ok { + tst[i] = t.(IFieldsItemContext) + i++ + } + } + + return tst +} + +func (s *CmdFieldsContext) FieldsItem(i int) IFieldsItemContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFieldsItemContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IFieldsItemContext) +} + +func (s *CmdFieldsContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdFields(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdEvalContext struct { + CommandContext +} + +func NewCmdEvalContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdEvalContext { + var p = new(CmdEvalContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdEvalContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdEvalContext) EVAL() antlr.TerminalNode { + return s.GetToken(SPL1ParserEVAL, 0) +} + +func (s *CmdEvalContext) AllAssignment() []IAssignmentContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IAssignmentContext); ok { + len++ + } + } + + tst := make([]IAssignmentContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IAssignmentContext); ok { + tst[i] = t.(IAssignmentContext) + i++ + } + } + + return tst +} + +func (s *CmdEvalContext) Assignment(i int) IAssignmentContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAssignmentContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IAssignmentContext) +} + +func (s *CmdEvalContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserCOMMA) +} + +func (s *CmdEvalContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, i) +} + +func (s *CmdEvalContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdEval(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdSortContext struct { + CommandContext +} + +func NewCmdSortContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdSortContext { + var p = new(CmdSortContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdSortContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdSortContext) SORT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSORT, 0) +} + +func (s *CmdSortContext) SortBody() ISortBodyContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISortBodyContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISortBodyContext) +} + +func (s *CmdSortContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdSort(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdTableContext struct { + CommandContext +} + +func NewCmdTableContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdTableContext { + var p = new(CmdTableContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdTableContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdTableContext) TABLE() antlr.TerminalNode { + return s.GetToken(SPL1ParserTABLE, 0) +} + +func (s *CmdTableContext) AllTableItem() []ITableItemContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ITableItemContext); ok { + len++ + } + } + + tst := make([]ITableItemContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ITableItemContext); ok { + tst[i] = t.(ITableItemContext) + i++ + } + } + + return tst +} + +func (s *CmdTableContext) TableItem(i int) ITableItemContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ITableItemContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ITableItemContext) +} + +func (s *CmdTableContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdTable(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdSearchContext struct { + CommandContext +} + +func NewCmdSearchContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdSearchContext { + var p = new(CmdSearchContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdSearchContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdSearchContext) SEARCH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSEARCH, 0) +} + +func (s *CmdSearchContext) SearchExpr() ISearchExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchExprContext) +} + +func (s *CmdSearchContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdSearch(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdTimechartContext struct { + CommandContext +} + +func NewCmdTimechartContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdTimechartContext { + var p = new(CmdTimechartContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdTimechartContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdTimechartContext) TIMECHART() antlr.TerminalNode { + return s.GetToken(SPL1ParserTIMECHART, 0) +} + +func (s *CmdTimechartContext) TimechartBody() ITimechartBodyContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ITimechartBodyContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ITimechartBodyContext) +} + +func (s *CmdTimechartContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdTimechart(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdStatsContext struct { + CommandContext +} + +func NewCmdStatsContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdStatsContext { + var p = new(CmdStatsContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdStatsContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdStatsContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTATS, 0) +} + +func (s *CmdStatsContext) AggList() IAggListContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggListContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAggListContext) +} + +func (s *CmdStatsContext) ByClause() IByClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IByClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IByClauseContext) +} + +func (s *CmdStatsContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdStats(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdWhereContext struct { + CommandContext +} + +func NewCmdWhereContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdWhereContext { + var p = new(CmdWhereContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdWhereContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdWhereContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL1ParserWHERE, 0) +} + +func (s *CmdWhereContext) ValueExpr() IValueExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueExprContext) +} + +func (s *CmdWhereContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdWhere(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdRexContext struct { + CommandContext +} + +func NewCmdRexContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdRexContext { + var p = new(CmdRexContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdRexContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdRexContext) REX() antlr.TerminalNode { + return s.GetToken(SPL1ParserREX, 0) +} + +func (s *CmdRexContext) STRING() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTRING, 0) +} + +func (s *CmdRexContext) RexField() IRexFieldContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IRexFieldContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IRexFieldContext) +} + +func (s *CmdRexContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdRex(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdBinContext struct { + CommandContext +} + +func NewCmdBinContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdBinContext { + var p = new(CmdBinContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdBinContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdBinContext) BIN() antlr.TerminalNode { + return s.GetToken(SPL1ParserBIN, 0) +} + +func (s *CmdBinContext) AllBinItem() []IBinItemContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IBinItemContext); ok { + len++ + } + } + + tst := make([]IBinItemContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IBinItemContext); ok { + tst[i] = t.(IBinItemContext) + i++ + } + } + + return tst +} + +func (s *CmdBinContext) BinItem(i int) IBinItemContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IBinItemContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IBinItemContext) +} + +func (s *CmdBinContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdBin(s) + + default: + return t.VisitChildren(s) + } +} + +type CmdHeadContext struct { + CommandContext +} + +func NewCmdHeadContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *CmdHeadContext { + var p = new(CmdHeadContext) + + InitEmptyCommandContext(&p.CommandContext) + p.parser = parser + p.CopyAll(ctx.(*CommandContext)) + + return p +} + +func (s *CmdHeadContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CmdHeadContext) HEAD() antlr.TerminalNode { + return s.GetToken(SPL1ParserHEAD, 0) +} + +func (s *CmdHeadContext) LimitArg() ILimitArgContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ILimitArgContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ILimitArgContext) +} + +func (s *CmdHeadContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitCmdHead(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Command() (localctx ICommandContext) { + localctx = NewCommandContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 6, SPL1ParserRULE_command) + var _la int + + var _alt int + + p.SetState(221) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH: + localctx = NewCmdSearchContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(162) + p.Match(SPL1ParserSEARCH) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(164) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 0, p.GetParserRuleContext()) == 1 { + { + p.SetState(163) + p.SearchExpr() + } + + } else if p.HasError() { // JIM + goto errorExit + } + + case SPL1ParserWHERE: + localctx = NewCmdWhereContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(166) + p.Match(SPL1ParserWHERE) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(168) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 1, p.GetParserRuleContext()) == 1 { + { + p.SetState(167) + p.ValueExpr() + } + + } else if p.HasError() { // JIM + goto errorExit + } + + case SPL1ParserSTATS: + localctx = NewCmdStatsContext(p, localctx) + p.EnterOuterAlt(localctx, 3) + { + p.SetState(170) + p.Match(SPL1ParserSTATS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(171) + p.AggList() + } + p.SetState(173) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserBY { + { + p.SetState(172) + p.ByClause() + } + + } + + case SPL1ParserTIMECHART: + localctx = NewCmdTimechartContext(p, localctx) + p.EnterOuterAlt(localctx, 4) + { + p.SetState(175) + p.Match(SPL1ParserTIMECHART) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(176) + p.TimechartBody() + } + + case SPL1ParserEVAL: + localctx = NewCmdEvalContext(p, localctx) + p.EnterOuterAlt(localctx, 5) + { + p.SetState(177) + p.Match(SPL1ParserEVAL) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(178) + p.Assignment() + } + p.SetState(183) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL1ParserCOMMA { + { + p.SetState(179) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(180) + p.Assignment() + } + + p.SetState(185) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + case SPL1ParserREX: + localctx = NewCmdRexContext(p, localctx) + p.EnterOuterAlt(localctx, 6) + { + p.SetState(186) + p.Match(SPL1ParserREX) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(188) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) == 1 { + { + p.SetState(187) + p.RexField() + } + + } else if p.HasError() { // JIM + goto errorExit + } + { + p.SetState(190) + p.Match(SPL1ParserSTRING) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserTABLE: + localctx = NewCmdTableContext(p, localctx) + p.EnterOuterAlt(localctx, 7) + { + p.SetState(191) + p.Match(SPL1ParserTABLE) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(195) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&2041801692151806) != 0 { + { + p.SetState(192) + p.TableItem() + } + + p.SetState(197) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + case SPL1ParserFIELDS: + localctx = NewCmdFieldsContext(p, localctx) + p.EnterOuterAlt(localctx, 8) + { + p.SetState(198) + p.Match(SPL1ParserFIELDS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(200) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&141562122076160) != 0 { + { + p.SetState(199) + p.FieldsSign() + } + + } + p.SetState(205) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1125908506214398) != 0 { + { + p.SetState(202) + p.FieldsItem() + } + + p.SetState(207) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + case SPL1ParserSORT: + localctx = NewCmdSortContext(p, localctx) + p.EnterOuterAlt(localctx, 9) + { + p.SetState(208) + p.Match(SPL1ParserSORT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(209) + p.SortBody() + } + + case SPL1ParserHEAD: + localctx = NewCmdHeadContext(p, localctx) + p.EnterOuterAlt(localctx, 10) + { + p.SetState(210) + p.Match(SPL1ParserHEAD) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(212) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 8, p.GetParserRuleContext()) == 1 { + { + p.SetState(211) + p.LimitArg() + } + + } else if p.HasError() { // JIM + goto errorExit + } + + case SPL1ParserBIN: + localctx = NewCmdBinContext(p, localctx) + p.EnterOuterAlt(localctx, 11) + { + p.SetState(214) + p.Match(SPL1ParserBIN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(218) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(215) + p.BinItem() + } + + } + p.SetState(220) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchExprContext is an interface to support dynamic dispatch. +type ISearchExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchAnd() ISearchAndContext + AllSearchOrTail() []ISearchOrTailContext + SearchOrTail(i int) ISearchOrTailContext + + // IsSearchExprContext differentiates from other interfaces. + IsSearchExprContext() +} + +type SearchExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchExprContext() *SearchExprContext { + var p = new(SearchExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchExpr + return p +} + +func InitEmptySearchExprContext(p *SearchExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchExpr +} + +func (*SearchExprContext) IsSearchExprContext() {} + +func NewSearchExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchExprContext { + var p = new(SearchExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchExpr + + return p +} + +func (s *SearchExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchExprContext) SearchAnd() ISearchAndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchAndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchAndContext) +} + +func (s *SearchExprContext) AllSearchOrTail() []ISearchOrTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchOrTailContext); ok { + len++ + } + } + + tst := make([]ISearchOrTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchOrTailContext); ok { + tst[i] = t.(ISearchOrTailContext) + i++ + } + } + + return tst +} + +func (s *SearchExprContext) SearchOrTail(i int) ISearchOrTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchOrTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchOrTailContext) +} + +func (s *SearchExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchExpr() (localctx ISearchExprContext) { + localctx = NewSearchExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 8, SPL1ParserRULE_searchExpr) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(223) + p.SearchAnd() + } + p.SetState(227) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 11, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(224) + p.SearchOrTail() + } + + } + p.SetState(229) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 11, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchOrTailContext is an interface to support dynamic dispatch. +type ISearchOrTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + OR() antlr.TerminalNode + SearchAnd() ISearchAndContext + AbsentOperand() IAbsentOperandContext + + // IsSearchOrTailContext differentiates from other interfaces. + IsSearchOrTailContext() +} + +type SearchOrTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchOrTailContext() *SearchOrTailContext { + var p = new(SearchOrTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOrTail + return p +} + +func InitEmptySearchOrTailContext(p *SearchOrTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOrTail +} + +func (*SearchOrTailContext) IsSearchOrTailContext() {} + +func NewSearchOrTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchOrTailContext { + var p = new(SearchOrTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchOrTail + + return p +} + +func (s *SearchOrTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchOrTailContext) OR() antlr.TerminalNode { + return s.GetToken(SPL1ParserOR, 0) +} + +func (s *SearchOrTailContext) SearchAnd() ISearchAndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchAndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchAndContext) +} + +func (s *SearchOrTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SearchOrTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchOrTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchOrTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchOrTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchOrTail() (localctx ISearchOrTailContext) { + localctx = NewSearchOrTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 10, SPL1ParserRULE_searchOrTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(230) + + if !(p.at(SPL1ParserOR)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserOR)", "")) + goto errorExit + } + { + p.SetState(231) + p.Match(SPL1ParserOR) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(234) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 12, p.GetParserRuleContext()) { + case 1: + { + p.SetState(232) + p.SearchAnd() + } + + case 2: + { + p.SetState(233) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchAndContext is an interface to support dynamic dispatch. +type ISearchAndContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchNot() ISearchNotContext + AllSearchAndPart() []ISearchAndPartContext + SearchAndPart(i int) ISearchAndPartContext + + // IsSearchAndContext differentiates from other interfaces. + IsSearchAndContext() +} + +type SearchAndContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchAndContext() *SearchAndContext { + var p = new(SearchAndContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAnd + return p +} + +func InitEmptySearchAndContext(p *SearchAndContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAnd +} + +func (*SearchAndContext) IsSearchAndContext() {} + +func NewSearchAndContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchAndContext { + var p = new(SearchAndContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchAnd + + return p +} + +func (s *SearchAndContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchAndContext) SearchNot() ISearchNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchNotContext) +} + +func (s *SearchAndContext) AllSearchAndPart() []ISearchAndPartContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchAndPartContext); ok { + len++ + } + } + + tst := make([]ISearchAndPartContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchAndPartContext); ok { + tst[i] = t.(ISearchAndPartContext) + i++ + } + } + + return tst +} + +func (s *SearchAndContext) SearchAndPart(i int) ISearchAndPartContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchAndPartContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchAndPartContext) +} + +func (s *SearchAndContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchAndContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchAndContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchAnd(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchAnd() (localctx ISearchAndContext) { + localctx = NewSearchAndContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 12, SPL1ParserRULE_searchAnd) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(236) + p.SearchNot() + } + p.SetState(240) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 13, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(237) + p.SearchAndPart() + } + + } + p.SetState(242) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 13, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchAndPartContext is an interface to support dynamic dispatch. +type ISearchAndPartContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsSearchAndPartContext differentiates from other interfaces. + IsSearchAndPartContext() +} + +type SearchAndPartContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchAndPartContext() *SearchAndPartContext { + var p = new(SearchAndPartContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAndPart + return p +} + +func InitEmptySearchAndPartContext(p *SearchAndPartContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAndPart +} + +func (*SearchAndPartContext) IsSearchAndPartContext() {} + +func NewSearchAndPartContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchAndPartContext { + var p = new(SearchAndPartContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchAndPart + + return p +} + +func (s *SearchAndPartContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchAndPartContext) CopyAll(ctx *SearchAndPartContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *SearchAndPartContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchAndPartContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type SAndExplicitContext struct { + SearchAndPartContext +} + +func NewSAndExplicitContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SAndExplicitContext { + var p = new(SAndExplicitContext) + + InitEmptySearchAndPartContext(&p.SearchAndPartContext) + p.parser = parser + p.CopyAll(ctx.(*SearchAndPartContext)) + + return p +} + +func (s *SAndExplicitContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SAndExplicitContext) AND() antlr.TerminalNode { + return s.GetToken(SPL1ParserAND, 0) +} + +func (s *SAndExplicitContext) SearchNot() ISearchNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchNotContext) +} + +func (s *SAndExplicitContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SAndExplicitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSAndExplicit(s) + + default: + return t.VisitChildren(s) + } +} + +type SAndImplicitContext struct { + SearchAndPartContext +} + +func NewSAndImplicitContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SAndImplicitContext { + var p = new(SAndImplicitContext) + + InitEmptySearchAndPartContext(&p.SearchAndPartContext) + p.parser = parser + p.CopyAll(ctx.(*SearchAndPartContext)) + + return p +} + +func (s *SAndImplicitContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SAndImplicitContext) SearchNot() ISearchNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchNotContext) +} + +func (s *SAndImplicitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSAndImplicit(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchAndPart() (localctx ISearchAndPartContext) { + localctx = NewSearchAndPartContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 14, SPL1ParserRULE_searchAndPart) + p.SetState(251) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 15, p.GetParserRuleContext()) { + case 1: + localctx = NewSAndExplicitContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + p.SetState(243) + + if !(p.at(SPL1ParserAND)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserAND)", "")) + goto errorExit + } + { + p.SetState(244) + p.Match(SPL1ParserAND) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(247) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 14, p.GetParserRuleContext()) { + case 1: + { + p.SetState(245) + p.SearchNot() + } + + case 2: + { + p.SetState(246) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + localctx = NewSAndImplicitContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + p.SetState(249) + + if !(p.startsTerm()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.startsTerm()", "")) + goto errorExit + } + { + p.SetState(250) + p.SearchNot() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchNotContext is an interface to support dynamic dispatch. +type ISearchNotContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsSearchNotContext differentiates from other interfaces. + IsSearchNotContext() +} + +type SearchNotContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchNotContext() *SearchNotContext { + var p = new(SearchNotContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchNot + return p +} + +func InitEmptySearchNotContext(p *SearchNotContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchNot +} + +func (*SearchNotContext) IsSearchNotContext() {} + +func NewSearchNotContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchNotContext { + var p = new(SearchNotContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchNot + + return p +} + +func (s *SearchNotContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchNotContext) CopyAll(ctx *SearchNotContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *SearchNotContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchNotContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type SNotPrimaryContext struct { + SearchNotContext +} + +func NewSNotPrimaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SNotPrimaryContext { + var p = new(SNotPrimaryContext) + + InitEmptySearchNotContext(&p.SearchNotContext) + p.parser = parser + p.CopyAll(ctx.(*SearchNotContext)) + + return p +} + +func (s *SNotPrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SNotPrimaryContext) SearchComparison() ISearchComparisonContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchComparisonContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchComparisonContext) +} + +func (s *SNotPrimaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSNotPrimary(s) + + default: + return t.VisitChildren(s) + } +} + +type SNotUnaryContext struct { + SearchNotContext +} + +func NewSNotUnaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SNotUnaryContext { + var p = new(SNotUnaryContext) + + InitEmptySearchNotContext(&p.SearchNotContext) + p.parser = parser + p.CopyAll(ctx.(*SearchNotContext)) + + return p +} + +func (s *SNotUnaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SNotUnaryContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT, 0) +} + +func (s *SNotUnaryContext) BANG() antlr.TerminalNode { + return s.GetToken(SPL1ParserBANG, 0) +} + +func (s *SNotUnaryContext) SearchNot() ISearchNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchNotContext) +} + +func (s *SNotUnaryContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SNotUnaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSNotUnary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchNot() (localctx ISearchNotContext) { + localctx = NewSearchNotContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 16, SPL1ParserRULE_searchNot) + var _la int + + p.SetState(259) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 17, p.GetParserRuleContext()) { + case 1: + localctx = NewSNotUnaryContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(253) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL1ParserNOT || _la == SPL1ParserBANG) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + p.SetState(256) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 16, p.GetParserRuleContext()) { + case 1: + { + p.SetState(254) + p.SearchNot() + } + + case 2: + { + p.SetState(255) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + localctx = NewSNotPrimaryContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(258) + p.SearchComparison() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchComparisonContext is an interface to support dynamic dispatch. +type ISearchComparisonContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchAdditive() ISearchAdditiveContext + AllSearchComparisonTail() []ISearchComparisonTailContext + SearchComparisonTail(i int) ISearchComparisonTailContext + + // IsSearchComparisonContext differentiates from other interfaces. + IsSearchComparisonContext() +} + +type SearchComparisonContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchComparisonContext() *SearchComparisonContext { + var p = new(SearchComparisonContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchComparison + return p +} + +func InitEmptySearchComparisonContext(p *SearchComparisonContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchComparison +} + +func (*SearchComparisonContext) IsSearchComparisonContext() {} + +func NewSearchComparisonContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchComparisonContext { + var p = new(SearchComparisonContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchComparison + + return p +} + +func (s *SearchComparisonContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchComparisonContext) SearchAdditive() ISearchAdditiveContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchAdditiveContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchAdditiveContext) +} + +func (s *SearchComparisonContext) AllSearchComparisonTail() []ISearchComparisonTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchComparisonTailContext); ok { + len++ + } + } + + tst := make([]ISearchComparisonTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchComparisonTailContext); ok { + tst[i] = t.(ISearchComparisonTailContext) + i++ + } + } + + return tst +} + +func (s *SearchComparisonContext) SearchComparisonTail(i int) ISearchComparisonTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchComparisonTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchComparisonTailContext) +} + +func (s *SearchComparisonContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchComparisonContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchComparisonContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchComparison(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchComparison() (localctx ISearchComparisonContext) { + localctx = NewSearchComparisonContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 18, SPL1ParserRULE_searchComparison) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(261) + p.SearchAdditive() + } + p.SetState(265) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 18, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(262) + p.SearchComparisonTail() + } + + } + p.SetState(267) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 18, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchComparisonTailContext is an interface to support dynamic dispatch. +type ISearchComparisonTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ComparisonOp() IComparisonOpContext + SearchOperand() ISearchOperandContext + AbsentOperand() IAbsentOperandContext + + // IsSearchComparisonTailContext differentiates from other interfaces. + IsSearchComparisonTailContext() +} + +type SearchComparisonTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchComparisonTailContext() *SearchComparisonTailContext { + var p = new(SearchComparisonTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchComparisonTail + return p +} + +func InitEmptySearchComparisonTailContext(p *SearchComparisonTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchComparisonTail +} + +func (*SearchComparisonTailContext) IsSearchComparisonTailContext() {} + +func NewSearchComparisonTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchComparisonTailContext { + var p = new(SearchComparisonTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchComparisonTail + + return p +} + +func (s *SearchComparisonTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchComparisonTailContext) ComparisonOp() IComparisonOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IComparisonOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IComparisonOpContext) +} + +func (s *SearchComparisonTailContext) SearchOperand() ISearchOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchOperandContext) +} + +func (s *SearchComparisonTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SearchComparisonTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchComparisonTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchComparisonTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchComparisonTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchComparisonTail() (localctx ISearchComparisonTailContext) { + localctx = NewSearchComparisonTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 20, SPL1ParserRULE_searchComparisonTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(268) + + if !(p.atCompare()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atCompare()", "")) + goto errorExit + } + { + p.SetState(269) + p.ComparisonOp() + } + p.SetState(272) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserDURATION, SPL1ParserNUMBER, SPL1ParserSTRING, SPL1ParserIDENT, SPL1ParserLPAREN, SPL1ParserLBRACKET, SPL1ParserPLUS, SPL1ParserMINUS, SPL1ParserSTAR, SPL1ParserNUMBER_TIGHT, SPL1ParserSTAR_TIGHT, SPL1ParserMINUS_TIGHT, SPL1ParserNOT_WORD: + { + p.SetState(270) + p.SearchOperand() + } + + case SPL1ParserEOF, SPL1ParserEQ2, SPL1ParserNE, SPL1ParserLE, SPL1ParserGE, SPL1ParserEQ, SPL1ParserLT, SPL1ParserGT, SPL1ParserPIPE, SPL1ParserCOMMA, SPL1ParserRPAREN, SPL1ParserRBRACKET: + { + p.SetState(271) + p.AbsentOperand() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchOperandContext is an interface to support dynamic dispatch. +type ISearchOperandContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsSearchOperandContext differentiates from other interfaces. + IsSearchOperandContext() +} + +type SearchOperandContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchOperandContext() *SearchOperandContext { + var p = new(SearchOperandContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperand + return p +} + +func InitEmptySearchOperandContext(p *SearchOperandContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperand +} + +func (*SearchOperandContext) IsSearchOperandContext() {} + +func NewSearchOperandContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchOperandContext { + var p = new(SearchOperandContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchOperand + + return p +} + +func (s *SearchOperandContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchOperandContext) CopyAll(ctx *SearchOperandContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *SearchOperandContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchOperandContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type SOpStringContext struct { + SearchOperandContext +} + +func NewSOpStringContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SOpStringContext { + var p = new(SOpStringContext) + + InitEmptySearchOperandContext(&p.SearchOperandContext) + p.parser = parser + p.CopyAll(ctx.(*SearchOperandContext)) + + return p +} + +func (s *SOpStringContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SOpStringContext) STRING() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTRING, 0) +} + +func (s *SOpStringContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSOpString(s) + + default: + return t.VisitChildren(s) + } +} + +type SOpExprContext struct { + SearchOperandContext +} + +func NewSOpExprContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SOpExprContext { + var p = new(SOpExprContext) + + InitEmptySearchOperandContext(&p.SearchOperandContext) + p.parser = parser + p.CopyAll(ctx.(*SearchOperandContext)) + + return p +} + +func (s *SOpExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SOpExprContext) SearchOperandExpr() ISearchOperandExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchOperandExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchOperandExprContext) +} + +func (s *SOpExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSOpExpr(s) + + default: + return t.VisitChildren(s) + } +} + +type SOpValueContext struct { + SearchOperandContext +} + +func NewSOpValueContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SOpValueContext { + var p = new(SOpValueContext) + + InitEmptySearchOperandContext(&p.SearchOperandContext) + p.parser = parser + p.CopyAll(ctx.(*SearchOperandContext)) + + return p +} + +func (s *SOpValueContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SOpValueContext) SearchOperandValue() ISearchOperandValueContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchOperandValueContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchOperandValueContext) +} + +func (s *SOpValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSOpValue(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchOperand() (localctx ISearchOperandContext) { + localctx = NewSearchOperandContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 22, SPL1ParserRULE_searchOperand) + p.SetState(277) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSTRING: + localctx = NewSOpStringContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(274) + p.Match(SPL1ParserSTRING) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNUMBER_TIGHT, SPL1ParserSTAR_TIGHT, SPL1ParserMINUS_TIGHT, SPL1ParserNOT_WORD: + localctx = NewSOpValueContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(275) + p.SearchOperandValue() + } + + case SPL1ParserDURATION, SPL1ParserNUMBER, SPL1ParserLPAREN, SPL1ParserLBRACKET, SPL1ParserPLUS, SPL1ParserMINUS, SPL1ParserSTAR: + localctx = NewSOpExprContext(p, localctx) + p.EnterOuterAlt(localctx, 3) + { + p.SetState(276) + p.SearchOperandExpr() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchOperandValueContext is an interface to support dynamic dispatch. +type ISearchOperandValueContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + AllRhsTail() []IRhsTailContext + RhsTail(i int) IRhsTailContext + NUMBER_TIGHT() antlr.TerminalNode + STAR_TIGHT() antlr.TerminalNode + Number() INumberContext + Minus() IMinusContext + Star() IStarContext + MINUS_TIGHT() antlr.TerminalNode + + // IsSearchOperandValueContext differentiates from other interfaces. + IsSearchOperandValueContext() +} + +type SearchOperandValueContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchOperandValueContext() *SearchOperandValueContext { + var p = new(SearchOperandValueContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandValue + return p +} + +func InitEmptySearchOperandValueContext(p *SearchOperandValueContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandValue +} + +func (*SearchOperandValueContext) IsSearchOperandValueContext() {} + +func NewSearchOperandValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchOperandValueContext { + var p = new(SearchOperandValueContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchOperandValue + + return p +} + +func (s *SearchOperandValueContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchOperandValueContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *SearchOperandValueContext) AllRhsTail() []IRhsTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IRhsTailContext); ok { + len++ + } + } + + tst := make([]IRhsTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IRhsTailContext); ok { + tst[i] = t.(IRhsTailContext) + i++ + } + } + + return tst +} + +func (s *SearchOperandValueContext) RhsTail(i int) IRhsTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IRhsTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IRhsTailContext) +} + +func (s *SearchOperandValueContext) NUMBER_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNUMBER_TIGHT, 0) +} + +func (s *SearchOperandValueContext) STAR_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_TIGHT, 0) +} + +func (s *SearchOperandValueContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *SearchOperandValueContext) Minus() IMinusContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMinusContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMinusContext) +} + +func (s *SearchOperandValueContext) Star() IStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStarContext) +} + +func (s *SearchOperandValueContext) MINUS_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserMINUS_TIGHT, 0) +} + +func (s *SearchOperandValueContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchOperandValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchOperandValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchOperandValue(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchOperandValue() (localctx ISearchOperandValueContext) { + localctx = NewSearchOperandValueContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 24, SPL1ParserRULE_searchOperandValue) + var _alt int + + p.SetState(321) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(279) + p.IdentLike() + } + p.SetState(283) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 21, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(280) + p.RhsTail() + } + + } + p.SetState(285) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 21, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + case SPL1ParserNUMBER_TIGHT: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(286) + p.Match(SPL1ParserNUMBER_TIGHT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(290) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 22, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(287) + p.RhsTail() + } + + } + p.SetState(292) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 22, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + case SPL1ParserSTAR_TIGHT: + p.EnterOuterAlt(localctx, 3) + { + p.SetState(293) + p.Match(SPL1ParserSTAR_TIGHT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(302) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + { + p.SetState(294) + p.IdentLike() + } + + case SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT: + { + p.SetState(295) + p.Number() + } + + case SPL1ParserMINUS, SPL1ParserMINUS_TIGHT: + { + p.SetState(296) + p.Minus() + } + p.SetState(300) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + { + p.SetState(297) + p.IdentLike() + } + + case SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT: + { + p.SetState(298) + p.Number() + } + + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP: + { + p.SetState(299) + p.Star() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + p.SetState(307) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 25, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(304) + p.RhsTail() + } + + } + p.SetState(309) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 25, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + case SPL1ParserMINUS_TIGHT: + p.EnterOuterAlt(localctx, 4) + { + p.SetState(310) + p.Match(SPL1ParserMINUS_TIGHT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(313) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + { + p.SetState(311) + p.IdentLike() + } + + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP: + { + p.SetState(312) + p.Star() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + p.SetState(318) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 27, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(315) + p.RhsTail() + } + + } + p.SetState(320) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 27, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IRhsTailContext is an interface to support dynamic dispatch. +type IRhsTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Star() IStarContext + IdentLike() IIdentLikeContext + Number() INumberContext + Minus() IMinusContext + + // IsRhsTailContext differentiates from other interfaces. + IsRhsTailContext() +} + +type RhsTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyRhsTailContext() *RhsTailContext { + var p = new(RhsTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_rhsTail + return p +} + +func InitEmptyRhsTailContext(p *RhsTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_rhsTail +} + +func (*RhsTailContext) IsRhsTailContext() {} + +func NewRhsTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RhsTailContext { + var p = new(RhsTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_rhsTail + + return p +} + +func (s *RhsTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *RhsTailContext) Star() IStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStarContext) +} + +func (s *RhsTailContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *RhsTailContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *RhsTailContext) Minus() IMinusContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMinusContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMinusContext) +} + +func (s *RhsTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *RhsTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *RhsTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitRhsTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) RhsTail() (localctx IRhsTailContext) { + localctx = NewRhsTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 26, SPL1ParserRULE_rhsTail) + p.SetState(336) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 30, p.GetParserRuleContext()) { + case 1: + p.EnterOuterAlt(localctx, 1) + p.SetState(323) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(324) + p.Star() + } + + case 2: + p.EnterOuterAlt(localctx, 2) + p.SetState(325) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(326) + p.IdentLike() + } + + case 3: + p.EnterOuterAlt(localctx, 3) + p.SetState(327) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(328) + p.Number() + } + + case 4: + p.EnterOuterAlt(localctx, 4) + p.SetState(329) + + if !(p.hyphenTail()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.hyphenTail()", "")) + goto errorExit + } + { + p.SetState(330) + p.Minus() + } + p.SetState(334) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + { + p.SetState(331) + p.IdentLike() + } + + case SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT: + { + p.SetState(332) + p.Number() + } + + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP: + { + p.SetState(333) + p.Star() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchOperandExprContext is an interface to support dynamic dispatch. +type ISearchOperandExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchOperandUnary() ISearchOperandUnaryContext + AllSearchMulTail() []ISearchMulTailContext + SearchMulTail(i int) ISearchMulTailContext + AllSearchAddTail() []ISearchAddTailContext + SearchAddTail(i int) ISearchAddTailContext + + // IsSearchOperandExprContext differentiates from other interfaces. + IsSearchOperandExprContext() +} + +type SearchOperandExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchOperandExprContext() *SearchOperandExprContext { + var p = new(SearchOperandExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandExpr + return p +} + +func InitEmptySearchOperandExprContext(p *SearchOperandExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandExpr +} + +func (*SearchOperandExprContext) IsSearchOperandExprContext() {} + +func NewSearchOperandExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchOperandExprContext { + var p = new(SearchOperandExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchOperandExpr + + return p +} + +func (s *SearchOperandExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchOperandExprContext) SearchOperandUnary() ISearchOperandUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchOperandUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchOperandUnaryContext) +} + +func (s *SearchOperandExprContext) AllSearchMulTail() []ISearchMulTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchMulTailContext); ok { + len++ + } + } + + tst := make([]ISearchMulTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchMulTailContext); ok { + tst[i] = t.(ISearchMulTailContext) + i++ + } + } + + return tst +} + +func (s *SearchOperandExprContext) SearchMulTail(i int) ISearchMulTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchMulTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchMulTailContext) +} + +func (s *SearchOperandExprContext) AllSearchAddTail() []ISearchAddTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchAddTailContext); ok { + len++ + } + } + + tst := make([]ISearchAddTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchAddTailContext); ok { + tst[i] = t.(ISearchAddTailContext) + i++ + } + } + + return tst +} + +func (s *SearchOperandExprContext) SearchAddTail(i int) ISearchAddTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchAddTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchAddTailContext) +} + +func (s *SearchOperandExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchOperandExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchOperandExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchOperandExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchOperandExpr() (localctx ISearchOperandExprContext) { + localctx = NewSearchOperandExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 28, SPL1ParserRULE_searchOperandExpr) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(338) + p.SearchOperandUnary() + } + p.SetState(342) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 31, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(339) + p.SearchMulTail() + } + + } + p.SetState(344) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 31, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + p.SetState(348) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 32, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(345) + p.SearchAddTail() + } + + } + p.SetState(350) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 32, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchOperandUnaryContext is an interface to support dynamic dispatch. +type ISearchOperandUnaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + MINUS() antlr.TerminalNode + PLUS() antlr.TerminalNode + SearchUnary() ISearchUnaryContext + AbsentOperand() IAbsentOperandContext + SearchOperandPrimary() ISearchOperandPrimaryContext + + // IsSearchOperandUnaryContext differentiates from other interfaces. + IsSearchOperandUnaryContext() +} + +type SearchOperandUnaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchOperandUnaryContext() *SearchOperandUnaryContext { + var p = new(SearchOperandUnaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandUnary + return p +} + +func InitEmptySearchOperandUnaryContext(p *SearchOperandUnaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandUnary +} + +func (*SearchOperandUnaryContext) IsSearchOperandUnaryContext() {} + +func NewSearchOperandUnaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchOperandUnaryContext { + var p = new(SearchOperandUnaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchOperandUnary + + return p +} + +func (s *SearchOperandUnaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchOperandUnaryContext) MINUS() antlr.TerminalNode { + return s.GetToken(SPL1ParserMINUS, 0) +} + +func (s *SearchOperandUnaryContext) PLUS() antlr.TerminalNode { + return s.GetToken(SPL1ParserPLUS, 0) +} + +func (s *SearchOperandUnaryContext) SearchUnary() ISearchUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchUnaryContext) +} + +func (s *SearchOperandUnaryContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SearchOperandUnaryContext) SearchOperandPrimary() ISearchOperandPrimaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchOperandPrimaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchOperandPrimaryContext) +} + +func (s *SearchOperandUnaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchOperandUnaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchOperandUnaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchOperandUnary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchOperandUnary() (localctx ISearchOperandUnaryContext) { + localctx = NewSearchOperandUnaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 30, SPL1ParserRULE_searchOperandUnary) + var _la int + + p.SetState(357) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserPLUS, SPL1ParserMINUS: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(351) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL1ParserPLUS || _la == SPL1ParserMINUS) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + p.SetState(354) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 33, p.GetParserRuleContext()) { + case 1: + { + p.SetState(352) + p.SearchUnary() + } + + case 2: + { + p.SetState(353) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case SPL1ParserDURATION, SPL1ParserNUMBER, SPL1ParserLPAREN, SPL1ParserLBRACKET, SPL1ParserSTAR: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(356) + p.SearchOperandPrimary() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchOperandPrimaryContext is an interface to support dynamic dispatch. +type ISearchOperandPrimaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + LPAREN() antlr.TerminalNode + SearchExpr() ISearchExprContext + RPAREN() antlr.TerminalNode + DURATION() antlr.TerminalNode + NUMBER() antlr.TerminalNode + STAR() antlr.TerminalNode + Subsearch() ISubsearchContext + + // IsSearchOperandPrimaryContext differentiates from other interfaces. + IsSearchOperandPrimaryContext() +} + +type SearchOperandPrimaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchOperandPrimaryContext() *SearchOperandPrimaryContext { + var p = new(SearchOperandPrimaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandPrimary + return p +} + +func InitEmptySearchOperandPrimaryContext(p *SearchOperandPrimaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchOperandPrimary +} + +func (*SearchOperandPrimaryContext) IsSearchOperandPrimaryContext() {} + +func NewSearchOperandPrimaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchOperandPrimaryContext { + var p = new(SearchOperandPrimaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchOperandPrimary + + return p +} + +func (s *SearchOperandPrimaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchOperandPrimaryContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserLPAREN, 0) +} + +func (s *SearchOperandPrimaryContext) SearchExpr() ISearchExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchExprContext) +} + +func (s *SearchOperandPrimaryContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *SearchOperandPrimaryContext) DURATION() antlr.TerminalNode { + return s.GetToken(SPL1ParserDURATION, 0) +} + +func (s *SearchOperandPrimaryContext) NUMBER() antlr.TerminalNode { + return s.GetToken(SPL1ParserNUMBER, 0) +} + +func (s *SearchOperandPrimaryContext) STAR() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR, 0) +} + +func (s *SearchOperandPrimaryContext) Subsearch() ISubsearchContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISubsearchContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISubsearchContext) +} + +func (s *SearchOperandPrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchOperandPrimaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchOperandPrimaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchOperandPrimary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchOperandPrimary() (localctx ISearchOperandPrimaryContext) { + localctx = NewSearchOperandPrimaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 32, SPL1ParserRULE_searchOperandPrimary) + p.SetState(367) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserLPAREN: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(359) + p.Match(SPL1ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(360) + p.SearchExpr() + } + { + p.SetState(361) + p.Match(SPL1ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserDURATION: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(363) + p.Match(SPL1ParserDURATION) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserNUMBER: + p.EnterOuterAlt(localctx, 3) + { + p.SetState(364) + p.Match(SPL1ParserNUMBER) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserSTAR: + p.EnterOuterAlt(localctx, 4) + { + p.SetState(365) + p.Match(SPL1ParserSTAR) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserLBRACKET: + p.EnterOuterAlt(localctx, 5) + { + p.SetState(366) + p.Subsearch() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchAdditiveContext is an interface to support dynamic dispatch. +type ISearchAdditiveContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchMultiplicative() ISearchMultiplicativeContext + AllSearchAddTail() []ISearchAddTailContext + SearchAddTail(i int) ISearchAddTailContext + + // IsSearchAdditiveContext differentiates from other interfaces. + IsSearchAdditiveContext() +} + +type SearchAdditiveContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchAdditiveContext() *SearchAdditiveContext { + var p = new(SearchAdditiveContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAdditive + return p +} + +func InitEmptySearchAdditiveContext(p *SearchAdditiveContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAdditive +} + +func (*SearchAdditiveContext) IsSearchAdditiveContext() {} + +func NewSearchAdditiveContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchAdditiveContext { + var p = new(SearchAdditiveContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchAdditive + + return p +} + +func (s *SearchAdditiveContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchAdditiveContext) SearchMultiplicative() ISearchMultiplicativeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchMultiplicativeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchMultiplicativeContext) +} + +func (s *SearchAdditiveContext) AllSearchAddTail() []ISearchAddTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchAddTailContext); ok { + len++ + } + } + + tst := make([]ISearchAddTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchAddTailContext); ok { + tst[i] = t.(ISearchAddTailContext) + i++ + } + } + + return tst +} + +func (s *SearchAdditiveContext) SearchAddTail(i int) ISearchAddTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchAddTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchAddTailContext) +} + +func (s *SearchAdditiveContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchAdditiveContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchAdditiveContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchAdditive(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchAdditive() (localctx ISearchAdditiveContext) { + localctx = NewSearchAdditiveContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 34, SPL1ParserRULE_searchAdditive) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(369) + p.SearchMultiplicative() + } + p.SetState(373) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 36, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(370) + p.SearchAddTail() + } + + } + p.SetState(375) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 36, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchAddTailContext is an interface to support dynamic dispatch. +type ISearchAddTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AddOp() IAddOpContext + SearchMultiplicative() ISearchMultiplicativeContext + AbsentOperand() IAbsentOperandContext + + // IsSearchAddTailContext differentiates from other interfaces. + IsSearchAddTailContext() +} + +type SearchAddTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchAddTailContext() *SearchAddTailContext { + var p = new(SearchAddTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAddTail + return p +} + +func InitEmptySearchAddTailContext(p *SearchAddTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchAddTail +} + +func (*SearchAddTailContext) IsSearchAddTailContext() {} + +func NewSearchAddTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchAddTailContext { + var p = new(SearchAddTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchAddTail + + return p +} + +func (s *SearchAddTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchAddTailContext) AddOp() IAddOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAddOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAddOpContext) +} + +func (s *SearchAddTailContext) SearchMultiplicative() ISearchMultiplicativeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchMultiplicativeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchMultiplicativeContext) +} + +func (s *SearchAddTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SearchAddTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchAddTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchAddTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchAddTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchAddTail() (localctx ISearchAddTailContext) { + localctx = NewSearchAddTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 36, SPL1ParserRULE_searchAddTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(376) + + if !(p.atAdd()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atAdd()", "")) + goto errorExit + } + { + p.SetState(377) + p.AddOp() + } + p.SetState(380) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 37, p.GetParserRuleContext()) { + case 1: + { + p.SetState(378) + p.SearchMultiplicative() + } + + case 2: + { + p.SetState(379) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchMultiplicativeContext is an interface to support dynamic dispatch. +type ISearchMultiplicativeContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchUnary() ISearchUnaryContext + AllSearchMulTail() []ISearchMulTailContext + SearchMulTail(i int) ISearchMulTailContext + + // IsSearchMultiplicativeContext differentiates from other interfaces. + IsSearchMultiplicativeContext() +} + +type SearchMultiplicativeContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchMultiplicativeContext() *SearchMultiplicativeContext { + var p = new(SearchMultiplicativeContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchMultiplicative + return p +} + +func InitEmptySearchMultiplicativeContext(p *SearchMultiplicativeContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchMultiplicative +} + +func (*SearchMultiplicativeContext) IsSearchMultiplicativeContext() {} + +func NewSearchMultiplicativeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchMultiplicativeContext { + var p = new(SearchMultiplicativeContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchMultiplicative + + return p +} + +func (s *SearchMultiplicativeContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchMultiplicativeContext) SearchUnary() ISearchUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchUnaryContext) +} + +func (s *SearchMultiplicativeContext) AllSearchMulTail() []ISearchMulTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchMulTailContext); ok { + len++ + } + } + + tst := make([]ISearchMulTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchMulTailContext); ok { + tst[i] = t.(ISearchMulTailContext) + i++ + } + } + + return tst +} + +func (s *SearchMultiplicativeContext) SearchMulTail(i int) ISearchMulTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchMulTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchMulTailContext) +} + +func (s *SearchMultiplicativeContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchMultiplicativeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchMultiplicativeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchMultiplicative(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchMultiplicative() (localctx ISearchMultiplicativeContext) { + localctx = NewSearchMultiplicativeContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 38, SPL1ParserRULE_searchMultiplicative) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(382) + p.SearchUnary() + } + p.SetState(386) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 38, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(383) + p.SearchMulTail() + } + + } + p.SetState(388) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 38, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchMulTailContext is an interface to support dynamic dispatch. +type ISearchMulTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SearchMulOp() ISearchMulOpContext + SearchUnary() ISearchUnaryContext + AbsentOperand() IAbsentOperandContext + + // IsSearchMulTailContext differentiates from other interfaces. + IsSearchMulTailContext() +} + +type SearchMulTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchMulTailContext() *SearchMulTailContext { + var p = new(SearchMulTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchMulTail + return p +} + +func InitEmptySearchMulTailContext(p *SearchMulTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchMulTail +} + +func (*SearchMulTailContext) IsSearchMulTailContext() {} + +func NewSearchMulTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchMulTailContext { + var p = new(SearchMulTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchMulTail + + return p +} + +func (s *SearchMulTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchMulTailContext) SearchMulOp() ISearchMulOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchMulOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchMulOpContext) +} + +func (s *SearchMulTailContext) SearchUnary() ISearchUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchUnaryContext) +} + +func (s *SearchMulTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SearchMulTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchMulTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchMulTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchMulTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchMulTail() (localctx ISearchMulTailContext) { + localctx = NewSearchMulTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 40, SPL1ParserRULE_searchMulTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(389) + + if !(p.atSearchMul()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atSearchMul()", "")) + goto errorExit + } + { + p.SetState(390) + p.SearchMulOp() + } + p.SetState(393) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 39, p.GetParserRuleContext()) { + case 1: + { + p.SetState(391) + p.SearchUnary() + } + + case 2: + { + p.SetState(392) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchUnaryContext is an interface to support dynamic dispatch. +type ISearchUnaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsSearchUnaryContext differentiates from other interfaces. + IsSearchUnaryContext() +} + +type SearchUnaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchUnaryContext() *SearchUnaryContext { + var p = new(SearchUnaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchUnary + return p +} + +func InitEmptySearchUnaryContext(p *SearchUnaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchUnary +} + +func (*SearchUnaryContext) IsSearchUnaryContext() {} + +func NewSearchUnaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchUnaryContext { + var p = new(SearchUnaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchUnary + + return p +} + +func (s *SearchUnaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchUnaryContext) CopyAll(ctx *SearchUnaryContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *SearchUnaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchUnaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type SUnarySignContext struct { + SearchUnaryContext +} + +func NewSUnarySignContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SUnarySignContext { + var p = new(SUnarySignContext) + + InitEmptySearchUnaryContext(&p.SearchUnaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchUnaryContext)) + + return p +} + +func (s *SUnarySignContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SUnarySignContext) Sign() ISignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISignContext) +} + +func (s *SUnarySignContext) SearchUnary() ISearchUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchUnaryContext) +} + +func (s *SUnarySignContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *SUnarySignContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSUnarySign(s) + + default: + return t.VisitChildren(s) + } +} + +type SUnaryPrimaryContext struct { + SearchUnaryContext +} + +func NewSUnaryPrimaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SUnaryPrimaryContext { + var p = new(SUnaryPrimaryContext) + + InitEmptySearchUnaryContext(&p.SearchUnaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchUnaryContext)) + + return p +} + +func (s *SUnaryPrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SUnaryPrimaryContext) SearchPrimary() ISearchPrimaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchPrimaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchPrimaryContext) +} + +func (s *SUnaryPrimaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSUnaryPrimary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchUnary() (localctx ISearchUnaryContext) { + localctx = NewSearchUnaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 42, SPL1ParserRULE_searchUnary) + p.SetState(401) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 41, p.GetParserRuleContext()) { + case 1: + localctx = NewSUnarySignContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(395) + p.Sign() + } + p.SetState(398) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 40, p.GetParserRuleContext()) { + case 1: + { + p.SetState(396) + p.SearchUnary() + } + + case 2: + { + p.SetState(397) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + localctx = NewSUnaryPrimaryContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(400) + p.SearchPrimary() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchPrimaryContext is an interface to support dynamic dispatch. +type ISearchPrimaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsSearchPrimaryContext differentiates from other interfaces. + IsSearchPrimaryContext() +} + +type SearchPrimaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchPrimaryContext() *SearchPrimaryContext { + var p = new(SearchPrimaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchPrimary + return p +} + +func InitEmptySearchPrimaryContext(p *SearchPrimaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchPrimary +} + +func (*SearchPrimaryContext) IsSearchPrimaryContext() {} + +func NewSearchPrimaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchPrimaryContext { + var p = new(SearchPrimaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchPrimary + + return p +} + +func (s *SearchPrimaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchPrimaryContext) CopyAll(ctx *SearchPrimaryContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *SearchPrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchPrimaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type SPrimSubsearchContext struct { + SearchPrimaryContext +} + +func NewSPrimSubsearchContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimSubsearchContext { + var p = new(SPrimSubsearchContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimSubsearchContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimSubsearchContext) Subsearch() ISubsearchContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISubsearchContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISubsearchContext) +} + +func (s *SPrimSubsearchContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimSubsearch(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimNumberContext struct { + SearchPrimaryContext +} + +func NewSPrimNumberContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimNumberContext { + var p = new(SPrimNumberContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimNumberContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimNumberContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *SPrimNumberContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimNumber(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimStarContext struct { + SearchPrimaryContext +} + +func NewSPrimStarContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimStarContext { + var p = new(SPrimStarContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimStarContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimStarContext) OperandStar() IOperandStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IOperandStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IOperandStarContext) +} + +func (s *SPrimStarContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimStar(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimStringContext struct { + SearchPrimaryContext +} + +func NewSPrimStringContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimStringContext { + var p = new(SPrimStringContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimStringContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimStringContext) STRING() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTRING, 0) +} + +func (s *SPrimStringContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimString(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimWordContext struct { + SearchPrimaryContext +} + +func NewSPrimWordContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimWordContext { + var p = new(SPrimWordContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimWordContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimWordContext) ExprWord() IExprWordContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IExprWordContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IExprWordContext) +} + +func (s *SPrimWordContext) AllSearchTermTail() []ISearchTermTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchTermTailContext); ok { + len++ + } + } + + tst := make([]ISearchTermTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchTermTailContext); ok { + tst[i] = t.(ISearchTermTailContext) + i++ + } + } + + return tst +} + +func (s *SPrimWordContext) SearchTermTail(i int) ISearchTermTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchTermTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchTermTailContext) +} + +func (s *SPrimWordContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimWord(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimStarRunContext struct { + SearchPrimaryContext +} + +func NewSPrimStarRunContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimStarRunContext { + var p = new(SPrimStarRunContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimStarRunContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimStarRunContext) Star() IStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStarContext) +} + +func (s *SPrimStarRunContext) AllSearchTermTail() []ISearchTermTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISearchTermTailContext); ok { + len++ + } + } + + tst := make([]ISearchTermTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISearchTermTailContext); ok { + tst[i] = t.(ISearchTermTailContext) + i++ + } + } + + return tst +} + +func (s *SPrimStarRunContext) SearchTermTail(i int) ISearchTermTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchTermTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISearchTermTailContext) +} + +func (s *SPrimStarRunContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimStarRun(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimDurationContext struct { + SearchPrimaryContext +} + +func NewSPrimDurationContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimDurationContext { + var p = new(SPrimDurationContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimDurationContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimDurationContext) DURATION() antlr.TerminalNode { + return s.GetToken(SPL1ParserDURATION, 0) +} + +func (s *SPrimDurationContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimDuration(s) + + default: + return t.VisitChildren(s) + } +} + +type SPrimParenContext struct { + SearchPrimaryContext +} + +func NewSPrimParenContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SPrimParenContext { + var p = new(SPrimParenContext) + + InitEmptySearchPrimaryContext(&p.SearchPrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*SearchPrimaryContext)) + + return p +} + +func (s *SPrimParenContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SPrimParenContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserLPAREN, 0) +} + +func (s *SPrimParenContext) SearchExpr() ISearchExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISearchExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISearchExprContext) +} + +func (s *SPrimParenContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *SPrimParenContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSPrimParen(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchPrimary() (localctx ISearchPrimaryContext) { + localctx = NewSearchPrimaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 44, SPL1ParserRULE_searchPrimary) + var _alt int + + p.SetState(426) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 44, p.GetParserRuleContext()) { + case 1: + localctx = NewSPrimParenContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(403) + p.Match(SPL1ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(404) + p.SearchExpr() + } + { + p.SetState(405) + p.Match(SPL1ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 2: + localctx = NewSPrimStringContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(407) + p.Match(SPL1ParserSTRING) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 3: + localctx = NewSPrimWordContext(p, localctx) + p.EnterOuterAlt(localctx, 3) + { + p.SetState(408) + p.ExprWord() + } + p.SetState(412) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 42, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(409) + p.SearchTermTail() + } + + } + p.SetState(414) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 42, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + case 4: + localctx = NewSPrimNumberContext(p, localctx) + p.EnterOuterAlt(localctx, 4) + { + p.SetState(415) + p.Number() + } + + case 5: + localctx = NewSPrimDurationContext(p, localctx) + p.EnterOuterAlt(localctx, 5) + { + p.SetState(416) + p.Match(SPL1ParserDURATION) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 6: + localctx = NewSPrimStarRunContext(p, localctx) + p.EnterOuterAlt(localctx, 6) + p.SetState(417) + + if !(p.termStarRun()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.termStarRun()", "")) + goto errorExit + } + { + p.SetState(418) + p.Star() + } + p.SetState(420) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = 1 + for ok := true; ok; ok = _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + switch _alt { + case 1: + { + p.SetState(419) + p.SearchTermTail() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + + p.SetState(422) + p.GetErrorHandler().Sync(p) + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 43, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + + case 7: + localctx = NewSPrimStarContext(p, localctx) + p.EnterOuterAlt(localctx, 7) + { + p.SetState(424) + p.OperandStar() + } + + case 8: + localctx = NewSPrimSubsearchContext(p, localctx) + p.EnterOuterAlt(localctx, 8) + { + p.SetState(425) + p.Subsearch() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchTermTailContext is an interface to support dynamic dispatch. +type ISearchTermTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + STAR_TERM() antlr.TerminalNode + IdentLike() IIdentLikeContext + Number() INumberContext + + // IsSearchTermTailContext differentiates from other interfaces. + IsSearchTermTailContext() +} + +type SearchTermTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchTermTailContext() *SearchTermTailContext { + var p = new(SearchTermTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchTermTail + return p +} + +func InitEmptySearchTermTailContext(p *SearchTermTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchTermTail +} + +func (*SearchTermTailContext) IsSearchTermTailContext() {} + +func NewSearchTermTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchTermTailContext { + var p = new(SearchTermTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchTermTail + + return p +} + +func (s *SearchTermTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchTermTailContext) STAR_TERM() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_TERM, 0) +} + +func (s *SearchTermTailContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *SearchTermTailContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *SearchTermTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchTermTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchTermTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchTermTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchTermTail() (localctx ISearchTermTailContext) { + localctx = NewSearchTermTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 46, SPL1ParserRULE_searchTermTail) + p.SetState(434) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 45, p.GetParserRuleContext()) { + case 1: + p.EnterOuterAlt(localctx, 1) + p.SetState(428) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(429) + p.Match(SPL1ParserSTAR_TERM) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 2: + p.EnterOuterAlt(localctx, 2) + p.SetState(430) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(431) + p.IdentLike() + } + + case 3: + p.EnterOuterAlt(localctx, 3) + p.SetState(432) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(433) + p.Number() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueExprContext is an interface to support dynamic dispatch. +type IValueExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ValueAnd() IValueAndContext + AllValueOrTail() []IValueOrTailContext + ValueOrTail(i int) IValueOrTailContext + + // IsValueExprContext differentiates from other interfaces. + IsValueExprContext() +} + +type ValueExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueExprContext() *ValueExprContext { + var p = new(ValueExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueExpr + return p +} + +func InitEmptyValueExprContext(p *ValueExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueExpr +} + +func (*ValueExprContext) IsValueExprContext() {} + +func NewValueExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueExprContext { + var p = new(ValueExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueExpr + + return p +} + +func (s *ValueExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueExprContext) ValueAnd() IValueAndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueAndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueAndContext) +} + +func (s *ValueExprContext) AllValueOrTail() []IValueOrTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IValueOrTailContext); ok { + len++ + } + } + + tst := make([]IValueOrTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IValueOrTailContext); ok { + tst[i] = t.(IValueOrTailContext) + i++ + } + } + + return tst +} + +func (s *ValueExprContext) ValueOrTail(i int) IValueOrTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueOrTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IValueOrTailContext) +} + +func (s *ValueExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueExpr() (localctx IValueExprContext) { + localctx = NewValueExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 48, SPL1ParserRULE_valueExpr) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(436) + p.ValueAnd() + } + p.SetState(440) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 46, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(437) + p.ValueOrTail() + } + + } + p.SetState(442) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 46, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueOrTailContext is an interface to support dynamic dispatch. +type IValueOrTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + OR() antlr.TerminalNode + ValueAnd() IValueAndContext + AbsentOperand() IAbsentOperandContext + + // IsValueOrTailContext differentiates from other interfaces. + IsValueOrTailContext() +} + +type ValueOrTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueOrTailContext() *ValueOrTailContext { + var p = new(ValueOrTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueOrTail + return p +} + +func InitEmptyValueOrTailContext(p *ValueOrTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueOrTail +} + +func (*ValueOrTailContext) IsValueOrTailContext() {} + +func NewValueOrTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueOrTailContext { + var p = new(ValueOrTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueOrTail + + return p +} + +func (s *ValueOrTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueOrTailContext) OR() antlr.TerminalNode { + return s.GetToken(SPL1ParserOR, 0) +} + +func (s *ValueOrTailContext) ValueAnd() IValueAndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueAndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueAndContext) +} + +func (s *ValueOrTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *ValueOrTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueOrTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueOrTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueOrTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueOrTail() (localctx IValueOrTailContext) { + localctx = NewValueOrTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 50, SPL1ParserRULE_valueOrTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(443) + + if !(p.at(SPL1ParserOR)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserOR)", "")) + goto errorExit + } + { + p.SetState(444) + p.Match(SPL1ParserOR) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(447) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 47, p.GetParserRuleContext()) { + case 1: + { + p.SetState(445) + p.ValueAnd() + } + + case 2: + { + p.SetState(446) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueAndContext is an interface to support dynamic dispatch. +type IValueAndContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ValueNot() IValueNotContext + AllValueAndPart() []IValueAndPartContext + ValueAndPart(i int) IValueAndPartContext + + // IsValueAndContext differentiates from other interfaces. + IsValueAndContext() +} + +type ValueAndContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueAndContext() *ValueAndContext { + var p = new(ValueAndContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAnd + return p +} + +func InitEmptyValueAndContext(p *ValueAndContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAnd +} + +func (*ValueAndContext) IsValueAndContext() {} + +func NewValueAndContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueAndContext { + var p = new(ValueAndContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueAnd + + return p +} + +func (s *ValueAndContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueAndContext) ValueNot() IValueNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueNotContext) +} + +func (s *ValueAndContext) AllValueAndPart() []IValueAndPartContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IValueAndPartContext); ok { + len++ + } + } + + tst := make([]IValueAndPartContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IValueAndPartContext); ok { + tst[i] = t.(IValueAndPartContext) + i++ + } + } + + return tst +} + +func (s *ValueAndContext) ValueAndPart(i int) IValueAndPartContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueAndPartContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IValueAndPartContext) +} + +func (s *ValueAndContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueAndContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueAndContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueAnd(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueAnd() (localctx IValueAndContext) { + localctx = NewValueAndContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 52, SPL1ParserRULE_valueAnd) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(449) + p.ValueNot() + } + p.SetState(453) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 48, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(450) + p.ValueAndPart() + } + + } + p.SetState(455) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 48, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueAndPartContext is an interface to support dynamic dispatch. +type IValueAndPartContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsValueAndPartContext differentiates from other interfaces. + IsValueAndPartContext() +} + +type ValueAndPartContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueAndPartContext() *ValueAndPartContext { + var p = new(ValueAndPartContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAndPart + return p +} + +func InitEmptyValueAndPartContext(p *ValueAndPartContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAndPart +} + +func (*ValueAndPartContext) IsValueAndPartContext() {} + +func NewValueAndPartContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueAndPartContext { + var p = new(ValueAndPartContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueAndPart + + return p +} + +func (s *ValueAndPartContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueAndPartContext) CopyAll(ctx *ValueAndPartContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *ValueAndPartContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueAndPartContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type VAndImplicitContext struct { + ValueAndPartContext +} + +func NewVAndImplicitContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VAndImplicitContext { + var p = new(VAndImplicitContext) + + InitEmptyValueAndPartContext(&p.ValueAndPartContext) + p.parser = parser + p.CopyAll(ctx.(*ValueAndPartContext)) + + return p +} + +func (s *VAndImplicitContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VAndImplicitContext) ValueNot() IValueNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueNotContext) +} + +func (s *VAndImplicitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVAndImplicit(s) + + default: + return t.VisitChildren(s) + } +} + +type VAndExplicitContext struct { + ValueAndPartContext +} + +func NewVAndExplicitContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VAndExplicitContext { + var p = new(VAndExplicitContext) + + InitEmptyValueAndPartContext(&p.ValueAndPartContext) + p.parser = parser + p.CopyAll(ctx.(*ValueAndPartContext)) + + return p +} + +func (s *VAndExplicitContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VAndExplicitContext) AND() antlr.TerminalNode { + return s.GetToken(SPL1ParserAND, 0) +} + +func (s *VAndExplicitContext) ValueNot() IValueNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueNotContext) +} + +func (s *VAndExplicitContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *VAndExplicitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVAndExplicit(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueAndPart() (localctx IValueAndPartContext) { + localctx = NewValueAndPartContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 54, SPL1ParserRULE_valueAndPart) + p.SetState(464) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 50, p.GetParserRuleContext()) { + case 1: + localctx = NewVAndExplicitContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + p.SetState(456) + + if !(p.at(SPL1ParserAND)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserAND)", "")) + goto errorExit + } + { + p.SetState(457) + p.Match(SPL1ParserAND) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(460) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 49, p.GetParserRuleContext()) { + case 1: + { + p.SetState(458) + p.ValueNot() + } + + case 2: + { + p.SetState(459) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + localctx = NewVAndImplicitContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + p.SetState(462) + + if !(p.startsTerm()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.startsTerm()", "")) + goto errorExit + } + { + p.SetState(463) + p.ValueNot() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueNotContext is an interface to support dynamic dispatch. +type IValueNotContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsValueNotContext differentiates from other interfaces. + IsValueNotContext() +} + +type ValueNotContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueNotContext() *ValueNotContext { + var p = new(ValueNotContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueNot + return p +} + +func InitEmptyValueNotContext(p *ValueNotContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueNot +} + +func (*ValueNotContext) IsValueNotContext() {} + +func NewValueNotContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueNotContext { + var p = new(ValueNotContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueNot + + return p +} + +func (s *ValueNotContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueNotContext) CopyAll(ctx *ValueNotContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *ValueNotContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueNotContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type VNotUnaryContext struct { + ValueNotContext +} + +func NewVNotUnaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VNotUnaryContext { + var p = new(VNotUnaryContext) + + InitEmptyValueNotContext(&p.ValueNotContext) + p.parser = parser + p.CopyAll(ctx.(*ValueNotContext)) + + return p +} + +func (s *VNotUnaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VNotUnaryContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT, 0) +} + +func (s *VNotUnaryContext) BANG() antlr.TerminalNode { + return s.GetToken(SPL1ParserBANG, 0) +} + +func (s *VNotUnaryContext) ValueNot() IValueNotContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueNotContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueNotContext) +} + +func (s *VNotUnaryContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *VNotUnaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVNotUnary(s) + + default: + return t.VisitChildren(s) + } +} + +type VNotPrimaryContext struct { + ValueNotContext +} + +func NewVNotPrimaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VNotPrimaryContext { + var p = new(VNotPrimaryContext) + + InitEmptyValueNotContext(&p.ValueNotContext) + p.parser = parser + p.CopyAll(ctx.(*ValueNotContext)) + + return p +} + +func (s *VNotPrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VNotPrimaryContext) ValueComparison() IValueComparisonContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueComparisonContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueComparisonContext) +} + +func (s *VNotPrimaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVNotPrimary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueNot() (localctx IValueNotContext) { + localctx = NewValueNotContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 56, SPL1ParserRULE_valueNot) + var _la int + + p.SetState(472) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 52, p.GetParserRuleContext()) { + case 1: + localctx = NewVNotUnaryContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(466) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL1ParserNOT || _la == SPL1ParserBANG) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + p.SetState(469) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 51, p.GetParserRuleContext()) { + case 1: + { + p.SetState(467) + p.ValueNot() + } + + case 2: + { + p.SetState(468) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + localctx = NewVNotPrimaryContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(471) + p.ValueComparison() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueComparisonContext is an interface to support dynamic dispatch. +type IValueComparisonContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ValueAdd() IValueAddContext + AllValueComparisonTail() []IValueComparisonTailContext + ValueComparisonTail(i int) IValueComparisonTailContext + + // IsValueComparisonContext differentiates from other interfaces. + IsValueComparisonContext() +} + +type ValueComparisonContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueComparisonContext() *ValueComparisonContext { + var p = new(ValueComparisonContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueComparison + return p +} + +func InitEmptyValueComparisonContext(p *ValueComparisonContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueComparison +} + +func (*ValueComparisonContext) IsValueComparisonContext() {} + +func NewValueComparisonContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueComparisonContext { + var p = new(ValueComparisonContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueComparison + + return p +} + +func (s *ValueComparisonContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueComparisonContext) ValueAdd() IValueAddContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueAddContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueAddContext) +} + +func (s *ValueComparisonContext) AllValueComparisonTail() []IValueComparisonTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IValueComparisonTailContext); ok { + len++ + } + } + + tst := make([]IValueComparisonTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IValueComparisonTailContext); ok { + tst[i] = t.(IValueComparisonTailContext) + i++ + } + } + + return tst +} + +func (s *ValueComparisonContext) ValueComparisonTail(i int) IValueComparisonTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueComparisonTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IValueComparisonTailContext) +} + +func (s *ValueComparisonContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueComparisonContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueComparisonContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueComparison(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueComparison() (localctx IValueComparisonContext) { + localctx = NewValueComparisonContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 58, SPL1ParserRULE_valueComparison) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(474) + p.ValueAdd() + } + p.SetState(478) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 53, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(475) + p.ValueComparisonTail() + } + + } + p.SetState(480) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 53, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueComparisonTailContext is an interface to support dynamic dispatch. +type IValueComparisonTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ComparisonOp() IComparisonOpContext + ValueAdd() IValueAddContext + AbsentOperand() IAbsentOperandContext + + // IsValueComparisonTailContext differentiates from other interfaces. + IsValueComparisonTailContext() +} + +type ValueComparisonTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueComparisonTailContext() *ValueComparisonTailContext { + var p = new(ValueComparisonTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueComparisonTail + return p +} + +func InitEmptyValueComparisonTailContext(p *ValueComparisonTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueComparisonTail +} + +func (*ValueComparisonTailContext) IsValueComparisonTailContext() {} + +func NewValueComparisonTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueComparisonTailContext { + var p = new(ValueComparisonTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueComparisonTail + + return p +} + +func (s *ValueComparisonTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueComparisonTailContext) ComparisonOp() IComparisonOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IComparisonOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IComparisonOpContext) +} + +func (s *ValueComparisonTailContext) ValueAdd() IValueAddContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueAddContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueAddContext) +} + +func (s *ValueComparisonTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *ValueComparisonTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueComparisonTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueComparisonTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueComparisonTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueComparisonTail() (localctx IValueComparisonTailContext) { + localctx = NewValueComparisonTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 60, SPL1ParserRULE_valueComparisonTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(481) + + if !(p.atCompare()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atCompare()", "")) + goto errorExit + } + { + p.SetState(482) + p.ComparisonOp() + } + p.SetState(485) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 54, p.GetParserRuleContext()) { + case 1: + { + p.SetState(483) + p.ValueAdd() + } + + case 2: + { + p.SetState(484) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueAddContext is an interface to support dynamic dispatch. +type IValueAddContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ValueMul() IValueMulContext + AllValueAddTail() []IValueAddTailContext + ValueAddTail(i int) IValueAddTailContext + + // IsValueAddContext differentiates from other interfaces. + IsValueAddContext() +} + +type ValueAddContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueAddContext() *ValueAddContext { + var p = new(ValueAddContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAdd + return p +} + +func InitEmptyValueAddContext(p *ValueAddContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAdd +} + +func (*ValueAddContext) IsValueAddContext() {} + +func NewValueAddContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueAddContext { + var p = new(ValueAddContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueAdd + + return p +} + +func (s *ValueAddContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueAddContext) ValueMul() IValueMulContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueMulContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueMulContext) +} + +func (s *ValueAddContext) AllValueAddTail() []IValueAddTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IValueAddTailContext); ok { + len++ + } + } + + tst := make([]IValueAddTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IValueAddTailContext); ok { + tst[i] = t.(IValueAddTailContext) + i++ + } + } + + return tst +} + +func (s *ValueAddContext) ValueAddTail(i int) IValueAddTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueAddTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IValueAddTailContext) +} + +func (s *ValueAddContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueAddContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueAddContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueAdd(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueAdd() (localctx IValueAddContext) { + localctx = NewValueAddContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 62, SPL1ParserRULE_valueAdd) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(487) + p.ValueMul() + } + p.SetState(491) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 55, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(488) + p.ValueAddTail() + } + + } + p.SetState(493) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 55, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueAddTailContext is an interface to support dynamic dispatch. +type IValueAddTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AddOp() IAddOpContext + ValueMul() IValueMulContext + AbsentOperand() IAbsentOperandContext + + // IsValueAddTailContext differentiates from other interfaces. + IsValueAddTailContext() +} + +type ValueAddTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueAddTailContext() *ValueAddTailContext { + var p = new(ValueAddTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAddTail + return p +} + +func InitEmptyValueAddTailContext(p *ValueAddTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueAddTail +} + +func (*ValueAddTailContext) IsValueAddTailContext() {} + +func NewValueAddTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueAddTailContext { + var p = new(ValueAddTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueAddTail + + return p +} + +func (s *ValueAddTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueAddTailContext) AddOp() IAddOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAddOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAddOpContext) +} + +func (s *ValueAddTailContext) ValueMul() IValueMulContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueMulContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueMulContext) +} + +func (s *ValueAddTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *ValueAddTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueAddTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueAddTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueAddTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueAddTail() (localctx IValueAddTailContext) { + localctx = NewValueAddTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 64, SPL1ParserRULE_valueAddTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(494) + + if !(p.atAdd()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atAdd()", "")) + goto errorExit + } + { + p.SetState(495) + p.AddOp() + } + p.SetState(498) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 56, p.GetParserRuleContext()) { + case 1: + { + p.SetState(496) + p.ValueMul() + } + + case 2: + { + p.SetState(497) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueMulContext is an interface to support dynamic dispatch. +type IValueMulContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + ValueUnary() IValueUnaryContext + AllValueMulTail() []IValueMulTailContext + ValueMulTail(i int) IValueMulTailContext + + // IsValueMulContext differentiates from other interfaces. + IsValueMulContext() +} + +type ValueMulContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueMulContext() *ValueMulContext { + var p = new(ValueMulContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueMul + return p +} + +func InitEmptyValueMulContext(p *ValueMulContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueMul +} + +func (*ValueMulContext) IsValueMulContext() {} + +func NewValueMulContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueMulContext { + var p = new(ValueMulContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueMul + + return p +} + +func (s *ValueMulContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueMulContext) ValueUnary() IValueUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueUnaryContext) +} + +func (s *ValueMulContext) AllValueMulTail() []IValueMulTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IValueMulTailContext); ok { + len++ + } + } + + tst := make([]IValueMulTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IValueMulTailContext); ok { + tst[i] = t.(IValueMulTailContext) + i++ + } + } + + return tst +} + +func (s *ValueMulContext) ValueMulTail(i int) IValueMulTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueMulTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IValueMulTailContext) +} + +func (s *ValueMulContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueMulContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueMulContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueMul(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueMul() (localctx IValueMulContext) { + localctx = NewValueMulContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 66, SPL1ParserRULE_valueMul) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(500) + p.ValueUnary() + } + p.SetState(504) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 57, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(501) + p.ValueMulTail() + } + + } + p.SetState(506) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 57, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueMulTailContext is an interface to support dynamic dispatch. +type IValueMulTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + MulOp() IMulOpContext + ValueUnary() IValueUnaryContext + AbsentOperand() IAbsentOperandContext + + // IsValueMulTailContext differentiates from other interfaces. + IsValueMulTailContext() +} + +type ValueMulTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueMulTailContext() *ValueMulTailContext { + var p = new(ValueMulTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueMulTail + return p +} + +func InitEmptyValueMulTailContext(p *ValueMulTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueMulTail +} + +func (*ValueMulTailContext) IsValueMulTailContext() {} + +func NewValueMulTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueMulTailContext { + var p = new(ValueMulTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueMulTail + + return p +} + +func (s *ValueMulTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueMulTailContext) MulOp() IMulOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMulOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMulOpContext) +} + +func (s *ValueMulTailContext) ValueUnary() IValueUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueUnaryContext) +} + +func (s *ValueMulTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *ValueMulTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueMulTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ValueMulTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitValueMulTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueMulTail() (localctx IValueMulTailContext) { + localctx = NewValueMulTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 68, SPL1ParserRULE_valueMulTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(507) + + if !(p.atMul()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atMul()", "")) + goto errorExit + } + { + p.SetState(508) + p.MulOp() + } + p.SetState(511) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 58, p.GetParserRuleContext()) { + case 1: + { + p.SetState(509) + p.ValueUnary() + } + + case 2: + { + p.SetState(510) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValueUnaryContext is an interface to support dynamic dispatch. +type IValueUnaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsValueUnaryContext differentiates from other interfaces. + IsValueUnaryContext() +} + +type ValueUnaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValueUnaryContext() *ValueUnaryContext { + var p = new(ValueUnaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueUnary + return p +} + +func InitEmptyValueUnaryContext(p *ValueUnaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valueUnary +} + +func (*ValueUnaryContext) IsValueUnaryContext() {} + +func NewValueUnaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueUnaryContext { + var p = new(ValueUnaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valueUnary + + return p +} + +func (s *ValueUnaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValueUnaryContext) CopyAll(ctx *ValueUnaryContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *ValueUnaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValueUnaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type VUnarySignContext struct { + ValueUnaryContext +} + +func NewVUnarySignContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VUnarySignContext { + var p = new(VUnarySignContext) + + InitEmptyValueUnaryContext(&p.ValueUnaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValueUnaryContext)) + + return p +} + +func (s *VUnarySignContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VUnarySignContext) Sign() ISignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISignContext) +} + +func (s *VUnarySignContext) ValueUnary() IValueUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueUnaryContext) +} + +func (s *VUnarySignContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *VUnarySignContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVUnarySign(s) + + default: + return t.VisitChildren(s) + } +} + +type VUnaryPrimaryContext struct { + ValueUnaryContext +} + +func NewVUnaryPrimaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VUnaryPrimaryContext { + var p = new(VUnaryPrimaryContext) + + InitEmptyValueUnaryContext(&p.ValueUnaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValueUnaryContext)) + + return p +} + +func (s *VUnaryPrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VUnaryPrimaryContext) ValuePrimary() IValuePrimaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValuePrimaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValuePrimaryContext) +} + +func (s *VUnaryPrimaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVUnaryPrimary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValueUnary() (localctx IValueUnaryContext) { + localctx = NewValueUnaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 70, SPL1ParserRULE_valueUnary) + p.SetState(519) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 60, p.GetParserRuleContext()) { + case 1: + localctx = NewVUnarySignContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(513) + p.Sign() + } + p.SetState(516) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 59, p.GetParserRuleContext()) { + case 1: + { + p.SetState(514) + p.ValueUnary() + } + + case 2: + { + p.SetState(515) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + localctx = NewVUnaryPrimaryContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(518) + p.ValuePrimary() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IValuePrimaryContext is an interface to support dynamic dispatch. +type IValuePrimaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsValuePrimaryContext differentiates from other interfaces. + IsValuePrimaryContext() +} + +type ValuePrimaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyValuePrimaryContext() *ValuePrimaryContext { + var p = new(ValuePrimaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valuePrimary + return p +} + +func InitEmptyValuePrimaryContext(p *ValuePrimaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_valuePrimary +} + +func (*ValuePrimaryContext) IsValuePrimaryContext() {} + +func NewValuePrimaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValuePrimaryContext { + var p = new(ValuePrimaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_valuePrimary + + return p +} + +func (s *ValuePrimaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *ValuePrimaryContext) CopyAll(ctx *ValuePrimaryContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *ValuePrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ValuePrimaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type VPrimStringContext struct { + ValuePrimaryContext +} + +func NewVPrimStringContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimStringContext { + var p = new(VPrimStringContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimStringContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimStringContext) STRING() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTRING, 0) +} + +func (s *VPrimStringContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimString(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimDurationContext struct { + ValuePrimaryContext +} + +func NewVPrimDurationContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimDurationContext { + var p = new(VPrimDurationContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimDurationContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimDurationContext) DURATION() antlr.TerminalNode { + return s.GetToken(SPL1ParserDURATION, 0) +} + +func (s *VPrimDurationContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimDuration(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimWordContext struct { + ValuePrimaryContext +} + +func NewVPrimWordContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimWordContext { + var p = new(VPrimWordContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimWordContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimWordContext) ExprWord() IExprWordContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IExprWordContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IExprWordContext) +} + +func (s *VPrimWordContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimWord(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimCallContext struct { + ValuePrimaryContext +} + +func NewVPrimCallContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimCallContext { + var p = new(VPrimCallContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimCallContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimCallContext) ExprWord() IExprWordContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IExprWordContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IExprWordContext) +} + +func (s *VPrimCallContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserLPAREN, 0) +} + +func (s *VPrimCallContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *VPrimCallContext) AllValueExpr() []IValueExprContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IValueExprContext); ok { + len++ + } + } + + tst := make([]IValueExprContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IValueExprContext); ok { + tst[i] = t.(IValueExprContext) + i++ + } + } + + return tst +} + +func (s *VPrimCallContext) ValueExpr(i int) IValueExprContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueExprContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IValueExprContext) +} + +func (s *VPrimCallContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserCOMMA) +} + +func (s *VPrimCallContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, i) +} + +func (s *VPrimCallContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimCall(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimNumberContext struct { + ValuePrimaryContext +} + +func NewVPrimNumberContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimNumberContext { + var p = new(VPrimNumberContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimNumberContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimNumberContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *VPrimNumberContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimNumber(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimSubsearchContext struct { + ValuePrimaryContext +} + +func NewVPrimSubsearchContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimSubsearchContext { + var p = new(VPrimSubsearchContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimSubsearchContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimSubsearchContext) Subsearch() ISubsearchContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISubsearchContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISubsearchContext) +} + +func (s *VPrimSubsearchContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimSubsearch(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimParenContext struct { + ValuePrimaryContext +} + +func NewVPrimParenContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimParenContext { + var p = new(VPrimParenContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimParenContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimParenContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserLPAREN, 0) +} + +func (s *VPrimParenContext) ValueExpr() IValueExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueExprContext) +} + +func (s *VPrimParenContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *VPrimParenContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimParen(s) + + default: + return t.VisitChildren(s) + } +} + +type VPrimStarContext struct { + ValuePrimaryContext +} + +func NewVPrimStarContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *VPrimStarContext { + var p = new(VPrimStarContext) + + InitEmptyValuePrimaryContext(&p.ValuePrimaryContext) + p.parser = parser + p.CopyAll(ctx.(*ValuePrimaryContext)) + + return p +} + +func (s *VPrimStarContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *VPrimStarContext) OperandStar() IOperandStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IOperandStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IOperandStarContext) +} + +func (s *VPrimStarContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitVPrimStar(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ValuePrimary() (localctx IValuePrimaryContext) { + localctx = NewValuePrimaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 72, SPL1ParserRULE_valuePrimary) + var _la int + + p.SetState(546) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 63, p.GetParserRuleContext()) { + case 1: + localctx = NewVPrimParenContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(521) + p.Match(SPL1ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(522) + p.ValueExpr() + } + { + p.SetState(523) + p.Match(SPL1ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 2: + localctx = NewVPrimCallContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + p.SetState(525) + + if !(p.callAhead()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.callAhead()", "")) + goto errorExit + } + { + p.SetState(526) + p.ExprWord() + } + { + p.SetState(527) + p.Match(SPL1ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(536) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 62, p.GetParserRuleContext()) == 1 { + { + p.SetState(528) + p.ValueExpr() + } + p.SetState(533) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL1ParserCOMMA { + { + p.SetState(529) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(530) + p.ValueExpr() + } + + p.SetState(535) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + } else if p.HasError() { // JIM + goto errorExit + } + { + p.SetState(538) + p.Match(SPL1ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 3: + localctx = NewVPrimWordContext(p, localctx) + p.EnterOuterAlt(localctx, 3) + { + p.SetState(540) + p.ExprWord() + } + + case 4: + localctx = NewVPrimStringContext(p, localctx) + p.EnterOuterAlt(localctx, 4) + { + p.SetState(541) + p.Match(SPL1ParserSTRING) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 5: + localctx = NewVPrimNumberContext(p, localctx) + p.EnterOuterAlt(localctx, 5) + { + p.SetState(542) + p.Number() + } + + case 6: + localctx = NewVPrimDurationContext(p, localctx) + p.EnterOuterAlt(localctx, 6) + { + p.SetState(543) + p.Match(SPL1ParserDURATION) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 7: + localctx = NewVPrimStarContext(p, localctx) + p.EnterOuterAlt(localctx, 7) + { + p.SetState(544) + p.OperandStar() + } + + case 8: + localctx = NewVPrimSubsearchContext(p, localctx) + p.EnterOuterAlt(localctx, 8) + { + p.SetState(545) + p.Subsearch() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISubsearchContext is an interface to support dynamic dispatch. +type ISubsearchContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + LBRACKET() antlr.TerminalNode + AllPIPE() []antlr.TerminalNode + PIPE(i int) antlr.TerminalNode + AllEOF() []antlr.TerminalNode + EOF(i int) antlr.TerminalNode + + // IsSubsearchContext differentiates from other interfaces. + IsSubsearchContext() +} + +type SubsearchContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySubsearchContext() *SubsearchContext { + var p = new(SubsearchContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_subsearch + return p +} + +func InitEmptySubsearchContext(p *SubsearchContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_subsearch +} + +func (*SubsearchContext) IsSubsearchContext() {} + +func NewSubsearchContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SubsearchContext { + var p = new(SubsearchContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_subsearch + + return p +} + +func (s *SubsearchContext) GetParser() antlr.Parser { return s.parser } + +func (s *SubsearchContext) LBRACKET() antlr.TerminalNode { + return s.GetToken(SPL1ParserLBRACKET, 0) +} + +func (s *SubsearchContext) AllPIPE() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserPIPE) +} + +func (s *SubsearchContext) PIPE(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserPIPE, i) +} + +func (s *SubsearchContext) AllEOF() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserEOF) +} + +func (s *SubsearchContext) EOF(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserEOF, i) +} + +func (s *SubsearchContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SubsearchContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SubsearchContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSubsearch(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Subsearch() (localctx ISubsearchContext) { + localctx = NewSubsearchContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 74, SPL1ParserRULE_subsearch) + var _la int + + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(548) + p.Match(SPL1ParserLBRACKET) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.abortSubsearch() + p.SetState(553) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 64, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(550) + _la = p.GetTokenStream().LA(1) + + if _la <= 0 || _la == SPL1ParserEOF || _la == SPL1ParserPIPE { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + + } + p.SetState(555) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 64, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAbsentOperandContext is an interface to support dynamic dispatch. +type IAbsentOperandContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EQ2() antlr.TerminalNode + EQ() antlr.TerminalNode + NE() antlr.TerminalNode + LT() antlr.TerminalNode + LE() antlr.TerminalNode + GT() antlr.TerminalNode + GE() antlr.TerminalNode + COMMA() antlr.TerminalNode + RPAREN() antlr.TerminalNode + RBRACKET() antlr.TerminalNode + PIPE() antlr.TerminalNode + EOF() antlr.TerminalNode + + // IsAbsentOperandContext differentiates from other interfaces. + IsAbsentOperandContext() +} + +type AbsentOperandContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAbsentOperandContext() *AbsentOperandContext { + var p = new(AbsentOperandContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_absentOperand + return p +} + +func InitEmptyAbsentOperandContext(p *AbsentOperandContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_absentOperand +} + +func (*AbsentOperandContext) IsAbsentOperandContext() {} + +func NewAbsentOperandContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AbsentOperandContext { + var p = new(AbsentOperandContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_absentOperand + + return p +} + +func (s *AbsentOperandContext) GetParser() antlr.Parser { return s.parser } + +func (s *AbsentOperandContext) EQ2() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ2, 0) +} + +func (s *AbsentOperandContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ, 0) +} + +func (s *AbsentOperandContext) NE() antlr.TerminalNode { + return s.GetToken(SPL1ParserNE, 0) +} + +func (s *AbsentOperandContext) LT() antlr.TerminalNode { + return s.GetToken(SPL1ParserLT, 0) +} + +func (s *AbsentOperandContext) LE() antlr.TerminalNode { + return s.GetToken(SPL1ParserLE, 0) +} + +func (s *AbsentOperandContext) GT() antlr.TerminalNode { + return s.GetToken(SPL1ParserGT, 0) +} + +func (s *AbsentOperandContext) GE() antlr.TerminalNode { + return s.GetToken(SPL1ParserGE, 0) +} + +func (s *AbsentOperandContext) COMMA() antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, 0) +} + +func (s *AbsentOperandContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *AbsentOperandContext) RBRACKET() antlr.TerminalNode { + return s.GetToken(SPL1ParserRBRACKET, 0) +} + +func (s *AbsentOperandContext) PIPE() antlr.TerminalNode { + return s.GetToken(SPL1ParserPIPE, 0) +} + +func (s *AbsentOperandContext) EOF() antlr.TerminalNode { + return s.GetToken(SPL1ParserEOF, 0) +} + +func (s *AbsentOperandContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AbsentOperandContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AbsentOperandContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAbsentOperand(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) AbsentOperand() (localctx IAbsentOperandContext) { + localctx = NewAbsentOperandContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 76, SPL1ParserRULE_absentOperand) + var _la int + + p.EnterOuterAlt(localctx, 1) + p.abortMissingOperand() + { + p.SetState(557) + _la = p.GetTokenStream().LA(1) + + if !((int64((_la - -1)) & ^0x3f) == 0 && ((int64(1)<<(_la - -1))&373628600321) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IComparisonOpContext is an interface to support dynamic dispatch. +type IComparisonOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EQ2() antlr.TerminalNode + EQ() antlr.TerminalNode + NE() antlr.TerminalNode + LT() antlr.TerminalNode + LE() antlr.TerminalNode + GT() antlr.TerminalNode + GE() antlr.TerminalNode + + // IsComparisonOpContext differentiates from other interfaces. + IsComparisonOpContext() +} + +type ComparisonOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyComparisonOpContext() *ComparisonOpContext { + var p = new(ComparisonOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_comparisonOp + return p +} + +func InitEmptyComparisonOpContext(p *ComparisonOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_comparisonOp +} + +func (*ComparisonOpContext) IsComparisonOpContext() {} + +func NewComparisonOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ComparisonOpContext { + var p = new(ComparisonOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_comparisonOp + + return p +} + +func (s *ComparisonOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *ComparisonOpContext) EQ2() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ2, 0) +} + +func (s *ComparisonOpContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ, 0) +} + +func (s *ComparisonOpContext) NE() antlr.TerminalNode { + return s.GetToken(SPL1ParserNE, 0) +} + +func (s *ComparisonOpContext) LT() antlr.TerminalNode { + return s.GetToken(SPL1ParserLT, 0) +} + +func (s *ComparisonOpContext) LE() antlr.TerminalNode { + return s.GetToken(SPL1ParserLE, 0) +} + +func (s *ComparisonOpContext) GT() antlr.TerminalNode { + return s.GetToken(SPL1ParserGT, 0) +} + +func (s *ComparisonOpContext) GE() antlr.TerminalNode { + return s.GetToken(SPL1ParserGE, 0) +} + +func (s *ComparisonOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ComparisonOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ComparisonOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitComparisonOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ComparisonOp() (localctx IComparisonOpContext) { + localctx = NewComparisonOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 78, SPL1ParserRULE_comparisonOp) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(559) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&2130706432) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IOperandStarContext is an interface to support dynamic dispatch. +type IOperandStarContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + STAR() antlr.TerminalNode + STAR_TIGHT() antlr.TerminalNode + STAR_TERM() antlr.TerminalNode + + // IsOperandStarContext differentiates from other interfaces. + IsOperandStarContext() +} + +type OperandStarContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyOperandStarContext() *OperandStarContext { + var p = new(OperandStarContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_operandStar + return p +} + +func InitEmptyOperandStarContext(p *OperandStarContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_operandStar +} + +func (*OperandStarContext) IsOperandStarContext() {} + +func NewOperandStarContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *OperandStarContext { + var p = new(OperandStarContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_operandStar + + return p +} + +func (s *OperandStarContext) GetParser() antlr.Parser { return s.parser } + +func (s *OperandStarContext) STAR() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR, 0) +} + +func (s *OperandStarContext) STAR_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_TIGHT, 0) +} + +func (s *OperandStarContext) STAR_TERM() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_TERM, 0) +} + +func (s *OperandStarContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *OperandStarContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *OperandStarContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitOperandStar(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) OperandStar() (localctx IOperandStarContext) { + localctx = NewOperandStarContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 80, SPL1ParserRULE_operandStar) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(561) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&352943232516096) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IStarContext is an interface to support dynamic dispatch. +type IStarContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + OperandStar() IOperandStarContext + STAR_OP() antlr.TerminalNode + + // IsStarContext differentiates from other interfaces. + IsStarContext() +} + +type StarContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStarContext() *StarContext { + var p = new(StarContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_star + return p +} + +func InitEmptyStarContext(p *StarContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_star +} + +func (*StarContext) IsStarContext() {} + +func NewStarContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StarContext { + var p = new(StarContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_star + + return p +} + +func (s *StarContext) GetParser() antlr.Parser { return s.parser } + +func (s *StarContext) OperandStar() IOperandStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IOperandStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IOperandStarContext) +} + +func (s *StarContext) STAR_OP() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_OP, 0) +} + +func (s *StarContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StarContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StarContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitStar(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Star() (localctx IStarContext) { + localctx = NewStarContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 82, SPL1ParserRULE_star) + p.SetState(565) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(563) + p.OperandStar() + } + + case SPL1ParserSTAR_OP: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(564) + p.Match(SPL1ParserSTAR_OP) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IMinusContext is an interface to support dynamic dispatch. +type IMinusContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + MINUS() antlr.TerminalNode + MINUS_TIGHT() antlr.TerminalNode + + // IsMinusContext differentiates from other interfaces. + IsMinusContext() +} + +type MinusContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyMinusContext() *MinusContext { + var p = new(MinusContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_minus + return p +} + +func InitEmptyMinusContext(p *MinusContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_minus +} + +func (*MinusContext) IsMinusContext() {} + +func NewMinusContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MinusContext { + var p = new(MinusContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_minus + + return p +} + +func (s *MinusContext) GetParser() antlr.Parser { return s.parser } + +func (s *MinusContext) MINUS() antlr.TerminalNode { + return s.GetToken(SPL1ParserMINUS, 0) +} + +func (s *MinusContext) MINUS_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserMINUS_TIGHT, 0) +} + +func (s *MinusContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *MinusContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *MinusContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitMinus(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Minus() (localctx IMinusContext) { + localctx = NewMinusContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 84, SPL1ParserRULE_minus) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(567) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL1ParserMINUS || _la == SPL1ParserMINUS_TIGHT) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// INumberContext is an interface to support dynamic dispatch. +type INumberContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + NUMBER() antlr.TerminalNode + NUMBER_TIGHT() antlr.TerminalNode + + // IsNumberContext differentiates from other interfaces. + IsNumberContext() +} + +type NumberContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyNumberContext() *NumberContext { + var p = new(NumberContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_number + return p +} + +func InitEmptyNumberContext(p *NumberContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_number +} + +func (*NumberContext) IsNumberContext() {} + +func NewNumberContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *NumberContext { + var p = new(NumberContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_number + + return p +} + +func (s *NumberContext) GetParser() antlr.Parser { return s.parser } + +func (s *NumberContext) NUMBER() antlr.TerminalNode { + return s.GetToken(SPL1ParserNUMBER, 0) +} + +func (s *NumberContext) NUMBER_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNUMBER_TIGHT, 0) +} + +func (s *NumberContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *NumberContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *NumberContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitNumber(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Number() (localctx INumberContext) { + localctx = NewNumberContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 86, SPL1ParserRULE_number) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(569) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL1ParserNUMBER || _la == SPL1ParserNUMBER_TIGHT) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAddOpContext is an interface to support dynamic dispatch. +type IAddOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + PLUS() antlr.TerminalNode + Minus() IMinusContext + + // IsAddOpContext differentiates from other interfaces. + IsAddOpContext() +} + +type AddOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAddOpContext() *AddOpContext { + var p = new(AddOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_addOp + return p +} + +func InitEmptyAddOpContext(p *AddOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_addOp +} + +func (*AddOpContext) IsAddOpContext() {} + +func NewAddOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AddOpContext { + var p = new(AddOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_addOp + + return p +} + +func (s *AddOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *AddOpContext) PLUS() antlr.TerminalNode { + return s.GetToken(SPL1ParserPLUS, 0) +} + +func (s *AddOpContext) Minus() IMinusContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMinusContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMinusContext) +} + +func (s *AddOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AddOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AddOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAddOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) AddOp() (localctx IAddOpContext) { + localctx = NewAddOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 88, SPL1ParserRULE_addOp) + p.SetState(573) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserPLUS: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(571) + p.Match(SPL1ParserPLUS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserMINUS, SPL1ParserMINUS_TIGHT: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(572) + p.Minus() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IMulOpContext is an interface to support dynamic dispatch. +type IMulOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Star() IStarContext + SLASH() antlr.TerminalNode + PERCENT() antlr.TerminalNode + + // IsMulOpContext differentiates from other interfaces. + IsMulOpContext() +} + +type MulOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyMulOpContext() *MulOpContext { + var p = new(MulOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_mulOp + return p +} + +func InitEmptyMulOpContext(p *MulOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_mulOp +} + +func (*MulOpContext) IsMulOpContext() {} + +func NewMulOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MulOpContext { + var p = new(MulOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_mulOp + + return p +} + +func (s *MulOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *MulOpContext) Star() IStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStarContext) +} + +func (s *MulOpContext) SLASH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSLASH, 0) +} + +func (s *MulOpContext) PERCENT() antlr.TerminalNode { + return s.GetToken(SPL1ParserPERCENT, 0) +} + +func (s *MulOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *MulOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *MulOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitMulOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) MulOp() (localctx IMulOpContext) { + localctx = NewMulOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 90, SPL1ParserRULE_mulOp) + p.SetState(578) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(575) + p.Star() + } + + case SPL1ParserSLASH: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(576) + p.Match(SPL1ParserSLASH) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserPERCENT: + p.EnterOuterAlt(localctx, 3) + { + p.SetState(577) + p.Match(SPL1ParserPERCENT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISearchMulOpContext is an interface to support dynamic dispatch. +type ISearchMulOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + STAR() antlr.TerminalNode + STAR_TIGHT() antlr.TerminalNode + STAR_OP() antlr.TerminalNode + SLASH() antlr.TerminalNode + PERCENT() antlr.TerminalNode + + // IsSearchMulOpContext differentiates from other interfaces. + IsSearchMulOpContext() +} + +type SearchMulOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySearchMulOpContext() *SearchMulOpContext { + var p = new(SearchMulOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchMulOp + return p +} + +func InitEmptySearchMulOpContext(p *SearchMulOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_searchMulOp +} + +func (*SearchMulOpContext) IsSearchMulOpContext() {} + +func NewSearchMulOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SearchMulOpContext { + var p = new(SearchMulOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_searchMulOp + + return p +} + +func (s *SearchMulOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *SearchMulOpContext) STAR() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR, 0) +} + +func (s *SearchMulOpContext) STAR_TIGHT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_TIGHT, 0) +} + +func (s *SearchMulOpContext) STAR_OP() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTAR_OP, 0) +} + +func (s *SearchMulOpContext) SLASH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSLASH, 0) +} + +func (s *SearchMulOpContext) PERCENT() antlr.TerminalNode { + return s.GetToken(SPL1ParserPERCENT, 0) +} + +func (s *SearchMulOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SearchMulOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SearchMulOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSearchMulOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SearchMulOp() (localctx ISearchMulOpContext) { + localctx = NewSearchMulOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 92, SPL1ParserRULE_searchMulOp) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(580) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&641015278993408) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISignContext is an interface to support dynamic dispatch. +type ISignContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Minus() IMinusContext + PLUS() antlr.TerminalNode + + // IsSignContext differentiates from other interfaces. + IsSignContext() +} + +type SignContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySignContext() *SignContext { + var p = new(SignContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sign + return p +} + +func InitEmptySignContext(p *SignContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sign +} + +func (*SignContext) IsSignContext() {} + +func NewSignContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SignContext { + var p = new(SignContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_sign + + return p +} + +func (s *SignContext) GetParser() antlr.Parser { return s.parser } + +func (s *SignContext) Minus() IMinusContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMinusContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMinusContext) +} + +func (s *SignContext) PLUS() antlr.TerminalNode { + return s.GetToken(SPL1ParserPLUS, 0) +} + +func (s *SignContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SignContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SignContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSign(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Sign() (localctx ISignContext) { + localctx = NewSignContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 94, SPL1ParserRULE_sign) + p.SetState(584) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserMINUS, SPL1ParserMINUS_TIGHT: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(582) + p.Minus() + } + + case SPL1ParserPLUS: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(583) + p.Match(SPL1ParserPLUS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IIdentLikeContext is an interface to support dynamic dispatch. +type IIdentLikeContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IDENT() antlr.TerminalNode + SEARCH() antlr.TerminalNode + WHERE() antlr.TerminalNode + STATS() antlr.TerminalNode + TIMECHART() antlr.TerminalNode + EVAL() antlr.TerminalNode + REX() antlr.TerminalNode + TABLE() antlr.TerminalNode + FIELDS() antlr.TerminalNode + SORT() antlr.TerminalNode + HEAD() antlr.TerminalNode + BIN() antlr.TerminalNode + BY() antlr.TerminalNode + AS() antlr.TerminalNode + SPAN() antlr.TerminalNode + LIMIT() antlr.TerminalNode + FIELD() antlr.TerminalNode + AND() antlr.TerminalNode + OR() antlr.TerminalNode + NOT() antlr.TerminalNode + NOT_WORD() antlr.TerminalNode + + // IsIdentLikeContext differentiates from other interfaces. + IsIdentLikeContext() +} + +type IdentLikeContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyIdentLikeContext() *IdentLikeContext { + var p = new(IdentLikeContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_identLike + return p +} + +func InitEmptyIdentLikeContext(p *IdentLikeContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_identLike +} + +func (*IdentLikeContext) IsIdentLikeContext() {} + +func NewIdentLikeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IdentLikeContext { + var p = new(IdentLikeContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_identLike + + return p +} + +func (s *IdentLikeContext) GetParser() antlr.Parser { return s.parser } + +func (s *IdentLikeContext) IDENT() antlr.TerminalNode { + return s.GetToken(SPL1ParserIDENT, 0) +} + +func (s *IdentLikeContext) SEARCH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSEARCH, 0) +} + +func (s *IdentLikeContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL1ParserWHERE, 0) +} + +func (s *IdentLikeContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTATS, 0) +} + +func (s *IdentLikeContext) TIMECHART() antlr.TerminalNode { + return s.GetToken(SPL1ParserTIMECHART, 0) +} + +func (s *IdentLikeContext) EVAL() antlr.TerminalNode { + return s.GetToken(SPL1ParserEVAL, 0) +} + +func (s *IdentLikeContext) REX() antlr.TerminalNode { + return s.GetToken(SPL1ParserREX, 0) +} + +func (s *IdentLikeContext) TABLE() antlr.TerminalNode { + return s.GetToken(SPL1ParserTABLE, 0) +} + +func (s *IdentLikeContext) FIELDS() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELDS, 0) +} + +func (s *IdentLikeContext) SORT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSORT, 0) +} + +func (s *IdentLikeContext) HEAD() antlr.TerminalNode { + return s.GetToken(SPL1ParserHEAD, 0) +} + +func (s *IdentLikeContext) BIN() antlr.TerminalNode { + return s.GetToken(SPL1ParserBIN, 0) +} + +func (s *IdentLikeContext) BY() antlr.TerminalNode { + return s.GetToken(SPL1ParserBY, 0) +} + +func (s *IdentLikeContext) AS() antlr.TerminalNode { + return s.GetToken(SPL1ParserAS, 0) +} + +func (s *IdentLikeContext) SPAN() antlr.TerminalNode { + return s.GetToken(SPL1ParserSPAN, 0) +} + +func (s *IdentLikeContext) LIMIT() antlr.TerminalNode { + return s.GetToken(SPL1ParserLIMIT, 0) +} + +func (s *IdentLikeContext) FIELD() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELD, 0) +} + +func (s *IdentLikeContext) AND() antlr.TerminalNode { + return s.GetToken(SPL1ParserAND, 0) +} + +func (s *IdentLikeContext) OR() antlr.TerminalNode { + return s.GetToken(SPL1ParserOR, 0) +} + +func (s *IdentLikeContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT, 0) +} + +func (s *IdentLikeContext) NOT_WORD() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT_WORD, 0) +} + +func (s *IdentLikeContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *IdentLikeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *IdentLikeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitIdentLike(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) IdentLike() (localctx IIdentLikeContext) { + localctx = NewIdentLikeContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 96, SPL1ParserRULE_identLike) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(586) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1125899916279806) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IExprWordContext is an interface to support dynamic dispatch. +type IExprWordContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IDENT() antlr.TerminalNode + SEARCH() antlr.TerminalNode + WHERE() antlr.TerminalNode + STATS() antlr.TerminalNode + TIMECHART() antlr.TerminalNode + EVAL() antlr.TerminalNode + REX() antlr.TerminalNode + TABLE() antlr.TerminalNode + FIELDS() antlr.TerminalNode + SORT() antlr.TerminalNode + HEAD() antlr.TerminalNode + BIN() antlr.TerminalNode + BY() antlr.TerminalNode + AS() antlr.TerminalNode + SPAN() antlr.TerminalNode + LIMIT() antlr.TerminalNode + FIELD() antlr.TerminalNode + AND() antlr.TerminalNode + OR() antlr.TerminalNode + NOT_WORD() antlr.TerminalNode + + // IsExprWordContext differentiates from other interfaces. + IsExprWordContext() +} + +type ExprWordContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyExprWordContext() *ExprWordContext { + var p = new(ExprWordContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_exprWord + return p +} + +func InitEmptyExprWordContext(p *ExprWordContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_exprWord +} + +func (*ExprWordContext) IsExprWordContext() {} + +func NewExprWordContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ExprWordContext { + var p = new(ExprWordContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_exprWord + + return p +} + +func (s *ExprWordContext) GetParser() antlr.Parser { return s.parser } + +func (s *ExprWordContext) IDENT() antlr.TerminalNode { + return s.GetToken(SPL1ParserIDENT, 0) +} + +func (s *ExprWordContext) SEARCH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSEARCH, 0) +} + +func (s *ExprWordContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL1ParserWHERE, 0) +} + +func (s *ExprWordContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTATS, 0) +} + +func (s *ExprWordContext) TIMECHART() antlr.TerminalNode { + return s.GetToken(SPL1ParserTIMECHART, 0) +} + +func (s *ExprWordContext) EVAL() antlr.TerminalNode { + return s.GetToken(SPL1ParserEVAL, 0) +} + +func (s *ExprWordContext) REX() antlr.TerminalNode { + return s.GetToken(SPL1ParserREX, 0) +} + +func (s *ExprWordContext) TABLE() antlr.TerminalNode { + return s.GetToken(SPL1ParserTABLE, 0) +} + +func (s *ExprWordContext) FIELDS() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELDS, 0) +} + +func (s *ExprWordContext) SORT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSORT, 0) +} + +func (s *ExprWordContext) HEAD() antlr.TerminalNode { + return s.GetToken(SPL1ParserHEAD, 0) +} + +func (s *ExprWordContext) BIN() antlr.TerminalNode { + return s.GetToken(SPL1ParserBIN, 0) +} + +func (s *ExprWordContext) BY() antlr.TerminalNode { + return s.GetToken(SPL1ParserBY, 0) +} + +func (s *ExprWordContext) AS() antlr.TerminalNode { + return s.GetToken(SPL1ParserAS, 0) +} + +func (s *ExprWordContext) SPAN() antlr.TerminalNode { + return s.GetToken(SPL1ParserSPAN, 0) +} + +func (s *ExprWordContext) LIMIT() antlr.TerminalNode { + return s.GetToken(SPL1ParserLIMIT, 0) +} + +func (s *ExprWordContext) FIELD() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELD, 0) +} + +func (s *ExprWordContext) AND() antlr.TerminalNode { + return s.GetToken(SPL1ParserAND, 0) +} + +func (s *ExprWordContext) OR() antlr.TerminalNode { + return s.GetToken(SPL1ParserOR, 0) +} + +func (s *ExprWordContext) NOT_WORD() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT_WORD, 0) +} + +func (s *ExprWordContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ExprWordContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ExprWordContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitExprWord(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ExprWord() (localctx IExprWordContext) { + localctx = NewExprWordContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 98, SPL1ParserRULE_exprWord) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(588) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1125899915755518) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAggListContext is an interface to support dynamic dispatch. +type IAggListContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AllAgg() []IAggContext + Agg(i int) IAggContext + AllCOMMA() []antlr.TerminalNode + COMMA(i int) antlr.TerminalNode + + // IsAggListContext differentiates from other interfaces. + IsAggListContext() +} + +type AggListContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAggListContext() *AggListContext { + var p = new(AggListContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aggList + return p +} + +func InitEmptyAggListContext(p *AggListContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aggList +} + +func (*AggListContext) IsAggListContext() {} + +func NewAggListContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AggListContext { + var p = new(AggListContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_aggList + + return p +} + +func (s *AggListContext) GetParser() antlr.Parser { return s.parser } + +func (s *AggListContext) AllAgg() []IAggContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IAggContext); ok { + len++ + } + } + + tst := make([]IAggContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IAggContext); ok { + tst[i] = t.(IAggContext) + i++ + } + } + + return tst +} + +func (s *AggListContext) Agg(i int) IAggContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IAggContext) +} + +func (s *AggListContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserCOMMA) +} + +func (s *AggListContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, i) +} + +func (s *AggListContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AggListContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AggListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAggList(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) AggList() (localctx IAggListContext) { + localctx = NewAggListContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 100, SPL1ParserRULE_aggList) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(590) + p.Agg() + } + p.SetState(595) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL1ParserCOMMA { + { + p.SetState(591) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(592) + p.Agg() + } + + p.SetState(597) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAggContext is an interface to support dynamic dispatch. +type IAggContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + LPAREN() antlr.TerminalNode + RPAREN() antlr.TerminalNode + AliasClause() IAliasClauseContext + ValueExpr() IValueExprContext + + // IsAggContext differentiates from other interfaces. + IsAggContext() +} + +type AggContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAggContext() *AggContext { + var p = new(AggContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_agg + return p +} + +func InitEmptyAggContext(p *AggContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_agg +} + +func (*AggContext) IsAggContext() {} + +func NewAggContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AggContext { + var p = new(AggContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_agg + + return p +} + +func (s *AggContext) GetParser() antlr.Parser { return s.parser } + +func (s *AggContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *AggContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserLPAREN, 0) +} + +func (s *AggContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *AggContext) AliasClause() IAliasClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAliasClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAliasClauseContext) +} + +func (s *AggContext) ValueExpr() IValueExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueExprContext) +} + +func (s *AggContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AggContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AggContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAgg(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Agg() (localctx IAggContext) { + localctx = NewAggContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 102, SPL1ParserRULE_agg) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(598) + p.IdentLike() + } + p.SetState(604) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserLPAREN { + { + p.SetState(599) + p.Match(SPL1ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(601) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 70, p.GetParserRuleContext()) == 1 { + { + p.SetState(600) + p.ValueExpr() + } + + } else if p.HasError() { // JIM + goto errorExit + } + { + p.SetState(603) + p.Match(SPL1ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + } + p.SetState(607) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserAS { + { + p.SetState(606) + p.AliasClause() + } + + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAggListNotSpanContext is an interface to support dynamic dispatch. +type IAggListNotSpanContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AggNotSpan() IAggNotSpanContext + AllCOMMA() []antlr.TerminalNode + COMMA(i int) antlr.TerminalNode + AllAgg() []IAggContext + Agg(i int) IAggContext + + // IsAggListNotSpanContext differentiates from other interfaces. + IsAggListNotSpanContext() +} + +type AggListNotSpanContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAggListNotSpanContext() *AggListNotSpanContext { + var p = new(AggListNotSpanContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aggListNotSpan + return p +} + +func InitEmptyAggListNotSpanContext(p *AggListNotSpanContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aggListNotSpan +} + +func (*AggListNotSpanContext) IsAggListNotSpanContext() {} + +func NewAggListNotSpanContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AggListNotSpanContext { + var p = new(AggListNotSpanContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_aggListNotSpan + + return p +} + +func (s *AggListNotSpanContext) GetParser() antlr.Parser { return s.parser } + +func (s *AggListNotSpanContext) AggNotSpan() IAggNotSpanContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggNotSpanContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAggNotSpanContext) +} + +func (s *AggListNotSpanContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserCOMMA) +} + +func (s *AggListNotSpanContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, i) +} + +func (s *AggListNotSpanContext) AllAgg() []IAggContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IAggContext); ok { + len++ + } + } + + tst := make([]IAggContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IAggContext); ok { + tst[i] = t.(IAggContext) + i++ + } + } + + return tst +} + +func (s *AggListNotSpanContext) Agg(i int) IAggContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IAggContext) +} + +func (s *AggListNotSpanContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AggListNotSpanContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AggListNotSpanContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAggListNotSpan(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) AggListNotSpan() (localctx IAggListNotSpanContext) { + localctx = NewAggListNotSpanContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 104, SPL1ParserRULE_aggListNotSpan) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(609) + p.AggNotSpan() + } + p.SetState(614) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL1ParserCOMMA { + { + p.SetState(610) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(611) + p.Agg() + } + + p.SetState(616) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAggNotSpanContext is an interface to support dynamic dispatch. +type IAggNotSpanContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLikeNotSpan() IIdentLikeNotSpanContext + LPAREN() antlr.TerminalNode + RPAREN() antlr.TerminalNode + AliasClause() IAliasClauseContext + ValueExpr() IValueExprContext + + // IsAggNotSpanContext differentiates from other interfaces. + IsAggNotSpanContext() +} + +type AggNotSpanContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAggNotSpanContext() *AggNotSpanContext { + var p = new(AggNotSpanContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aggNotSpan + return p +} + +func InitEmptyAggNotSpanContext(p *AggNotSpanContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aggNotSpan +} + +func (*AggNotSpanContext) IsAggNotSpanContext() {} + +func NewAggNotSpanContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AggNotSpanContext { + var p = new(AggNotSpanContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_aggNotSpan + + return p +} + +func (s *AggNotSpanContext) GetParser() antlr.Parser { return s.parser } + +func (s *AggNotSpanContext) IdentLikeNotSpan() IIdentLikeNotSpanContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeNotSpanContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeNotSpanContext) +} + +func (s *AggNotSpanContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserLPAREN, 0) +} + +func (s *AggNotSpanContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL1ParserRPAREN, 0) +} + +func (s *AggNotSpanContext) AliasClause() IAliasClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAliasClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAliasClauseContext) +} + +func (s *AggNotSpanContext) ValueExpr() IValueExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueExprContext) +} + +func (s *AggNotSpanContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AggNotSpanContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AggNotSpanContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAggNotSpan(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) AggNotSpan() (localctx IAggNotSpanContext) { + localctx = NewAggNotSpanContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 106, SPL1ParserRULE_aggNotSpan) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(617) + p.IdentLikeNotSpan() + } + p.SetState(623) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserLPAREN { + { + p.SetState(618) + p.Match(SPL1ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(620) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 74, p.GetParserRuleContext()) == 1 { + { + p.SetState(619) + p.ValueExpr() + } + + } else if p.HasError() { // JIM + goto errorExit + } + { + p.SetState(622) + p.Match(SPL1ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + } + p.SetState(626) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserAS { + { + p.SetState(625) + p.AliasClause() + } + + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAliasClauseContext is an interface to support dynamic dispatch. +type IAliasClauseContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AS() antlr.TerminalNode + IdentLike() IIdentLikeContext + + // IsAliasClauseContext differentiates from other interfaces. + IsAliasClauseContext() +} + +type AliasClauseContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAliasClauseContext() *AliasClauseContext { + var p = new(AliasClauseContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aliasClause + return p +} + +func InitEmptyAliasClauseContext(p *AliasClauseContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_aliasClause +} + +func (*AliasClauseContext) IsAliasClauseContext() {} + +func NewAliasClauseContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AliasClauseContext { + var p = new(AliasClauseContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_aliasClause + + return p +} + +func (s *AliasClauseContext) GetParser() antlr.Parser { return s.parser } + +func (s *AliasClauseContext) AS() antlr.TerminalNode { + return s.GetToken(SPL1ParserAS, 0) +} + +func (s *AliasClauseContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *AliasClauseContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AliasClauseContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AliasClauseContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAliasClause(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) AliasClause() (localctx IAliasClauseContext) { + localctx = NewAliasClauseContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 108, SPL1ParserRULE_aliasClause) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(628) + p.Match(SPL1ParserAS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(629) + p.IdentLike() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IByClauseContext is an interface to support dynamic dispatch. +type IByClauseContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + BY() antlr.TerminalNode + FieldExprList() IFieldExprListContext + + // IsByClauseContext differentiates from other interfaces. + IsByClauseContext() +} + +type ByClauseContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyByClauseContext() *ByClauseContext { + var p = new(ByClauseContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_byClause + return p +} + +func InitEmptyByClauseContext(p *ByClauseContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_byClause +} + +func (*ByClauseContext) IsByClauseContext() {} + +func NewByClauseContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ByClauseContext { + var p = new(ByClauseContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_byClause + + return p +} + +func (s *ByClauseContext) GetParser() antlr.Parser { return s.parser } + +func (s *ByClauseContext) BY() antlr.TerminalNode { + return s.GetToken(SPL1ParserBY, 0) +} + +func (s *ByClauseContext) FieldExprList() IFieldExprListContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFieldExprListContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IFieldExprListContext) +} + +func (s *ByClauseContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ByClauseContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ByClauseContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitByClause(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) ByClause() (localctx IByClauseContext) { + localctx = NewByClauseContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 110, SPL1ParserRULE_byClause) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(631) + p.Match(SPL1ParserBY) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(632) + p.FieldExprList() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ITimechartBodyContext is an interface to support dynamic dispatch. +type ITimechartBodyContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsTimechartBodyContext differentiates from other interfaces. + IsTimechartBodyContext() +} + +type TimechartBodyContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyTimechartBodyContext() *TimechartBodyContext { + var p = new(TimechartBodyContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_timechartBody + return p +} + +func InitEmptyTimechartBodyContext(p *TimechartBodyContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_timechartBody +} + +func (*TimechartBodyContext) IsTimechartBodyContext() {} + +func NewTimechartBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TimechartBodyContext { + var p = new(TimechartBodyContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_timechartBody + + return p +} + +func (s *TimechartBodyContext) GetParser() antlr.Parser { return s.parser } + +func (s *TimechartBodyContext) CopyAll(ctx *TimechartBodyContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *TimechartBodyContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *TimechartBodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type TcAggFirstContext struct { + TimechartBodyContext +} + +func NewTcAggFirstContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *TcAggFirstContext { + var p = new(TcAggFirstContext) + + InitEmptyTimechartBodyContext(&p.TimechartBodyContext) + p.parser = parser + p.CopyAll(ctx.(*TimechartBodyContext)) + + return p +} + +func (s *TcAggFirstContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *TcAggFirstContext) AggListNotSpan() IAggListNotSpanContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggListNotSpanContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAggListNotSpanContext) +} + +func (s *TcAggFirstContext) ByClause() IByClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IByClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IByClauseContext) +} + +func (s *TcAggFirstContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitTcAggFirst(s) + + default: + return t.VisitChildren(s) + } +} + +type TcSpanFirstContext struct { + TimechartBodyContext +} + +func NewTcSpanFirstContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *TcSpanFirstContext { + var p = new(TcSpanFirstContext) + + InitEmptyTimechartBodyContext(&p.TimechartBodyContext) + p.parser = parser + p.CopyAll(ctx.(*TimechartBodyContext)) + + return p +} + +func (s *TcSpanFirstContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *TcSpanFirstContext) TimechartSpan() ITimechartSpanContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ITimechartSpanContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ITimechartSpanContext) +} + +func (s *TcSpanFirstContext) AggList() IAggListContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggListContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAggListContext) +} + +func (s *TcSpanFirstContext) ByClause() IByClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IByClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IByClauseContext) +} + +func (s *TcSpanFirstContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitTcSpanFirst(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) TimechartBody() (localctx ITimechartBodyContext) { + localctx = NewTimechartBodyContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 112, SPL1ParserRULE_timechartBody) + var _la int + + p.SetState(644) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 79, p.GetParserRuleContext()) { + case 1: + localctx = NewTcSpanFirstContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + p.SetState(634) + + if !(p.at(SPL1ParserSPAN)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserSPAN)", "")) + goto errorExit + } + { + p.SetState(635) + p.TimechartSpan() + } + { + p.SetState(636) + p.AggList() + } + p.SetState(638) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserBY { + { + p.SetState(637) + p.ByClause() + } + + } + + case 2: + localctx = NewTcAggFirstContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(640) + p.AggListNotSpan() + } + p.SetState(642) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL1ParserBY { + { + p.SetState(641) + p.ByClause() + } + + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ITimechartSpanContext is an interface to support dynamic dispatch. +type ITimechartSpanContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + SPAN() antlr.TerminalNode + SpanAssign() ISpanAssignContext + + // IsTimechartSpanContext differentiates from other interfaces. + IsTimechartSpanContext() +} + +type TimechartSpanContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyTimechartSpanContext() *TimechartSpanContext { + var p = new(TimechartSpanContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_timechartSpan + return p +} + +func InitEmptyTimechartSpanContext(p *TimechartSpanContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_timechartSpan +} + +func (*TimechartSpanContext) IsTimechartSpanContext() {} + +func NewTimechartSpanContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TimechartSpanContext { + var p = new(TimechartSpanContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_timechartSpan + + return p +} + +func (s *TimechartSpanContext) GetParser() antlr.Parser { return s.parser } + +func (s *TimechartSpanContext) SPAN() antlr.TerminalNode { + return s.GetToken(SPL1ParserSPAN, 0) +} + +func (s *TimechartSpanContext) SpanAssign() ISpanAssignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISpanAssignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISpanAssignContext) +} + +func (s *TimechartSpanContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *TimechartSpanContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *TimechartSpanContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitTimechartSpan(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) TimechartSpan() (localctx ITimechartSpanContext) { + localctx = NewTimechartSpanContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 114, SPL1ParserRULE_timechartSpan) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(646) + p.Match(SPL1ParserSPAN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(647) + p.SpanAssign() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISpanAssignContext is an interface to support dynamic dispatch. +type ISpanAssignContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EQ() antlr.TerminalNode + SpanValue() ISpanValueContext + + // IsSpanAssignContext differentiates from other interfaces. + IsSpanAssignContext() +} + +type SpanAssignContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySpanAssignContext() *SpanAssignContext { + var p = new(SpanAssignContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_spanAssign + return p +} + +func InitEmptySpanAssignContext(p *SpanAssignContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_spanAssign +} + +func (*SpanAssignContext) IsSpanAssignContext() {} + +func NewSpanAssignContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SpanAssignContext { + var p = new(SpanAssignContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_spanAssign + + return p +} + +func (s *SpanAssignContext) GetParser() antlr.Parser { return s.parser } + +func (s *SpanAssignContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ, 0) +} + +func (s *SpanAssignContext) SpanValue() ISpanValueContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISpanValueContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISpanValueContext) +} + +func (s *SpanAssignContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SpanAssignContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SpanAssignContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSpanAssign(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SpanAssign() (localctx ISpanAssignContext) { + localctx = NewSpanAssignContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 116, SPL1ParserRULE_spanAssign) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(649) + p.Match(SPL1ParserEQ) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(650) + p.SpanValue() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IRexFieldContext is an interface to support dynamic dispatch. +type IRexFieldContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + FIELD() antlr.TerminalNode + EQ() antlr.TerminalNode + IdentLike() IIdentLikeContext + + // IsRexFieldContext differentiates from other interfaces. + IsRexFieldContext() +} + +type RexFieldContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyRexFieldContext() *RexFieldContext { + var p = new(RexFieldContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_rexField + return p +} + +func InitEmptyRexFieldContext(p *RexFieldContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_rexField +} + +func (*RexFieldContext) IsRexFieldContext() {} + +func NewRexFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RexFieldContext { + var p = new(RexFieldContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_rexField + + return p +} + +func (s *RexFieldContext) GetParser() antlr.Parser { return s.parser } + +func (s *RexFieldContext) FIELD() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELD, 0) +} + +func (s *RexFieldContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ, 0) +} + +func (s *RexFieldContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *RexFieldContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *RexFieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *RexFieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitRexField(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) RexField() (localctx IRexFieldContext) { + localctx = NewRexFieldContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 118, SPL1ParserRULE_rexField) + p.EnterOuterAlt(localctx, 1) + p.SetState(652) + + if !(p.at(SPL1ParserFIELD)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserFIELD)", "")) + goto errorExit + } + { + p.SetState(653) + p.Match(SPL1ParserFIELD) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(654) + p.Match(SPL1ParserEQ) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(655) + p.IdentLike() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IFieldExprListContext is an interface to support dynamic dispatch. +type IFieldExprListContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AllFieldExpr() []IFieldExprContext + FieldExpr(i int) IFieldExprContext + AllCOMMA() []antlr.TerminalNode + COMMA(i int) antlr.TerminalNode + + // IsFieldExprListContext differentiates from other interfaces. + IsFieldExprListContext() +} + +type FieldExprListContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyFieldExprListContext() *FieldExprListContext { + var p = new(FieldExprListContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldExprList + return p +} + +func InitEmptyFieldExprListContext(p *FieldExprListContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldExprList +} + +func (*FieldExprListContext) IsFieldExprListContext() {} + +func NewFieldExprListContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldExprListContext { + var p = new(FieldExprListContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_fieldExprList + + return p +} + +func (s *FieldExprListContext) GetParser() antlr.Parser { return s.parser } + +func (s *FieldExprListContext) AllFieldExpr() []IFieldExprContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IFieldExprContext); ok { + len++ + } + } + + tst := make([]IFieldExprContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IFieldExprContext); ok { + tst[i] = t.(IFieldExprContext) + i++ + } + } + + return tst +} + +func (s *FieldExprListContext) FieldExpr(i int) IFieldExprContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFieldExprContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IFieldExprContext) +} + +func (s *FieldExprListContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL1ParserCOMMA) +} + +func (s *FieldExprListContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, i) +} + +func (s *FieldExprListContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *FieldExprListContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *FieldExprListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitFieldExprList(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) FieldExprList() (localctx IFieldExprListContext) { + localctx = NewFieldExprListContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 120, SPL1ParserRULE_fieldExprList) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(657) + p.FieldExpr() + } + p.SetState(663) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&2041801692151806) != 0 { + p.SetState(661) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserCOMMA: + { + p.SetState(658) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(659) + p.FieldExpr() + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP, SPL1ParserNOT_WORD: + { + p.SetState(660) + p.FieldExpr() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + + p.SetState(665) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IFieldExprContext is an interface to support dynamic dispatch. +type IFieldExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + Star() IStarContext + + // IsFieldExprContext differentiates from other interfaces. + IsFieldExprContext() +} + +type FieldExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyFieldExprContext() *FieldExprContext { + var p = new(FieldExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldExpr + return p +} + +func InitEmptyFieldExprContext(p *FieldExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldExpr +} + +func (*FieldExprContext) IsFieldExprContext() {} + +func NewFieldExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldExprContext { + var p = new(FieldExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_fieldExpr + + return p +} + +func (s *FieldExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *FieldExprContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *FieldExprContext) Star() IStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStarContext) +} + +func (s *FieldExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *FieldExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *FieldExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitFieldExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) FieldExpr() (localctx IFieldExprContext) { + localctx = NewFieldExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 122, SPL1ParserRULE_fieldExpr) + p.SetState(668) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(666) + p.IdentLike() + } + + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(667) + p.Star() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAssignmentContext is an interface to support dynamic dispatch. +type IAssignmentContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + EQ() antlr.TerminalNode + ValueExpr() IValueExprContext + + // IsAssignmentContext differentiates from other interfaces. + IsAssignmentContext() +} + +type AssignmentContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAssignmentContext() *AssignmentContext { + var p = new(AssignmentContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_assignment + return p +} + +func InitEmptyAssignmentContext(p *AssignmentContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_assignment +} + +func (*AssignmentContext) IsAssignmentContext() {} + +func NewAssignmentContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AssignmentContext { + var p = new(AssignmentContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_assignment + + return p +} + +func (s *AssignmentContext) GetParser() antlr.Parser { return s.parser } + +func (s *AssignmentContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *AssignmentContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ, 0) +} + +func (s *AssignmentContext) ValueExpr() IValueExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IValueExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IValueExprContext) +} + +func (s *AssignmentContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AssignmentContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AssignmentContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitAssignment(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) Assignment() (localctx IAssignmentContext) { + localctx = NewAssignmentContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 124, SPL1ParserRULE_assignment) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(670) + p.IdentLike() + } + { + p.SetState(671) + p.Match(SPL1ParserEQ) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(672) + p.ValueExpr() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISpanValueContext is an interface to support dynamic dispatch. +type ISpanValueContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + DURATION() antlr.TerminalNode + IdentLike() IIdentLikeContext + + // IsSpanValueContext differentiates from other interfaces. + IsSpanValueContext() +} + +type SpanValueContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySpanValueContext() *SpanValueContext { + var p = new(SpanValueContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_spanValue + return p +} + +func InitEmptySpanValueContext(p *SpanValueContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_spanValue +} + +func (*SpanValueContext) IsSpanValueContext() {} + +func NewSpanValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SpanValueContext { + var p = new(SpanValueContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_spanValue + + return p +} + +func (s *SpanValueContext) GetParser() antlr.Parser { return s.parser } + +func (s *SpanValueContext) DURATION() antlr.TerminalNode { + return s.GetToken(SPL1ParserDURATION, 0) +} + +func (s *SpanValueContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *SpanValueContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SpanValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SpanValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSpanValue(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SpanValue() (localctx ISpanValueContext) { + localctx = NewSpanValueContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 126, SPL1ParserRULE_spanValue) + p.SetState(676) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserDURATION: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(674) + p.Match(SPL1ParserDURATION) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(675) + p.IdentLike() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ITableItemContext is an interface to support dynamic dispatch. +type ITableItemContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + COMMA() antlr.TerminalNode + Star() IStarContext + IdentLike() IIdentLikeContext + + // IsTableItemContext differentiates from other interfaces. + IsTableItemContext() +} + +type TableItemContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyTableItemContext() *TableItemContext { + var p = new(TableItemContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_tableItem + return p +} + +func InitEmptyTableItemContext(p *TableItemContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_tableItem +} + +func (*TableItemContext) IsTableItemContext() {} + +func NewTableItemContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TableItemContext { + var p = new(TableItemContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_tableItem + + return p +} + +func (s *TableItemContext) GetParser() antlr.Parser { return s.parser } + +func (s *TableItemContext) COMMA() antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, 0) +} + +func (s *TableItemContext) Star() IStarContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStarContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStarContext) +} + +func (s *TableItemContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *TableItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *TableItemContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *TableItemContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitTableItem(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) TableItem() (localctx ITableItemContext) { + localctx = NewTableItemContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 128, SPL1ParserRULE_tableItem) + p.SetState(681) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserCOMMA: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(678) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM, SPL1ParserSTAR_OP: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(679) + p.Star() + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 3) + { + p.SetState(680) + p.IdentLike() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IFieldsSignContext is an interface to support dynamic dispatch. +type IFieldsSignContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Minus() IMinusContext + PLUS() antlr.TerminalNode + + // IsFieldsSignContext differentiates from other interfaces. + IsFieldsSignContext() +} + +type FieldsSignContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyFieldsSignContext() *FieldsSignContext { + var p = new(FieldsSignContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldsSign + return p +} + +func InitEmptyFieldsSignContext(p *FieldsSignContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldsSign +} + +func (*FieldsSignContext) IsFieldsSignContext() {} + +func NewFieldsSignContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldsSignContext { + var p = new(FieldsSignContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_fieldsSign + + return p +} + +func (s *FieldsSignContext) GetParser() antlr.Parser { return s.parser } + +func (s *FieldsSignContext) Minus() IMinusContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMinusContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMinusContext) +} + +func (s *FieldsSignContext) PLUS() antlr.TerminalNode { + return s.GetToken(SPL1ParserPLUS, 0) +} + +func (s *FieldsSignContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *FieldsSignContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *FieldsSignContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitFieldsSign(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) FieldsSign() (localctx IFieldsSignContext) { + localctx = NewFieldsSignContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 130, SPL1ParserRULE_fieldsSign) + p.SetState(685) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserMINUS, SPL1ParserMINUS_TIGHT: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(683) + p.Minus() + } + + case SPL1ParserPLUS: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(684) + p.Match(SPL1ParserPLUS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IFieldsItemContext is an interface to support dynamic dispatch. +type IFieldsItemContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + COMMA() antlr.TerminalNode + IdentLike() IIdentLikeContext + + // IsFieldsItemContext differentiates from other interfaces. + IsFieldsItemContext() +} + +type FieldsItemContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyFieldsItemContext() *FieldsItemContext { + var p = new(FieldsItemContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldsItem + return p +} + +func InitEmptyFieldsItemContext(p *FieldsItemContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_fieldsItem +} + +func (*FieldsItemContext) IsFieldsItemContext() {} + +func NewFieldsItemContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldsItemContext { + var p = new(FieldsItemContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_fieldsItem + + return p +} + +func (s *FieldsItemContext) GetParser() antlr.Parser { return s.parser } + +func (s *FieldsItemContext) COMMA() antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, 0) +} + +func (s *FieldsItemContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *FieldsItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *FieldsItemContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *FieldsItemContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitFieldsItem(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) FieldsItem() (localctx IFieldsItemContext) { + localctx = NewFieldsItemContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 132, SPL1ParserRULE_fieldsItem) + p.SetState(689) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserCOMMA: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(687) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(688) + p.IdentLike() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISortBodyContext is an interface to support dynamic dispatch. +type ISortBodyContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsSortBodyContext differentiates from other interfaces. + IsSortBodyContext() +} + +type SortBodyContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySortBodyContext() *SortBodyContext { + var p = new(SortBodyContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortBody + return p +} + +func InitEmptySortBodyContext(p *SortBodyContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortBody +} + +func (*SortBodyContext) IsSortBodyContext() {} + +func NewSortBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SortBodyContext { + var p = new(SortBodyContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_sortBody + + return p +} + +func (s *SortBodyContext) GetParser() antlr.Parser { return s.parser } + +func (s *SortBodyContext) CopyAll(ctx *SortBodyContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *SortBodyContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortBodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type SortFirstFieldContext struct { + SortBodyContext +} + +func NewSortFirstFieldContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SortFirstFieldContext { + var p = new(SortFirstFieldContext) + + InitEmptySortBodyContext(&p.SortBodyContext) + p.parser = parser + p.CopyAll(ctx.(*SortBodyContext)) + + return p +} + +func (s *SortFirstFieldContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortFirstFieldContext) SortFirstItem() ISortFirstItemContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISortFirstItemContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISortFirstItemContext) +} + +func (s *SortFirstFieldContext) AllSortItem() []ISortItemContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISortItemContext); ok { + len++ + } + } + + tst := make([]ISortItemContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISortItemContext); ok { + tst[i] = t.(ISortItemContext) + i++ + } + } + + return tst +} + +func (s *SortFirstFieldContext) SortItem(i int) ISortItemContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISortItemContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISortItemContext) +} + +func (s *SortFirstFieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSortFirstField(s) + + default: + return t.VisitChildren(s) + } +} + +type SortEmptyContext struct { + SortBodyContext +} + +func NewSortEmptyContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SortEmptyContext { + var p = new(SortEmptyContext) + + InitEmptySortBodyContext(&p.SortBodyContext) + p.parser = parser + p.CopyAll(ctx.(*SortBodyContext)) + + return p +} + +func (s *SortEmptyContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortEmptyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSortEmpty(s) + + default: + return t.VisitChildren(s) + } +} + +type SortLimitContext struct { + SortBodyContext +} + +func NewSortLimitContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *SortLimitContext { + var p = new(SortLimitContext) + + InitEmptySortBodyContext(&p.SortBodyContext) + p.parser = parser + p.CopyAll(ctx.(*SortBodyContext)) + + return p +} + +func (s *SortLimitContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortLimitContext) LimitArg() ILimitArgContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ILimitArgContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ILimitArgContext) +} + +func (s *SortLimitContext) AllSortItem() []ISortItemContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(ISortItemContext); ok { + len++ + } + } + + tst := make([]ISortItemContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(ISortItemContext); ok { + tst[i] = t.(ISortItemContext) + i++ + } + } + + return tst +} + +func (s *SortLimitContext) SortItem(i int) ISortItemContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISortItemContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(ISortItemContext) +} + +func (s *SortLimitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSortLimit(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SortBody() (localctx ISortBodyContext) { + localctx = NewSortBodyContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 134, SPL1ParserRULE_sortBody) + var _la int + + p.SetState(706) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 89, p.GetParserRuleContext()) { + case 1: + localctx = NewSortLimitContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(691) + p.LimitArg() + } + p.SetState(695) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1267470628290558) != 0 { + { + p.SetState(692) + p.SortItem() + } + + p.SetState(697) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + case 2: + localctx = NewSortFirstFieldContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(698) + p.SortFirstItem() + } + p.SetState(702) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1267470628290558) != 0 { + { + p.SetState(699) + p.SortItem() + } + + p.SetState(704) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + case 3: + localctx = NewSortEmptyContext(p, localctx) + p.EnterOuterAlt(localctx, 3) + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISortItemContext is an interface to support dynamic dispatch. +type ISortItemContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + COMMA() antlr.TerminalNode + IdentLike() IIdentLikeContext + Sign() ISignContext + + // IsSortItemContext differentiates from other interfaces. + IsSortItemContext() +} + +type SortItemContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySortItemContext() *SortItemContext { + var p = new(SortItemContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortItem + return p +} + +func InitEmptySortItemContext(p *SortItemContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortItem +} + +func (*SortItemContext) IsSortItemContext() {} + +func NewSortItemContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SortItemContext { + var p = new(SortItemContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_sortItem + + return p +} + +func (s *SortItemContext) GetParser() antlr.Parser { return s.parser } + +func (s *SortItemContext) COMMA() antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, 0) +} + +func (s *SortItemContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *SortItemContext) Sign() ISignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISignContext) +} + +func (s *SortItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortItemContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SortItemContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSortItem(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SortItem() (localctx ISortItemContext) { + localctx = NewSortItemContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 136, SPL1ParserRULE_sortItem) + var _la int + + p.SetState(713) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserCOMMA: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(708) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserPLUS, SPL1ParserMINUS, SPL1ParserMINUS_TIGHT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 2) + p.SetState(710) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&141562122076160) != 0 { + { + p.SetState(709) + p.Sign() + } + + } + { + p.SetState(712) + p.IdentLike() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISortFirstItemContext is an interface to support dynamic dispatch. +type ISortFirstItemContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + COMMA() antlr.TerminalNode + Sign() ISignContext + IdentLike() IIdentLikeContext + SortField() ISortFieldContext + + // IsSortFirstItemContext differentiates from other interfaces. + IsSortFirstItemContext() +} + +type SortFirstItemContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySortFirstItemContext() *SortFirstItemContext { + var p = new(SortFirstItemContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortFirstItem + return p +} + +func InitEmptySortFirstItemContext(p *SortFirstItemContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortFirstItem +} + +func (*SortFirstItemContext) IsSortFirstItemContext() {} + +func NewSortFirstItemContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SortFirstItemContext { + var p = new(SortFirstItemContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_sortFirstItem + + return p +} + +func (s *SortFirstItemContext) GetParser() antlr.Parser { return s.parser } + +func (s *SortFirstItemContext) COMMA() antlr.TerminalNode { + return s.GetToken(SPL1ParserCOMMA, 0) +} + +func (s *SortFirstItemContext) Sign() ISignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISignContext) +} + +func (s *SortFirstItemContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *SortFirstItemContext) SortField() ISortFieldContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISortFieldContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISortFieldContext) +} + +func (s *SortFirstItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortFirstItemContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SortFirstItemContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSortFirstItem(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SortFirstItem() (localctx ISortFirstItemContext) { + localctx = NewSortFirstItemContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 138, SPL1ParserRULE_sortFirstItem) + p.SetState(720) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL1ParserCOMMA: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(715) + p.Match(SPL1ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL1ParserPLUS, SPL1ParserMINUS, SPL1ParserMINUS_TIGHT: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(716) + p.Sign() + } + { + p.SetState(717) + p.IdentLike() + } + + case SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, SPL1ParserIDENT, SPL1ParserNOT_WORD: + p.EnterOuterAlt(localctx, 3) + { + p.SetState(719) + p.SortField() + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISortFieldContext is an interface to support dynamic dispatch. +type ISortFieldContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLikeNotLimit() IIdentLikeNotLimitContext + + // IsSortFieldContext differentiates from other interfaces. + IsSortFieldContext() +} + +type SortFieldContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySortFieldContext() *SortFieldContext { + var p = new(SortFieldContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortField + return p +} + +func InitEmptySortFieldContext(p *SortFieldContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_sortField +} + +func (*SortFieldContext) IsSortFieldContext() {} + +func NewSortFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SortFieldContext { + var p = new(SortFieldContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_sortField + + return p +} + +func (s *SortFieldContext) GetParser() antlr.Parser { return s.parser } + +func (s *SortFieldContext) IdentLikeNotLimit() IIdentLikeNotLimitContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeNotLimitContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeNotLimitContext) +} + +func (s *SortFieldContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SortFieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SortFieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitSortField(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) SortField() (localctx ISortFieldContext) { + localctx = NewSortFieldContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 140, SPL1ParserRULE_sortField) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(722) + p.IdentLikeNotLimit() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ILimitArgContext is an interface to support dynamic dispatch. +type ILimitArgContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsLimitArgContext differentiates from other interfaces. + IsLimitArgContext() +} + +type LimitArgContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyLimitArgContext() *LimitArgContext { + var p = new(LimitArgContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_limitArg + return p +} + +func InitEmptyLimitArgContext(p *LimitArgContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_limitArg +} + +func (*LimitArgContext) IsLimitArgContext() {} + +func NewLimitArgContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *LimitArgContext { + var p = new(LimitArgContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_limitArg + + return p +} + +func (s *LimitArgContext) GetParser() antlr.Parser { return s.parser } + +func (s *LimitArgContext) CopyAll(ctx *LimitArgContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *LimitArgContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *LimitArgContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type LimitNumberContext struct { + LimitArgContext +} + +func NewLimitNumberContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *LimitNumberContext { + var p = new(LimitNumberContext) + + InitEmptyLimitArgContext(&p.LimitArgContext) + p.parser = parser + p.CopyAll(ctx.(*LimitArgContext)) + + return p +} + +func (s *LimitNumberContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *LimitNumberContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *LimitNumberContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitLimitNumber(s) + + default: + return t.VisitChildren(s) + } +} + +type LimitKeywordContext struct { + LimitArgContext +} + +func NewLimitKeywordContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *LimitKeywordContext { + var p = new(LimitKeywordContext) + + InitEmptyLimitArgContext(&p.LimitArgContext) + p.parser = parser + p.CopyAll(ctx.(*LimitArgContext)) + + return p +} + +func (s *LimitKeywordContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *LimitKeywordContext) LIMIT() antlr.TerminalNode { + return s.GetToken(SPL1ParserLIMIT, 0) +} + +func (s *LimitKeywordContext) LimitTail() ILimitTailContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ILimitTailContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ILimitTailContext) +} + +func (s *LimitKeywordContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitLimitKeyword(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) LimitArg() (localctx ILimitArgContext) { + localctx = NewLimitArgContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 142, SPL1ParserRULE_limitArg) + p.SetState(728) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 93, p.GetParserRuleContext()) { + case 1: + localctx = NewLimitKeywordContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + p.SetState(724) + + if !(p.at(SPL1ParserLIMIT)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserLIMIT)", "")) + goto errorExit + } + { + p.SetState(725) + p.Match(SPL1ParserLIMIT) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(726) + p.LimitTail() + } + + case 2: + localctx = NewLimitNumberContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(727) + p.Number() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ILimitTailContext is an interface to support dynamic dispatch. +type ILimitTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EQ() antlr.TerminalNode + Number() INumberContext + + // IsLimitTailContext differentiates from other interfaces. + IsLimitTailContext() +} + +type LimitTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyLimitTailContext() *LimitTailContext { + var p = new(LimitTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_limitTail + return p +} + +func InitEmptyLimitTailContext(p *LimitTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_limitTail +} + +func (*LimitTailContext) IsLimitTailContext() {} + +func NewLimitTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *LimitTailContext { + var p = new(LimitTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_limitTail + + return p +} + +func (s *LimitTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *LimitTailContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL1ParserEQ, 0) +} + +func (s *LimitTailContext) Number() INumberContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INumberContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INumberContext) +} + +func (s *LimitTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *LimitTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *LimitTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitLimitTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) LimitTail() (localctx ILimitTailContext) { + localctx = NewLimitTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 144, SPL1ParserRULE_limitTail) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(730) + p.Match(SPL1ParserEQ) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(731) + p.Number() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IBinItemContext is an interface to support dynamic dispatch. +type IBinItemContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + // IsBinItemContext differentiates from other interfaces. + IsBinItemContext() +} + +type BinItemContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyBinItemContext() *BinItemContext { + var p = new(BinItemContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_binItem + return p +} + +func InitEmptyBinItemContext(p *BinItemContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_binItem +} + +func (*BinItemContext) IsBinItemContext() {} + +func NewBinItemContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *BinItemContext { + var p = new(BinItemContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_binItem + + return p +} + +func (s *BinItemContext) GetParser() antlr.Parser { return s.parser } + +func (s *BinItemContext) CopyAll(ctx *BinItemContext) { + s.CopyFrom(&ctx.BaseParserRuleContext) +} + +func (s *BinItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *BinItemContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +type BinFieldItemContext struct { + BinItemContext +} + +func NewBinFieldItemContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BinFieldItemContext { + var p = new(BinFieldItemContext) + + InitEmptyBinItemContext(&p.BinItemContext) + p.parser = parser + p.CopyAll(ctx.(*BinItemContext)) + + return p +} + +func (s *BinFieldItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *BinFieldItemContext) BinField() IBinFieldContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IBinFieldContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IBinFieldContext) +} + +func (s *BinFieldItemContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitBinFieldItem(s) + + default: + return t.VisitChildren(s) + } +} + +type BinSpanItemContext struct { + BinItemContext +} + +func NewBinSpanItemContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BinSpanItemContext { + var p = new(BinSpanItemContext) + + InitEmptyBinItemContext(&p.BinItemContext) + p.parser = parser + p.CopyAll(ctx.(*BinItemContext)) + + return p +} + +func (s *BinSpanItemContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *BinSpanItemContext) SPAN() antlr.TerminalNode { + return s.GetToken(SPL1ParserSPAN, 0) +} + +func (s *BinSpanItemContext) SpanAssign() ISpanAssignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISpanAssignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISpanAssignContext) +} + +func (s *BinSpanItemContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitBinSpanItem(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) BinItem() (localctx IBinItemContext) { + localctx = NewBinItemContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 146, SPL1ParserRULE_binItem) + p.SetState(739) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 94, p.GetParserRuleContext()) { + case 1: + localctx = NewBinSpanItemContext(p, localctx) + p.EnterOuterAlt(localctx, 1) + p.SetState(733) + + if !(p.at(SPL1ParserSPAN)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL1ParserSPAN)", "")) + goto errorExit + } + { + p.SetState(734) + p.Match(SPL1ParserSPAN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(735) + p.SpanAssign() + } + + case 2: + localctx = NewBinFieldItemContext(p, localctx) + p.EnterOuterAlt(localctx, 2) + { + p.SetState(736) + p.BinField() + } + p.binFieldSeen() + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IBinFieldContext is an interface to support dynamic dispatch. +type IBinFieldContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLikeNotSpan() IIdentLikeNotSpanContext + + // IsBinFieldContext differentiates from other interfaces. + IsBinFieldContext() +} + +type BinFieldContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyBinFieldContext() *BinFieldContext { + var p = new(BinFieldContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_binField + return p +} + +func InitEmptyBinFieldContext(p *BinFieldContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_binField +} + +func (*BinFieldContext) IsBinFieldContext() {} + +func NewBinFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *BinFieldContext { + var p = new(BinFieldContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_binField + + return p +} + +func (s *BinFieldContext) GetParser() antlr.Parser { return s.parser } + +func (s *BinFieldContext) IdentLikeNotSpan() IIdentLikeNotSpanContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeNotSpanContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeNotSpanContext) +} + +func (s *BinFieldContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *BinFieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *BinFieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitBinField(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) BinField() (localctx IBinFieldContext) { + localctx = NewBinFieldContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 148, SPL1ParserRULE_binField) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(741) + p.IdentLikeNotSpan() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IIdentLikeNotSpanContext is an interface to support dynamic dispatch. +type IIdentLikeNotSpanContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IDENT() antlr.TerminalNode + SEARCH() antlr.TerminalNode + WHERE() antlr.TerminalNode + STATS() antlr.TerminalNode + TIMECHART() antlr.TerminalNode + EVAL() antlr.TerminalNode + REX() antlr.TerminalNode + TABLE() antlr.TerminalNode + FIELDS() antlr.TerminalNode + SORT() antlr.TerminalNode + HEAD() antlr.TerminalNode + BIN() antlr.TerminalNode + BY() antlr.TerminalNode + AS() antlr.TerminalNode + LIMIT() antlr.TerminalNode + FIELD() antlr.TerminalNode + AND() antlr.TerminalNode + OR() antlr.TerminalNode + NOT() antlr.TerminalNode + + // IsIdentLikeNotSpanContext differentiates from other interfaces. + IsIdentLikeNotSpanContext() +} + +type IdentLikeNotSpanContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyIdentLikeNotSpanContext() *IdentLikeNotSpanContext { + var p = new(IdentLikeNotSpanContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_identLikeNotSpan + return p +} + +func InitEmptyIdentLikeNotSpanContext(p *IdentLikeNotSpanContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_identLikeNotSpan +} + +func (*IdentLikeNotSpanContext) IsIdentLikeNotSpanContext() {} + +func NewIdentLikeNotSpanContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IdentLikeNotSpanContext { + var p = new(IdentLikeNotSpanContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_identLikeNotSpan + + return p +} + +func (s *IdentLikeNotSpanContext) GetParser() antlr.Parser { return s.parser } + +func (s *IdentLikeNotSpanContext) IDENT() antlr.TerminalNode { + return s.GetToken(SPL1ParserIDENT, 0) +} + +func (s *IdentLikeNotSpanContext) SEARCH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSEARCH, 0) +} + +func (s *IdentLikeNotSpanContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL1ParserWHERE, 0) +} + +func (s *IdentLikeNotSpanContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTATS, 0) +} + +func (s *IdentLikeNotSpanContext) TIMECHART() antlr.TerminalNode { + return s.GetToken(SPL1ParserTIMECHART, 0) +} + +func (s *IdentLikeNotSpanContext) EVAL() antlr.TerminalNode { + return s.GetToken(SPL1ParserEVAL, 0) +} + +func (s *IdentLikeNotSpanContext) REX() antlr.TerminalNode { + return s.GetToken(SPL1ParserREX, 0) +} + +func (s *IdentLikeNotSpanContext) TABLE() antlr.TerminalNode { + return s.GetToken(SPL1ParserTABLE, 0) +} + +func (s *IdentLikeNotSpanContext) FIELDS() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELDS, 0) +} + +func (s *IdentLikeNotSpanContext) SORT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSORT, 0) +} + +func (s *IdentLikeNotSpanContext) HEAD() antlr.TerminalNode { + return s.GetToken(SPL1ParserHEAD, 0) +} + +func (s *IdentLikeNotSpanContext) BIN() antlr.TerminalNode { + return s.GetToken(SPL1ParserBIN, 0) +} + +func (s *IdentLikeNotSpanContext) BY() antlr.TerminalNode { + return s.GetToken(SPL1ParserBY, 0) +} + +func (s *IdentLikeNotSpanContext) AS() antlr.TerminalNode { + return s.GetToken(SPL1ParserAS, 0) +} + +func (s *IdentLikeNotSpanContext) LIMIT() antlr.TerminalNode { + return s.GetToken(SPL1ParserLIMIT, 0) +} + +func (s *IdentLikeNotSpanContext) FIELD() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELD, 0) +} + +func (s *IdentLikeNotSpanContext) AND() antlr.TerminalNode { + return s.GetToken(SPL1ParserAND, 0) +} + +func (s *IdentLikeNotSpanContext) OR() antlr.TerminalNode { + return s.GetToken(SPL1ParserOR, 0) +} + +func (s *IdentLikeNotSpanContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT, 0) +} + +func (s *IdentLikeNotSpanContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *IdentLikeNotSpanContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *IdentLikeNotSpanContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitIdentLikeNotSpan(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) IdentLikeNotSpan() (localctx IIdentLikeNotSpanContext) { + localctx = NewIdentLikeNotSpanContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 150, SPL1ParserRULE_identLikeNotSpan) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(743) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&9420798) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IIdentLikeNotLimitContext is an interface to support dynamic dispatch. +type IIdentLikeNotLimitContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IDENT() antlr.TerminalNode + SEARCH() antlr.TerminalNode + WHERE() antlr.TerminalNode + STATS() antlr.TerminalNode + TIMECHART() antlr.TerminalNode + EVAL() antlr.TerminalNode + REX() antlr.TerminalNode + TABLE() antlr.TerminalNode + FIELDS() antlr.TerminalNode + SORT() antlr.TerminalNode + HEAD() antlr.TerminalNode + BIN() antlr.TerminalNode + BY() antlr.TerminalNode + AS() antlr.TerminalNode + SPAN() antlr.TerminalNode + FIELD() antlr.TerminalNode + AND() antlr.TerminalNode + OR() antlr.TerminalNode + NOT() antlr.TerminalNode + NOT_WORD() antlr.TerminalNode + + // IsIdentLikeNotLimitContext differentiates from other interfaces. + IsIdentLikeNotLimitContext() +} + +type IdentLikeNotLimitContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyIdentLikeNotLimitContext() *IdentLikeNotLimitContext { + var p = new(IdentLikeNotLimitContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_identLikeNotLimit + return p +} + +func InitEmptyIdentLikeNotLimitContext(p *IdentLikeNotLimitContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL1ParserRULE_identLikeNotLimit +} + +func (*IdentLikeNotLimitContext) IsIdentLikeNotLimitContext() {} + +func NewIdentLikeNotLimitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IdentLikeNotLimitContext { + var p = new(IdentLikeNotLimitContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL1ParserRULE_identLikeNotLimit + + return p +} + +func (s *IdentLikeNotLimitContext) GetParser() antlr.Parser { return s.parser } + +func (s *IdentLikeNotLimitContext) IDENT() antlr.TerminalNode { + return s.GetToken(SPL1ParserIDENT, 0) +} + +func (s *IdentLikeNotLimitContext) SEARCH() antlr.TerminalNode { + return s.GetToken(SPL1ParserSEARCH, 0) +} + +func (s *IdentLikeNotLimitContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL1ParserWHERE, 0) +} + +func (s *IdentLikeNotLimitContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL1ParserSTATS, 0) +} + +func (s *IdentLikeNotLimitContext) TIMECHART() antlr.TerminalNode { + return s.GetToken(SPL1ParserTIMECHART, 0) +} + +func (s *IdentLikeNotLimitContext) EVAL() antlr.TerminalNode { + return s.GetToken(SPL1ParserEVAL, 0) +} + +func (s *IdentLikeNotLimitContext) REX() antlr.TerminalNode { + return s.GetToken(SPL1ParserREX, 0) +} + +func (s *IdentLikeNotLimitContext) TABLE() antlr.TerminalNode { + return s.GetToken(SPL1ParserTABLE, 0) +} + +func (s *IdentLikeNotLimitContext) FIELDS() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELDS, 0) +} + +func (s *IdentLikeNotLimitContext) SORT() antlr.TerminalNode { + return s.GetToken(SPL1ParserSORT, 0) +} + +func (s *IdentLikeNotLimitContext) HEAD() antlr.TerminalNode { + return s.GetToken(SPL1ParserHEAD, 0) +} + +func (s *IdentLikeNotLimitContext) BIN() antlr.TerminalNode { + return s.GetToken(SPL1ParserBIN, 0) +} + +func (s *IdentLikeNotLimitContext) BY() antlr.TerminalNode { + return s.GetToken(SPL1ParserBY, 0) +} + +func (s *IdentLikeNotLimitContext) AS() antlr.TerminalNode { + return s.GetToken(SPL1ParserAS, 0) +} + +func (s *IdentLikeNotLimitContext) SPAN() antlr.TerminalNode { + return s.GetToken(SPL1ParserSPAN, 0) +} + +func (s *IdentLikeNotLimitContext) FIELD() antlr.TerminalNode { + return s.GetToken(SPL1ParserFIELD, 0) +} + +func (s *IdentLikeNotLimitContext) AND() antlr.TerminalNode { + return s.GetToken(SPL1ParserAND, 0) +} + +func (s *IdentLikeNotLimitContext) OR() antlr.TerminalNode { + return s.GetToken(SPL1ParserOR, 0) +} + +func (s *IdentLikeNotLimitContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT, 0) +} + +func (s *IdentLikeNotLimitContext) NOT_WORD() antlr.TerminalNode { + return s.GetToken(SPL1ParserNOT_WORD, 0) +} + +func (s *IdentLikeNotLimitContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *IdentLikeNotLimitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *IdentLikeNotLimitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL1Visitor: + return t.VisitIdentLikeNotLimit(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL1Parser) IdentLikeNotLimit() (localctx IIdentLikeNotLimitContext) { + localctx = NewIdentLikeNotLimitContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 152, SPL1ParserRULE_identLikeNotLimit) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(745) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1125899916247038) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +func (p *SPL1Parser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { + switch ruleIndex { + case 5: + var t *SearchOrTailContext = nil + if localctx != nil { + t = localctx.(*SearchOrTailContext) + } + return p.SearchOrTail_Sempred(t, predIndex) + + case 7: + var t *SearchAndPartContext = nil + if localctx != nil { + t = localctx.(*SearchAndPartContext) + } + return p.SearchAndPart_Sempred(t, predIndex) + + case 10: + var t *SearchComparisonTailContext = nil + if localctx != nil { + t = localctx.(*SearchComparisonTailContext) + } + return p.SearchComparisonTail_Sempred(t, predIndex) + + case 13: + var t *RhsTailContext = nil + if localctx != nil { + t = localctx.(*RhsTailContext) + } + return p.RhsTail_Sempred(t, predIndex) + + case 18: + var t *SearchAddTailContext = nil + if localctx != nil { + t = localctx.(*SearchAddTailContext) + } + return p.SearchAddTail_Sempred(t, predIndex) + + case 20: + var t *SearchMulTailContext = nil + if localctx != nil { + t = localctx.(*SearchMulTailContext) + } + return p.SearchMulTail_Sempred(t, predIndex) + + case 22: + var t *SearchPrimaryContext = nil + if localctx != nil { + t = localctx.(*SearchPrimaryContext) + } + return p.SearchPrimary_Sempred(t, predIndex) + + case 23: + var t *SearchTermTailContext = nil + if localctx != nil { + t = localctx.(*SearchTermTailContext) + } + return p.SearchTermTail_Sempred(t, predIndex) + + case 25: + var t *ValueOrTailContext = nil + if localctx != nil { + t = localctx.(*ValueOrTailContext) + } + return p.ValueOrTail_Sempred(t, predIndex) + + case 27: + var t *ValueAndPartContext = nil + if localctx != nil { + t = localctx.(*ValueAndPartContext) + } + return p.ValueAndPart_Sempred(t, predIndex) + + case 30: + var t *ValueComparisonTailContext = nil + if localctx != nil { + t = localctx.(*ValueComparisonTailContext) + } + return p.ValueComparisonTail_Sempred(t, predIndex) + + case 32: + var t *ValueAddTailContext = nil + if localctx != nil { + t = localctx.(*ValueAddTailContext) + } + return p.ValueAddTail_Sempred(t, predIndex) + + case 34: + var t *ValueMulTailContext = nil + if localctx != nil { + t = localctx.(*ValueMulTailContext) + } + return p.ValueMulTail_Sempred(t, predIndex) + + case 36: + var t *ValuePrimaryContext = nil + if localctx != nil { + t = localctx.(*ValuePrimaryContext) + } + return p.ValuePrimary_Sempred(t, predIndex) + + case 56: + var t *TimechartBodyContext = nil + if localctx != nil { + t = localctx.(*TimechartBodyContext) + } + return p.TimechartBody_Sempred(t, predIndex) + + case 59: + var t *RexFieldContext = nil + if localctx != nil { + t = localctx.(*RexFieldContext) + } + return p.RexField_Sempred(t, predIndex) + + case 71: + var t *LimitArgContext = nil + if localctx != nil { + t = localctx.(*LimitArgContext) + } + return p.LimitArg_Sempred(t, predIndex) + + case 73: + var t *BinItemContext = nil + if localctx != nil { + t = localctx.(*BinItemContext) + } + return p.BinItem_Sempred(t, predIndex) + + default: + panic("No predicate with index: " + fmt.Sprint(ruleIndex)) + } +} + +func (p *SPL1Parser) SearchOrTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 0: + return p.at(SPL1ParserOR) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) SearchAndPart_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 1: + return p.at(SPL1ParserAND) + + case 2: + return p.startsTerm() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) SearchComparisonTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 3: + return p.atCompare() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) RhsTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 4: + return p.touchingPrev() + + case 5: + return p.touchingPrev() + + case 6: + return p.touchingPrev() + + case 7: + return p.hyphenTail() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) SearchAddTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 8: + return p.atAdd() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) SearchMulTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 9: + return p.atSearchMul() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) SearchPrimary_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 10: + return p.termStarRun() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) SearchTermTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 11: + return p.touchingPrev() + + case 12: + return p.touchingPrev() + + case 13: + return p.touchingPrev() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) ValueOrTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 14: + return p.at(SPL1ParserOR) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) ValueAndPart_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 15: + return p.at(SPL1ParserAND) + + case 16: + return p.startsTerm() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) ValueComparisonTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 17: + return p.atCompare() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) ValueAddTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 18: + return p.atAdd() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) ValueMulTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 19: + return p.atMul() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) ValuePrimary_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 20: + return p.callAhead() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) TimechartBody_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 21: + return p.at(SPL1ParserSPAN) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) RexField_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 22: + return p.at(SPL1ParserFIELD) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) LimitArg_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 23: + return p.at(SPL1ParserLIMIT) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL1Parser) BinItem_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 24: + return p.at(SPL1ParserSPAN) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} diff --git a/pkg/parser/spl1/gen/spl1_visitor.go b/pkg/parser/spl1/gen/spl1_visitor.go new file mode 100644 index 0000000..e448f61 --- /dev/null +++ b/pkg/parser/spl1/gen/spl1_visitor.go @@ -0,0 +1,351 @@ +// Code generated from pkg/parser/spl1/grammar/SPL1.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl1gen // SPL1 +import "github.com/antlr4-go/antlr/v4" + +// A complete Visitor for a parse tree produced by SPL1Parser. +type SPL1Visitor interface { + antlr.ParseTreeVisitor + + // Visit a parse tree produced by SPL1Parser#stageCommand. + VisitStageCommand(ctx *StageCommandContext) interface{} + + // Visit a parse tree produced by SPL1Parser#stageSearch. + VisitStageSearch(ctx *StageSearchContext) interface{} + + // Visit a parse tree produced by SPL1Parser#stageEnd. + VisitStageEnd(ctx *StageEndContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdSearch. + VisitCmdSearch(ctx *CmdSearchContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdWhere. + VisitCmdWhere(ctx *CmdWhereContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdStats. + VisitCmdStats(ctx *CmdStatsContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdTimechart. + VisitCmdTimechart(ctx *CmdTimechartContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdEval. + VisitCmdEval(ctx *CmdEvalContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdRex. + VisitCmdRex(ctx *CmdRexContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdTable. + VisitCmdTable(ctx *CmdTableContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdFields. + VisitCmdFields(ctx *CmdFieldsContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdSort. + VisitCmdSort(ctx *CmdSortContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdHead. + VisitCmdHead(ctx *CmdHeadContext) interface{} + + // Visit a parse tree produced by SPL1Parser#CmdBin. + VisitCmdBin(ctx *CmdBinContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchExpr. + VisitSearchExpr(ctx *SearchExprContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchOrTail. + VisitSearchOrTail(ctx *SearchOrTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchAnd. + VisitSearchAnd(ctx *SearchAndContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SAndExplicit. + VisitSAndExplicit(ctx *SAndExplicitContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SAndImplicit. + VisitSAndImplicit(ctx *SAndImplicitContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SNotUnary. + VisitSNotUnary(ctx *SNotUnaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SNotPrimary. + VisitSNotPrimary(ctx *SNotPrimaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchComparison. + VisitSearchComparison(ctx *SearchComparisonContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchComparisonTail. + VisitSearchComparisonTail(ctx *SearchComparisonTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SOpString. + VisitSOpString(ctx *SOpStringContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SOpValue. + VisitSOpValue(ctx *SOpValueContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SOpExpr. + VisitSOpExpr(ctx *SOpExprContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchOperandValue. + VisitSearchOperandValue(ctx *SearchOperandValueContext) interface{} + + // Visit a parse tree produced by SPL1Parser#rhsTail. + VisitRhsTail(ctx *RhsTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchOperandExpr. + VisitSearchOperandExpr(ctx *SearchOperandExprContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchOperandUnary. + VisitSearchOperandUnary(ctx *SearchOperandUnaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchOperandPrimary. + VisitSearchOperandPrimary(ctx *SearchOperandPrimaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchAdditive. + VisitSearchAdditive(ctx *SearchAdditiveContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchAddTail. + VisitSearchAddTail(ctx *SearchAddTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchMultiplicative. + VisitSearchMultiplicative(ctx *SearchMultiplicativeContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchMulTail. + VisitSearchMulTail(ctx *SearchMulTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SUnarySign. + VisitSUnarySign(ctx *SUnarySignContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SUnaryPrimary. + VisitSUnaryPrimary(ctx *SUnaryPrimaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimParen. + VisitSPrimParen(ctx *SPrimParenContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimString. + VisitSPrimString(ctx *SPrimStringContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimWord. + VisitSPrimWord(ctx *SPrimWordContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimNumber. + VisitSPrimNumber(ctx *SPrimNumberContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimDuration. + VisitSPrimDuration(ctx *SPrimDurationContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimStarRun. + VisitSPrimStarRun(ctx *SPrimStarRunContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimStar. + VisitSPrimStar(ctx *SPrimStarContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SPrimSubsearch. + VisitSPrimSubsearch(ctx *SPrimSubsearchContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchTermTail. + VisitSearchTermTail(ctx *SearchTermTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueExpr. + VisitValueExpr(ctx *ValueExprContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueOrTail. + VisitValueOrTail(ctx *ValueOrTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueAnd. + VisitValueAnd(ctx *ValueAndContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VAndExplicit. + VisitVAndExplicit(ctx *VAndExplicitContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VAndImplicit. + VisitVAndImplicit(ctx *VAndImplicitContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VNotUnary. + VisitVNotUnary(ctx *VNotUnaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VNotPrimary. + VisitVNotPrimary(ctx *VNotPrimaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueComparison. + VisitValueComparison(ctx *ValueComparisonContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueComparisonTail. + VisitValueComparisonTail(ctx *ValueComparisonTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueAdd. + VisitValueAdd(ctx *ValueAddContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueAddTail. + VisitValueAddTail(ctx *ValueAddTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueMul. + VisitValueMul(ctx *ValueMulContext) interface{} + + // Visit a parse tree produced by SPL1Parser#valueMulTail. + VisitValueMulTail(ctx *ValueMulTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VUnarySign. + VisitVUnarySign(ctx *VUnarySignContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VUnaryPrimary. + VisitVUnaryPrimary(ctx *VUnaryPrimaryContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimParen. + VisitVPrimParen(ctx *VPrimParenContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimCall. + VisitVPrimCall(ctx *VPrimCallContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimWord. + VisitVPrimWord(ctx *VPrimWordContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimString. + VisitVPrimString(ctx *VPrimStringContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimNumber. + VisitVPrimNumber(ctx *VPrimNumberContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimDuration. + VisitVPrimDuration(ctx *VPrimDurationContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimStar. + VisitVPrimStar(ctx *VPrimStarContext) interface{} + + // Visit a parse tree produced by SPL1Parser#VPrimSubsearch. + VisitVPrimSubsearch(ctx *VPrimSubsearchContext) interface{} + + // Visit a parse tree produced by SPL1Parser#subsearch. + VisitSubsearch(ctx *SubsearchContext) interface{} + + // Visit a parse tree produced by SPL1Parser#absentOperand. + VisitAbsentOperand(ctx *AbsentOperandContext) interface{} + + // Visit a parse tree produced by SPL1Parser#comparisonOp. + VisitComparisonOp(ctx *ComparisonOpContext) interface{} + + // Visit a parse tree produced by SPL1Parser#operandStar. + VisitOperandStar(ctx *OperandStarContext) interface{} + + // Visit a parse tree produced by SPL1Parser#star. + VisitStar(ctx *StarContext) interface{} + + // Visit a parse tree produced by SPL1Parser#minus. + VisitMinus(ctx *MinusContext) interface{} + + // Visit a parse tree produced by SPL1Parser#number. + VisitNumber(ctx *NumberContext) interface{} + + // Visit a parse tree produced by SPL1Parser#addOp. + VisitAddOp(ctx *AddOpContext) interface{} + + // Visit a parse tree produced by SPL1Parser#mulOp. + VisitMulOp(ctx *MulOpContext) interface{} + + // Visit a parse tree produced by SPL1Parser#searchMulOp. + VisitSearchMulOp(ctx *SearchMulOpContext) interface{} + + // Visit a parse tree produced by SPL1Parser#sign. + VisitSign(ctx *SignContext) interface{} + + // Visit a parse tree produced by SPL1Parser#identLike. + VisitIdentLike(ctx *IdentLikeContext) interface{} + + // Visit a parse tree produced by SPL1Parser#exprWord. + VisitExprWord(ctx *ExprWordContext) interface{} + + // Visit a parse tree produced by SPL1Parser#aggList. + VisitAggList(ctx *AggListContext) interface{} + + // Visit a parse tree produced by SPL1Parser#agg. + VisitAgg(ctx *AggContext) interface{} + + // Visit a parse tree produced by SPL1Parser#aggListNotSpan. + VisitAggListNotSpan(ctx *AggListNotSpanContext) interface{} + + // Visit a parse tree produced by SPL1Parser#aggNotSpan. + VisitAggNotSpan(ctx *AggNotSpanContext) interface{} + + // Visit a parse tree produced by SPL1Parser#aliasClause. + VisitAliasClause(ctx *AliasClauseContext) interface{} + + // Visit a parse tree produced by SPL1Parser#byClause. + VisitByClause(ctx *ByClauseContext) interface{} + + // Visit a parse tree produced by SPL1Parser#TcSpanFirst. + VisitTcSpanFirst(ctx *TcSpanFirstContext) interface{} + + // Visit a parse tree produced by SPL1Parser#TcAggFirst. + VisitTcAggFirst(ctx *TcAggFirstContext) interface{} + + // Visit a parse tree produced by SPL1Parser#timechartSpan. + VisitTimechartSpan(ctx *TimechartSpanContext) interface{} + + // Visit a parse tree produced by SPL1Parser#spanAssign. + VisitSpanAssign(ctx *SpanAssignContext) interface{} + + // Visit a parse tree produced by SPL1Parser#rexField. + VisitRexField(ctx *RexFieldContext) interface{} + + // Visit a parse tree produced by SPL1Parser#fieldExprList. + VisitFieldExprList(ctx *FieldExprListContext) interface{} + + // Visit a parse tree produced by SPL1Parser#fieldExpr. + VisitFieldExpr(ctx *FieldExprContext) interface{} + + // Visit a parse tree produced by SPL1Parser#assignment. + VisitAssignment(ctx *AssignmentContext) interface{} + + // Visit a parse tree produced by SPL1Parser#spanValue. + VisitSpanValue(ctx *SpanValueContext) interface{} + + // Visit a parse tree produced by SPL1Parser#tableItem. + VisitTableItem(ctx *TableItemContext) interface{} + + // Visit a parse tree produced by SPL1Parser#fieldsSign. + VisitFieldsSign(ctx *FieldsSignContext) interface{} + + // Visit a parse tree produced by SPL1Parser#fieldsItem. + VisitFieldsItem(ctx *FieldsItemContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SortLimit. + VisitSortLimit(ctx *SortLimitContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SortFirstField. + VisitSortFirstField(ctx *SortFirstFieldContext) interface{} + + // Visit a parse tree produced by SPL1Parser#SortEmpty. + VisitSortEmpty(ctx *SortEmptyContext) interface{} + + // Visit a parse tree produced by SPL1Parser#sortItem. + VisitSortItem(ctx *SortItemContext) interface{} + + // Visit a parse tree produced by SPL1Parser#sortFirstItem. + VisitSortFirstItem(ctx *SortFirstItemContext) interface{} + + // Visit a parse tree produced by SPL1Parser#sortField. + VisitSortField(ctx *SortFieldContext) interface{} + + // Visit a parse tree produced by SPL1Parser#LimitKeyword. + VisitLimitKeyword(ctx *LimitKeywordContext) interface{} + + // Visit a parse tree produced by SPL1Parser#LimitNumber. + VisitLimitNumber(ctx *LimitNumberContext) interface{} + + // Visit a parse tree produced by SPL1Parser#limitTail. + VisitLimitTail(ctx *LimitTailContext) interface{} + + // Visit a parse tree produced by SPL1Parser#BinSpanItem. + VisitBinSpanItem(ctx *BinSpanItemContext) interface{} + + // Visit a parse tree produced by SPL1Parser#BinFieldItem. + VisitBinFieldItem(ctx *BinFieldItemContext) interface{} + + // Visit a parse tree produced by SPL1Parser#binField. + VisitBinField(ctx *BinFieldContext) interface{} + + // Visit a parse tree produced by SPL1Parser#identLikeNotSpan. + VisitIdentLikeNotSpan(ctx *IdentLikeNotSpanContext) interface{} + + // Visit a parse tree produced by SPL1Parser#identLikeNotLimit. + VisitIdentLikeNotLimit(ctx *IdentLikeNotLimitContext) interface{} +} diff --git a/pkg/parser/spl1/grammar/SPL1.g4 b/pkg/parser/spl1/grammar/SPL1.g4 new file mode 100644 index 0000000..b085eff --- /dev/null +++ b/pkg/parser/spl1/grammar/SPL1.g4 @@ -0,0 +1,740 @@ +// SPL1.g4 — classic Splunk SPL, parsed by ANTLR. +// +// The generated Go parser replaces the hand-written lexer and recursive +// descent parser. Three things stay outside the grammar on purpose: +// +// - Stage sequencing. `stageCommand`/`stageSearch` are entry rules the Go +// driver calls one stage at a time so a semantic error in stage 1 is +// reported before a grammar error in stage 3, and so an unimplemented +// command name can be classified before it is parsed. +// - String decoding and value slicing. The lexer keeps raw token text; the +// lowering code slices values from the source and decodes escapes. +// - Command bodies that are empty on purpose (`table`, `fields`, `sort`, +// `bin`) are accepted by the grammar and refused by the lowering at the +// command token, matching the hand parser's positions. +// +// Every operand and every keyword value is required in the grammar. ANTLR +// then rejects a missing operand at the very token where the hand parser +// rejects it, and the fail-fast error listener aborts at that first error, so +// no later grammar error can overtake it. +// +// Classic SPL is context sensitive: an unquoted word on the right of a +// comparison in a search expression is a literal value, while the same word +// in `where`, `eval`, or an aggregate argument is a field reference. The +// grammar keeps two parallel expression rule sets (`search*` and `value*`) +// instead of a mutable mode flag. Keyword tokens stay usable as identifiers +// through `identLike`, so `by=1`, `table where`, and `eval search=...` work. + +grammar SPL1; + +// Tight token types. The driver retypes a STAR that touches a preceding word +// as STAR_TERM, because the wildcard belongs to the search term (`error*`), and +// the STAR, MINUS, and NUMBER tokens that begin a literal value run on the +// right of a comparison as STAR_TIGHT, MINUS_TIGHT, and NUMBER_TIGHT (see +// tight.go). It also retypes NOT after an arithmetic or comparison operator as +// NOT_WORD, because there the word is a field name (`1+not`), while at the +// start of an expression it is the negation operator and commits. These are +// not lexer rules: the lexer emits the ordinary token, and the retyping is a +// token-stream pass, because the decision depends on the surrounding tokens, +// past the end of the token the lexer is matching. +tokens { NUMBER_TIGHT, STAR_TIGHT, MINUS_TIGHT, STAR_TERM, STAR_OP, NOT_WORD } + +@parser::members { +// la returns the token type at lookahead k. +func (p *SPL1Parser) la(k int) int { return p.GetTokenStream().LA(k) } + +// tok returns the token at lookahead k; k may be negative. +func (p *SPL1Parser) tok(k int) antlr.Token { return p.GetTokenStream().LT(k) } + +// at reports whether the current token has type t. +func (p *SPL1Parser) at(t int) bool { return p.la(1) == t } + +// isIdentLike reports whether token type t is accepted by identLike. +func (p *SPL1Parser) isIdentLike(t int) bool { + switch t { + case SPL1ParserIDENT, SPL1ParserSEARCH, SPL1ParserWHERE, SPL1ParserSTATS, + SPL1ParserTIMECHART, SPL1ParserEVAL, SPL1ParserREX, SPL1ParserTABLE, + SPL1ParserFIELDS, SPL1ParserSORT, SPL1ParserHEAD, SPL1ParserBIN, + SPL1ParserBY, SPL1ParserAS, SPL1ParserSPAN, SPL1ParserLIMIT, + SPL1ParserFIELD, SPL1ParserAND, SPL1ParserOR, SPL1ParserNOT, + SPL1ParserNOT_WORD: + return true + } + return false +} + +// touches reports whether the tokens at k and k+1 are adjacent in the source. +// Token offsets are rune indexes, so this is exact. +func (p *SPL1Parser) touches(k int) bool { + a, b := p.tok(k), p.tok(k+1) + if a == nil || b == nil { + return false + } + return a.GetStop()+1 == b.GetStart() +} + +// touchingPrev reports whether the current token starts exactly where the +// last consumed token ended. +func (p *SPL1Parser) touchingPrev() bool { + prev, cur := p.tok(-1), p.tok(1) + if prev == nil || cur == nil { + return false + } + return prev.GetStop()+1 == cur.GetStart() +} + +// startsTerm is the implicit-AND boundary. Every word starts a term except +// the conjunction and clause keywords, matching the hand parser. Tight tokens +// are the same spellings as their plain forms, so they start a term too. +func (p *SPL1Parser) startsTerm() bool { + t := p.la(1) + switch t { + case SPL1ParserAND, SPL1ParserOR, SPL1ParserBY, SPL1ParserAS: + return false + case SPL1ParserSTAR_OP: + // A star with an operand on its left multiplies; it never starts an + // implicit-AND term. + return false + case SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM: + // After a completed operand a star multiplies; it starts a new + // implicit-AND term only where no operand precedes it (`where * a`). + // Without this, `where (a*)` parses as `a AND TRUE` instead of + // reporting the missing operand after the star. + return !p.prevEndsOperand() + case SPL1ParserSTRING, SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT, + SPL1ParserDURATION, SPL1ParserLPAREN, SPL1ParserLBRACKET: + return true + } + return p.isIdentLike(t) +} + +// prevEndsOperand reports whether the last consumed token can end an operand, +// so a following star is a multiplication operator. The token stream is the +// tight one, so a retyped star still reads as a star. +func (p *SPL1Parser) prevEndsOperand() bool { + prev := p.tok(-1) + if prev == nil { + return false + } + switch t := prev.GetTokenType(); t { + case SPL1ParserSTRING, SPL1ParserNUMBER, SPL1ParserNUMBER_TIGHT, + SPL1ParserDURATION, SPL1ParserRPAREN, SPL1ParserRBRACKET, + SPL1ParserSTAR, SPL1ParserSTAR_TIGHT, SPL1ParserSTAR_TERM: + return true + default: + return p.isIdentLike(t) + } +} + +// isStar, isNumber, and isMinus accept every spelling of a token, wherever the +// term, value-run, and operator distinctions do not matter. +func (p *SPL1Parser) isStar(t int) bool { + return t == SPL1ParserSTAR || t == SPL1ParserSTAR_TIGHT || + t == SPL1ParserSTAR_TERM +} + +func (p *SPL1Parser) isNumber(t int) bool { + return t == SPL1ParserNUMBER || t == SPL1ParserNUMBER_TIGHT +} + +func (p *SPL1Parser) isMinus(t int) bool { + return t == SPL1ParserMINUS || t == SPL1ParserMINUS_TIGHT +} + +// callAhead reports whether an identifier is followed by '('. Adjacency is +// not required: `eval x=lower (msg)` is a call. +func (p *SPL1Parser) callAhead() bool { return p.la(2) == SPL1ParserLPAREN } + +// atNot, atCompare, atAdd, and atMul report whether the current token is an +// operator of that kind. The binary and unary rules gate on them so the +// parser commits to the operator and blames the missing operand after it, +// which is where the hand parser reports. +func (p *SPL1Parser) atNot() bool { return p.at(SPL1ParserNOT) || p.at(SPL1ParserBANG) } + +func (p *SPL1Parser) atCompare() bool { + switch p.la(1) { + case SPL1ParserEQ2, SPL1ParserEQ, SPL1ParserNE, SPL1ParserLT, SPL1ParserLE, + SPL1ParserGT, SPL1ParserGE: + return true + } + return false +} + +func (p *SPL1Parser) atAdd() bool { + return p.at(SPL1ParserPLUS) || p.at(SPL1ParserMINUS) || p.at(SPL1ParserMINUS_TIGHT) +} + +func (p *SPL1Parser) atMul() bool { + t := p.la(1) + return t == SPL1ParserSTAR_OP || p.isStar(t) || + t == SPL1ParserSLASH || t == SPL1ParserPERCENT +} + +// atSearchMul is atMul for term position, where an adjacent STAR is part of +// the preceding term (`error*`) rather than a multiplication operator. +func (p *SPL1Parser) atSearchMul() bool { + t := p.la(1) + return t == SPL1ParserSTAR || t == SPL1ParserSTAR_TIGHT || + t == SPL1ParserSTAR_OP || + t == SPL1ParserSLASH || t == SPL1ParserPERCENT +} + +// parseAbort is the panic value for a grammar action that ends the parse at a +// token. The front-end recovers it structurally and maps the token through its +// SourceMap; generated code cannot import the front-end, so the methods below +// are the whole contract. +type parseAbort struct { + token antlr.Token + code string + message string +} + +func (a parseAbort) AbortToken() antlr.Token { return a.token } +func (a parseAbort) AbortCode() string { return a.code } +func (a parseAbort) AbortMessage() string { return a.message } + +// abortMissingOperand ends the parse at the token where an operand was +// required, which is where the hand parser fails. +func (p *SPL1Parser) abortMissingOperand() { + t := p.tok(1) + message := "expected an expression, found end of query" + if t != nil && t.GetTokenType() != antlr.TokenEOF { + message = "expected an expression, found " + fmt.Sprintf("%q", t.GetText()) + } + panic(parseAbort{token: t, code: "syntax", message: message}) +} + +// binFieldSeen refuses a second `bin` field at that field's token, before the +// rest of the stage is parsed. The hand parser reports the extra field in +// source order, so a later grammar error must not be able to overtake it. The +// completed siblings live in the enclosing command context's children. +func (p *SPL1Parser) binFieldSeen() { + t := p.tok(-1) + cur := p.GetParserRuleContext() + parent := cur.GetParent() + if t == nil || parent == nil { + return + } + for _, child := range parent.GetChildren() { + prev, ok := child.(*BinFieldItemContext) + if !ok || prev == cur { + continue + } + panic(parseAbort{ + token: t, + code: "syntax", + message: fmt.Sprintf("bin accepts exactly one field; found %q after %q", + t.GetText(), prev.BinField().GetStart().GetText()), + }) + } +} + +// abortSubsearch refuses a subsearch at its opening bracket, before the rest of +// the stage is parsed, matching the hand parser's fail-fast priority. +func (p *SPL1Parser) abortSubsearch() { + panic(parseAbort{ + token: p.tok(-1), + code: "unsupported-subsearch", + message: "subsearches are not supported", + }) +} + +// termStarRun reports whether a '*' begins a tight free-text wildcard run +// such as `*error*`, as opposed to a bare wildcard. +func (p *SPL1Parser) termStarRun() bool { + if !p.isStar(p.la(1)) || !p.touches(1) { + return false + } + return p.isIdentLike(p.la(2)) || p.isNumber(p.la(2)) +} + +// hyphenTail reports whether a '-' continues a value run: it must touch the +// previous component and be followed, without a space, by a word, number, or +// wildcard. +func (p *SPL1Parser) hyphenTail() bool { + return p.touchingPrev() && p.touches(1) && + (p.isIdentLike(p.la(2)) || p.isNumber(p.la(2)) || p.isStar(p.la(2))) +} +} + +// --- entry rules --------------------------------------------------------- +// +// The driver calls one of these per stage and inspects stageEnd to decide +// whether another stage follows. + +stageCommand : command stageEnd ; + +// An implicit search always has an expression; empty input and a leading pipe +// are handled by the driver before this rule is called. +stageSearch : searchExpr stageEnd ; + +stageEnd : PIPE | EOF ; + +command + : SEARCH searchExpr? #CmdSearch + | WHERE valueExpr? #CmdWhere + | STATS aggList byClause? #CmdStats + | TIMECHART timechartBody #CmdTimechart + | EVAL assignment (COMMA assignment)* #CmdEval + | REX rexField? STRING #CmdRex + | TABLE tableItem* #CmdTable + | FIELDS fieldsSign? fieldsItem* #CmdFields + | SORT sortBody #CmdSort + | HEAD limitArg? #CmdHead + | BIN binItem* #CmdBin + ; + +// Every operator rule below is gated on its own token type. Without the gate, +// ANTLR predicts the whole loop with unlimited lookahead and, seeing that the +// operand is missing, refuses to enter the loop; the error then lands on the +// operator. The hand parser commits to the operator and reports the missing +// operand after it (`a AND` at end of query, `a = = b` at the second '='). +// The gates make the grammar do the same, and they keep `a * b` arithmetic +// instead of letting '*' start an implicit-AND term. + +// --- search expression: comparison RHS values are literals --------------- + +searchExpr + : searchAnd searchOrTail* + ; + +searchOrTail + : {p.at(SPL1ParserOR)}? OR (searchAnd | absentOperand) + ; + +searchAnd + : searchNot searchAndPart* + ; + +searchAndPart + : {p.at(SPL1ParserAND)}? AND (searchNot | absentOperand) #SAndExplicit + | {p.startsTerm()}? searchNot #SAndImplicit + ; + +searchNot + : (NOT | BANG) (searchNot | absentOperand) #SNotUnary + | searchComparison #SNotPrimary + ; + +searchComparison + : searchAdditive searchComparisonTail* + ; + +searchComparisonTail + : {p.atCompare()}? comparisonOp (searchOperand | absentOperand) + ; + +// A comparison RHS is a quoted string, a tight literal value run, or a search +// expression. The three alternatives must be decided by token type alone. +// ANTLR's SLL prediction never uses a semantic predicate to prune a +// simulation, so alternatives that share a first token and differ only by +// predicates cannot be told apart: every surviving alternative dies together +// at the end of the stage and the parser reports no viable alternative. That +// is why the value-run starts are distinct token types rather than a predicate +// over STAR, MINUS, and NUMBER. searchOperandExpr excludes those types, so the +// first sets stay disjoint and no predicate is needed at this decision. +searchOperand + : STRING #SOpString + | searchOperandValue #SOpValue + | searchOperandExpr #SOpExpr + ; + +// A value run starts on a word, or on a wildcard, hyphen, or number the driver +// marked tight, and runs on while its components touch. The alternatives are +// disjoint by token type. +searchOperandValue + : identLike rhsTail* + | NUMBER_TIGHT rhsTail* + | STAR_TIGHT (identLike | number | minus (identLike | number | star)) rhsTail* + | MINUS_TIGHT (identLike | star) rhsTail* + ; + +// Components must touch; whitespace ends the run. +rhsTail + : {p.touchingPrev()}? star + | {p.touchingPrev()}? identLike + | {p.touchingPrev()}? number + | {p.hyphenTail()}? minus (identLike | number | star) + ; + +// The expression alternative of a comparison RHS: an additive chain whose +// first operand can never begin a value run, so the alternatives above keep +// their own first tokens. Later operands are ordinary search expressions. +searchOperandExpr + : searchOperandUnary searchMulTail* searchAddTail* + ; + +searchOperandUnary + : (MINUS | PLUS) (searchUnary | absentOperand) + | searchOperandPrimary + ; + +searchOperandPrimary + : LPAREN searchExpr RPAREN + | DURATION + | NUMBER + | STAR + | subsearch + ; + +searchAdditive + : searchMultiplicative searchAddTail* + ; + +searchAddTail + : {p.atAdd()}? addOp (searchMultiplicative | absentOperand) + ; + +searchMultiplicative + : searchUnary searchMulTail* + ; + +searchMulTail + : {p.atSearchMul()}? searchMulOp (searchUnary | absentOperand) + ; + +searchUnary + : sign (searchUnary | absentOperand) #SUnarySign + | searchPrimary #SUnaryPrimary + ; + +searchPrimary + : LPAREN searchExpr RPAREN #SPrimParen + | STRING #SPrimString + | exprWord searchTermTail* #SPrimWord + | number #SPrimNumber + | DURATION #SPrimDuration + | {p.termStarRun()}? star searchTermTail+ #SPrimStarRun + | operandStar #SPrimStar + | subsearch #SPrimSubsearch + ; + +// Free-text runs merge only adjacent wildcards and words: `a-b` stays +// arithmetic in term position. The driver retypes a STAR that touches the +// preceding word as STAR_TERM, so `a* | stats` is the term `a*` followed by a +// stage; without that the star could also begin a multiplication whose operand +// is missing. +searchTermTail + : {p.touchingPrev()}? STAR_TERM + | {p.touchingPrev()}? identLike + | {p.touchingPrev()}? number + ; + +// --- value expression: bare words are field references ------------------- + +valueExpr + : valueAnd valueOrTail* + ; + +valueOrTail + : {p.at(SPL1ParserOR)}? OR (valueAnd | absentOperand) + ; + +valueAnd + : valueNot valueAndPart* + ; + +valueAndPart + : {p.at(SPL1ParserAND)}? AND (valueNot | absentOperand) #VAndExplicit + | {p.startsTerm()}? valueNot #VAndImplicit + ; + +valueNot + : (NOT | BANG) (valueNot | absentOperand) #VNotUnary + | valueComparison #VNotPrimary + ; + +valueComparison + : valueAdd valueComparisonTail* + ; + +valueComparisonTail + : {p.atCompare()}? comparisonOp (valueAdd | absentOperand) + ; + +valueAdd + : valueMul valueAddTail* + ; + +valueAddTail + : {p.atAdd()}? addOp (valueMul | absentOperand) + ; + +valueMul + : valueUnary valueMulTail* + ; + +valueMulTail + : {p.atMul()}? mulOp (valueUnary | absentOperand) + ; + +valueUnary + : sign (valueUnary | absentOperand) #VUnarySign + | valuePrimary #VUnaryPrimary + ; + +valuePrimary + : LPAREN valueExpr RPAREN #VPrimParen + | {p.callAhead()}? exprWord LPAREN (valueExpr (COMMA valueExpr)*)? RPAREN #VPrimCall + | exprWord #VPrimWord + | STRING #VPrimString + | number #VPrimNumber + | DURATION #VPrimDuration + | operandStar #VPrimStar + | subsearch #VPrimSubsearch + ; + +// A subsearch consumes the rest of its stage so the lowering layer can refuse +// it at the bracket instead of reporting a grammar error further in. +subsearch + : LBRACKET {p.abortSubsearch()} (~(PIPE | EOF))* + ; + +// absentOperand keeps every expression rule total: at a token that cannot +// begin a primary it ends the parse immediately, at the token where the hand +// parser fails. Totality is what lets prediction commit to an operator whose +// operand is missing, so the first diagnostic stays at the operand position +// instead of moving back to the operator. +absentOperand + : {p.abortMissingOperand()} (EQ2 | EQ | NE | LT | LE | GT | GE | COMMA | RPAREN | RBRACKET | PIPE | EOF) + ; + +comparisonOp : EQ2 | EQ | NE | LT | LE | GT | GE ; + +// `star`, `minus`, and `number` accept both spellings of a token, because the +// driver retypes only the ones that begin a value run. Every rule below them +// is shared by the value-run and expression reads, and none of them changes +// meaning with the tightness. +// +// STAR_OP is a star the driver retyped because an operand precedes it, so it +// can only be a multiplication operator. Operand positions use operandStar, so +// prediction cannot read a multiplication as the start of an implicit-AND term +// (`a * * | ...`); field lists keep accepting every spelling. +operandStar : STAR | STAR_TIGHT | STAR_TERM ; +star : operandStar | STAR_OP ; +minus : MINUS | MINUS_TIGHT ; +number : NUMBER | NUMBER_TIGHT ; + +addOp : PLUS | minus ; +mulOp : star | SLASH | PERCENT ; +// Term-position multiplication excludes STAR_TERM: there the star already +// belongs to the preceding term. +searchMulOp : STAR | STAR_TIGHT | STAR_OP | SLASH | PERCENT ; +sign : minus | PLUS ; + +// --- identifiers and command bodies -------------------------------------- + +identLike + : IDENT | SEARCH | WHERE | STATS | TIMECHART | EVAL | REX | TABLE | FIELDS + | SORT | HEAD | BIN | BY | AS | SPAN | LIMIT | FIELD | AND | OR | NOT + | NOT_WORD + ; + +// exprWord is identLike where a bare `not` cannot start an expression: there +// the keyword is the negation operator, and the driver retypes a `not` that +// follows an operator as NOT_WORD so it stays available as a field name. +exprWord + : IDENT | SEARCH | WHERE | STATS | TIMECHART | EVAL | REX | TABLE | FIELDS + | SORT | HEAD | BIN | BY | AS | SPAN | LIMIT | FIELD | AND | OR | NOT_WORD + ; + +aggList + : agg (COMMA agg)* + ; + +agg + : identLike (LPAREN valueExpr? RPAREN)? aliasClause? + ; + +// `timechart` may not take an aggregation named `span`: the first word after +// `timechart` is either the span keyword or an aggregation. +aggListNotSpan + : aggNotSpan (COMMA agg)* + ; + +aggNotSpan + : identLikeNotSpan (LPAREN valueExpr? RPAREN)? aliasClause? + ; + +aliasClause + : AS identLike + ; + +byClause + : BY fieldExprList + ; + +timechartBody + : {p.at(SPL1ParserSPAN)}? timechartSpan aggList byClause? #TcSpanFirst + | aggListNotSpan byClause? #TcAggFirst + ; + +timechartSpan + : SPAN spanAssign + ; + +spanAssign + : EQ spanValue + ; + +rexField + : {p.at(SPL1ParserFIELD)}? FIELD EQ identLike + ; + +fieldExprList + : fieldExpr (COMMA fieldExpr | fieldExpr)* + ; + +fieldExpr + : identLike + | star + ; + +assignment + : identLike EQ valueExpr + ; + +spanValue + : DURATION + | identLike + ; + +tableItem + : COMMA + | star + | identLike + ; + +fieldsSign + : minus + | PLUS + ; + +fieldsItem + : COMMA + | identLike + ; + +sortBody + : limitArg sortItem* #SortLimit + | sortFirstItem sortItem* #SortFirstField + | #SortEmpty + ; + +sortItem + : COMMA + | sign? identLike + ; + +// `limit` is the keyword only in the first body position; after a limit or a +// field it is an ordinary field name, so only the first item excludes it. +// A sign rules the limit reading out, so `sort -limit` is a descending sort on +// a field named `limit` and `sort -not` on the retyped NOT_WORD. +sortFirstItem + : COMMA + | sign identLike + | sortField + ; + +sortField + : identLikeNotLimit + ; + +limitArg + : {p.at(SPL1ParserLIMIT)}? LIMIT limitTail #LimitKeyword + | number #LimitNumber + ; + +limitTail + : EQ number + ; + +binItem + : {p.at(SPL1ParserSPAN)}? SPAN spanAssign #BinSpanItem + | binField {p.binFieldSeen()} #BinFieldItem + ; + +// `span` is always the keyword inside `bin`, so it is not a field name here. +binField + : identLikeNotSpan + ; + +// `span` excluded: `bin span` starts a span assignment, never a field. +identLikeNotSpan + : IDENT | SEARCH | WHERE | STATS | TIMECHART | EVAL | REX | TABLE | FIELDS + | SORT | HEAD | BIN | BY | AS | LIMIT | FIELD | AND | OR | NOT + ; + +// `limit` excluded: `sort limit` starts the limit argument, never a field. +identLikeNotLimit + : IDENT | SEARCH | WHERE | STATS | TIMECHART | EVAL | REX | TABLE | FIELDS + | SORT | HEAD | BIN | BY | AS | SPAN | FIELD | AND | OR | NOT | NOT_WORD + ; + +// --- lexer --------------------------------------------------------------- + +// Keywords are ASCII fragments rather than the caseInsensitive option so the +// generated automaton is stable across ANTLR versions and targets. +SEARCH : [sS][eE][aA][rR][cC][hH] ; +WHERE : [wW][hH][eE][rR][eE] ; +STATS : [sS][tT][aA][tT][sS] ; +TIMECHART : [tT][iI][mM][eE][cC][hH][aA][rR][tT] ; +EVAL : [eE][vV][aA][lL] ; +REX : [rR][eE][xX] ; +TABLE : [tT][aA][bB][lL][eE] ; +FIELDS : [fF][iI][eE][lL][dD][sS] ; +SORT : [sS][oO][rR][tT] ; +HEAD : [hH][eE][aA][dD] ; +BIN : [bB][iI][nN] ; +BY : [bB][yY] ; +AS : [aA][sS] ; +SPAN : [sS][pP][aA][nN] ; +LIMIT : [lL][iI][mM][iI][tT] ; +FIELD : [fF][iI][eE][lL][dD] ; +AND : [aA][nN][dD] ; +OR : [oO][rR] ; +NOT : [nN][oO][tT] ; + +// Durations are declared before numbers; maximal munch keeps `1mon` whole. +DURATION : DIGITS ('.' DIGITS)? EXPONENT? UNIT ; +NUMBER : DIGITS ('.' DIGITS)? EXPONENT? ; + +STRING : '"' DQ_BODY '"' | '\'' SQ_BODY '\'' ; + +// A backslash escapes only the matching quote. Any other backslash stays a +// literal, including a run of them: `"a\\"` is unterminated because the last +// backslash escapes the closing quote. +fragment DQ_BODY : ('\\'+ '"' | '\\'+ ~["\\] | ~["\\])* ; +fragment SQ_BODY : ('\\'+ '\'' | '\\'+ ~['\\] | ~['\\])* ; + +IDENT : [_@A-Za-z] [_@A-Za-z0-9.:]* ; + +EQ2 : '==' ; +NE : '!=' ; +LE : '<=' ; +GE : '>=' ; +EQ : '=' ; +LT : '<' ; +GT : '>' ; +BANG : '!' ; +PIPE : '|' ; +COMMA : ',' ; +LPAREN : '(' ; +RPAREN : ')' ; +LBRACKET : '[' ; +RBRACKET : ']' ; +PLUS : '+' ; +MINUS : '-' ; +STAR : '*' ; +SLASH : '/' ; +PERCENT : '%' ; + +WS : [ \t\r\n]+ -> skip ; + +// The lexer never reports errors itself; the invalid-token pass in Go reports +// the first UNKNOWN token in source order with an exact position. +UNKNOWN : . ; + +fragment DIGITS : [0-9]+ ; +fragment EXPONENT : [eE] [+-]? [0-9]+ ; +fragment UNIT : 'mon' | 'ms' | [smhdwy] ; diff --git a/pkg/parser/spl1/lexer.go b/pkg/parser/spl1/lexer.go index ba20a33..3fb524e 100644 --- a/pkg/parser/spl1/lexer.go +++ b/pkg/parser/spl1/lexer.go @@ -6,8 +6,12 @@ import ( "strings" "unicode/utf8" + "github.com/antlr4-go/antlr/v4" + "github.com/be-thomas/openspl/pkg/ast" "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" + "github.com/be-thomas/openspl/pkg/parser/spl1/gen" ) // Kind is a lexical token kind. @@ -112,245 +116,201 @@ func (t Token) describe() string { return t.Kind.String() } -type lexer struct { - src string - i int - line int - col int - toks []Token -} - -// Lex tokenizes a classic SPL query. It is exported for the SPL2 front-end and -// for tooling that needs token-level access. +// Lex tokenizes a classic SPL query. It is exported for tooling that needs +// token-level access and is a thin adapter over the generated ANTLR lexer: +// keyword tokens are reported as identifiers, and string literals carry their +// decoded value. func Lex(src string) ([]Token, error) { - l := &lexer{src: src, line: 1, col: 1} - for { - l.skipSpace() - if l.i >= len(l.src) { - l.toks = append(l.toks, Token{Kind: EOF, Pos: l.pos()}) - return l.toks, nil + m := antlrpos.New(src) + stream, err := newTokenStream(m, src) + if err != nil { + return nil, err + } + toks := stream.GetAllTokens() + out := make([]Token, 0, len(toks)) + for _, t := range toks { + tok, err := convertToken(m, t) + if err != nil { + return nil, err } + out = append(out, tok) + } + return out, nil +} - pos := l.pos() - ch := l.src[l.i] - switch { - case ch == '|': - l.advance() - l.emit(Pipe, "|", pos) - case ch == ',': - l.advance() - l.emit(Comma, ",", pos) - case ch == '(': - l.advance() - l.emit(LParen, "(", pos) - case ch == ')': - l.advance() - l.emit(RParen, ")", pos) - case ch == '[': - l.advance() - l.emit(LBracket, "[", pos) - case ch == ']': - l.advance() - l.emit(RBracket, "]", pos) - case ch == '"' || ch == '\'': - text, err := l.scanString(ch, pos) - if err != nil { - return nil, err - } - l.emitString(text, pos) - case isDigit(ch): - if err := l.scanNumber(pos); err != nil { - return nil, err - } - case isIdentStart(ch): - start := l.i - for l.i < len(l.src) && isIdentPart(l.src[l.i]) { - l.advance() - } - l.emit(Ident, l.src[start:l.i], pos) - case ch == '=': - l.advance() - text := "=" - if l.i < len(l.src) && l.src[l.i] == '=' { - l.advance() - text = "==" +// newTokenStream runs the generated lexer over src, fills the stream so every +// token is available up front, and applies the invalid-token pass. Lexing the +// whole input before parsing keeps the hand parser's priority: a lexical error +// in a later stage beats a semantic error in an earlier one. The returned +// stream answers the parser's lookahead with the value-run token types (see +// tightStream); GetAllTokens still returns the lexer's own tokens. +func newTokenStream(m *antlrpos.SourceMap, src string) (*tightStream, error) { + lexer := spl1gen.NewSPL1Lexer(antlr.NewInputStream(src)) + lexer.RemoveErrorListeners() + stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) + stream.Fill() + toks := stream.GetAllTokens() + if err := checkTokens(m, toks, src); err != nil { + return nil, err + } + return &tightStream{CommonTokenStream: stream, types: tightTokenTypes(toks)}, nil +} + +// checkTokens reports the first lexically invalid token in source order. +// +// ANTLR's lexer never fails: a character no rule accepts becomes UNKNOWN, a +// numeric literal immediately followed by a letter lexes as a valid number +// plus an identifier, and a number too large for a float64 still lexes as +// NUMBER. All three are lexical errors in SPL, reported at the start of the +// offending token before any parsing begins. +func checkTokens(m *antlrpos.SourceMap, toks []antlr.Token, src string) error { + for i, t := range toks { + switch t.GetTokenType() { + case spl1gen.SPL1ParserUNKNOWN: + return invalidCharacter(m, t, src) + case spl1gen.SPL1ParserNUMBER, spl1gen.SPL1ParserDURATION: + // A number outside float64 is invalid, like any other lexical + // error, and is reported before parsing begins. + if t.GetTokenType() == spl1gen.SPL1ParserNUMBER { + if _, err := strconv.ParseFloat(t.GetText(), 64); err != nil { + return diag.NewError(m.Pos(t), "syntax", + "invalid number %q", t.GetText()) + } } - l.emit(Eq, text, pos) - case ch == '!': - l.advance() - if l.i < len(l.src) && l.src[l.i] == '=' { - l.advance() - l.emit(Ne, "!=", pos) - } else { - l.emit(Bang, "!", pos) + next := nextToken(toks, i) + if next == nil || next.GetTokenType() == antlr.TokenEOF { + continue } - case ch == '<': - l.advance() - if l.i < len(l.src) && l.src[l.i] == '=' { - l.advance() - l.emit(Le, "<=", pos) - } else { - l.emit(Lt, "<", pos) + if t.GetStop()+1 != next.GetStart() { + continue } - case ch == '>': - l.advance() - if l.i < len(l.src) && l.src[l.i] == '=' { - l.advance() - l.emit(Ge, ">=", pos) - } else { - l.emit(Gt, ">", pos) + at := m.ByteOffset(next.GetStart()) + if at >= len(src) || !isLetter(src[at]) { + continue } - case ch == '+': - l.advance() - l.emit(Plus, "+", pos) - case ch == '-': - l.advance() - l.emit(Minus, "-", pos) - case ch == '*': - l.advance() - l.emit(Star, "*", pos) - case ch == '/': - l.advance() - l.emit(Slash, "/", pos) - case ch == '%': - l.advance() - l.emit(Percent, "%", pos) - default: - r, size := utf8.DecodeRuneInString(l.src[l.i:]) - if r == utf8.RuneError && size == 1 { - return nil, diag.NewError(pos, "syntax", "unexpected byte 0x%02X", ch) + start := m.ByteOffset(t.GetStart()) + // The literal is malformed because a letter-run continues it, so + // quote the whole run rather than the numeric token alone. + end := m.ByteOffset(next.GetStop() + 1) + if end > len(src) { + end = len(src) } - return nil, diag.NewError(pos, "syntax", "unexpected character %q", string(r)) + return diag.NewError(m.Pos(t), "syntax", + "invalid numeric literal %q", src[start:end]) } } + return nil } -func (l *lexer) pos() ast.Pos { - return ast.Pos{Line: l.line, Col: l.col, Offset: l.i} -} - -func (l *lexer) emit(k Kind, text string, pos ast.Pos) { - l.toks = append(l.toks, Token{Kind: k, Text: text, Pos: pos}) +func nextToken(toks []antlr.Token, i int) antlr.Token { + if i+1 < len(toks) { + return toks[i+1] + } + return nil } -func (l *lexer) emitString(text string, pos ast.Pos) { - l.toks = append(l.toks, Token{Kind: String, Text: text, Pos: pos}) +func invalidCharacter(m *antlrpos.SourceMap, t antlr.Token, src string) error { + at := m.ByteOffset(t.GetStart()) + if at >= len(src) { + return diag.NewError(m.Pos(t), "syntax", "unexpected end of query") + } + r, size := utf8.DecodeRuneInString(src[at:]) + if r == utf8.RuneError && size == 1 { + return diag.NewError(m.Pos(t), "syntax", "unexpected byte 0x%02X", src[at]) + } + return diag.NewError(m.Pos(t), "syntax", "unexpected character %q", string(r)) } -func (l *lexer) advance() byte { - ch := l.src[l.i] - l.i++ - if ch == '\n' { - l.line++ - l.col = 1 - } else { - l.col++ +// convertToken maps a generated token onto the public token kind. +func convertToken(m *antlrpos.SourceMap, t antlr.Token) (Token, error) { + pos := m.Pos(t) + switch t.GetTokenType() { + case spl1gen.SPL1ParserEOF: + return Token{Kind: EOF, Pos: pos}, nil + case spl1gen.SPL1ParserIDENT, + spl1gen.SPL1ParserSEARCH, spl1gen.SPL1ParserWHERE, spl1gen.SPL1ParserSTATS, + spl1gen.SPL1ParserTIMECHART, spl1gen.SPL1ParserEVAL, spl1gen.SPL1ParserREX, + spl1gen.SPL1ParserTABLE, spl1gen.SPL1ParserFIELDS, spl1gen.SPL1ParserSORT, + spl1gen.SPL1ParserHEAD, spl1gen.SPL1ParserBIN, spl1gen.SPL1ParserBY, + spl1gen.SPL1ParserAS, spl1gen.SPL1ParserSPAN, spl1gen.SPL1ParserLIMIT, + spl1gen.SPL1ParserFIELD, spl1gen.SPL1ParserAND, spl1gen.SPL1ParserOR, + spl1gen.SPL1ParserNOT: + return Token{Kind: Ident, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserSTRING: + return Token{Kind: String, Text: decodeString(t.GetText()), Pos: pos}, nil + case spl1gen.SPL1ParserNUMBER: + return Token{Kind: Number, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserDURATION: + return Token{Kind: Duration, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserPIPE: + return Token{Kind: Pipe, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserCOMMA: + return Token{Kind: Comma, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserLPAREN: + return Token{Kind: LParen, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserRPAREN: + return Token{Kind: RParen, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserLBRACKET: + return Token{Kind: LBracket, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserRBRACKET: + return Token{Kind: RBracket, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserEQ2, spl1gen.SPL1ParserEQ: + return Token{Kind: Eq, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserNE: + return Token{Kind: Ne, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserLT: + return Token{Kind: Lt, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserLE: + return Token{Kind: Le, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserGT: + return Token{Kind: Gt, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserGE: + return Token{Kind: Ge, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserPLUS: + return Token{Kind: Plus, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserMINUS: + return Token{Kind: Minus, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserSTAR: + return Token{Kind: Star, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserSLASH: + return Token{Kind: Slash, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserPERCENT: + return Token{Kind: Percent, Text: t.GetText(), Pos: pos}, nil + case spl1gen.SPL1ParserBANG: + return Token{Kind: Bang, Text: t.GetText(), Pos: pos}, nil } - return ch + return Token{}, invalidCharacterFrom(m, t) } -func (l *lexer) skipSpace() { - for l.i < len(l.src) { - switch l.src[l.i] { - case ' ', '\t', '\r', '\n': - l.advance() - default: - return - } - } +// invalidCharacterFrom is the defensive path for a token type convertToken +// does not know; checkTokens has already refused UNKNOWN, so reaching it means +// the grammar gained a token the adapter was not updated for. +func invalidCharacterFrom(m *antlrpos.SourceMap, t antlr.Token) error { + return diag.NewError(m.Pos(t), "syntax", "unexpected %q", t.GetText()) } -func (l *lexer) scanString(quote byte, pos ast.Pos) (string, error) { - l.advance() // opening quote +// decodeString returns the value of a string literal token: the delimiters are +// dropped and only an escaped delimiter is unescaped. Every other backslash is +// kept so regular expressions survive intact. +func decodeString(raw string) string { + if len(raw) < 2 { + return "" + } + quote := raw[0] + body := raw[1 : len(raw)-1] var b strings.Builder - for l.i < len(l.src) { - ch := l.advance() - if ch == quote { - return b.String(), nil - } - // Only the quote itself is unescaped. Backslashes are preserved so - // regular expressions survive intact (`\d`, `\S`, and `\\`). - if ch == '\\' && l.i < len(l.src) && l.src[l.i] == quote { - l.advance() + b.Grow(len(body)) + for i := 0; i < len(body); i++ { + if body[i] == '\\' && i+1 < len(body) && body[i+1] == quote { b.WriteByte(quote) + i++ continue } - b.WriteByte(ch) + b.WriteByte(body[i]) } - return "", diag.NewError(pos, "syntax", "unterminated string literal") + return b.String() } -func (l *lexer) scanNumber(pos ast.Pos) error { - start := l.i - for l.i < len(l.src) && isDigit(l.src[l.i]) { - l.advance() - } - if l.i < len(l.src) && l.src[l.i] == '.' && l.i+1 < len(l.src) && isDigit(l.src[l.i+1]) { - l.advance() - for l.i < len(l.src) && isDigit(l.src[l.i]) { - l.advance() - } - } - // Scientific notation: 1e3, 2.5E-2. - if l.i < len(l.src) && (l.src[l.i] == 'e' || l.src[l.i] == 'E') { - j := l.i + 1 - if j < len(l.src) && (l.src[j] == '+' || l.src[j] == '-') { - j++ - } - if j < len(l.src) && isDigit(l.src[j]) { - for l.i < j { - l.advance() - } - for l.i < len(l.src) && isDigit(l.src[l.i]) { - l.advance() - } - } - } - - num := l.src[start:l.i] - unit := l.scanDurationUnit() - if unit != "" { - l.toks = append(l.toks, Token{Kind: Duration, Text: num + unit, Pos: pos}) - return nil - } - if l.i < len(l.src) && isLetter(l.src[l.i]) { - return diag.NewError(pos, "syntax", "invalid numeric literal %q", l.src[start:l.i+1]) - } - if _, err := strconv.ParseFloat(num, 64); err != nil { - return diag.NewError(pos, "syntax", "invalid number %q", num) - } - l.toks = append(l.toks, Token{Kind: Number, Text: num, Pos: pos}) - return nil -} - -// scanDurationUnit consumes the longest valid SPL time unit at the cursor. -func (l *lexer) scanDurationUnit() string { - rest := l.src[l.i:] - for _, unit := range []string{"mon", "ms", "s", "m", "h", "d", "w", "y"} { - if strings.HasPrefix(rest, unit) { - after := l.i + len(unit) - if after < len(l.src) && isLetter(l.src[after]) { - continue - } - for range unit { - l.advance() - } - return unit - } - } - return "" -} - -func isDigit(b byte) bool { return b >= '0' && b <= '9' } - func isLetter(b byte) bool { return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') } - -func isIdentStart(b byte) bool { - return b == '_' || b == '@' || isLetter(b) -} - -func isIdentPart(b byte) bool { - return isIdentStart(b) || isDigit(b) || b == '.' || b == ':' -} diff --git a/pkg/parser/spl1/lexer_test.go b/pkg/parser/spl1/lexer_test.go index 7ae4e60..945a396 100644 --- a/pkg/parser/spl1/lexer_test.go +++ b/pkg/parser/spl1/lexer_test.go @@ -91,6 +91,74 @@ func TestLexInvalidByteIsReportedAsAByte(t *testing.T) { } } +// TestNumberRangeIsALexicalError checks that a number too large for a float64 +// is refused before parsing begins, so it wins over a semantic error in an +// earlier stage, exactly like any other lexical error. +func TestNumberRangeIsALexicalError(t *testing.T) { + tests := []struct { + src string + line int + col int + }{ + {`1e400`, 1, 1}, + {`1e400 | stats count`, 1, 1}, + {`index=web 1e400 | join a b`, 1, 11}, + {`index=web | join a b | stats count 1e400`, 1, 36}, + } + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + _, err := Parse(tc.src) + if err == nil { + t.Fatal("expected an error") + } + ds, ok := diag.FromError(err) + if !ok || len(ds) != 1 { + t.Fatalf("err = %v, want one diagnostic", err) + } + d := ds[0] + if d.Code != "syntax" || d.Pos.Line != tc.line || d.Pos.Col != tc.col { + t.Fatalf("diagnostic = %#v, want syntax at %d:%d", d, tc.line, tc.col) + } + if want := `invalid number "1e400"`; d.Message != want { + t.Fatalf("message = %q, want %q", d.Message, want) + } + }) + } +} + +// TestInvalidNumericLiteralQuotesTheRun checks the letter-run diagnostic: the +// quoted text is the whole malformed literal, not the numeric prefix alone. +func TestInvalidNumericLiteralQuotesTheRun(t *testing.T) { + tests := []struct { + src string + want string + }{ + {`index=web 5month`, "5month"}, + {`index=web 1monx`, "1monx"}, + // The run stops at the operator: `1e` is the contiguous letter run. + {`index=web 1e+foo`, "1e"}, + } + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + _, err := Parse(tc.src) + if err == nil { + t.Fatal("expected an error") + } + ds, ok := diag.FromError(err) + if !ok || len(ds) != 1 { + t.Fatalf("err = %v, want one diagnostic", err) + } + d := ds[0] + if d.Code != "syntax" || d.Pos.Line != 1 || d.Pos.Col != 11 { + t.Fatalf("diagnostic = %#v, want syntax at 1:11", d) + } + if want := `invalid numeric literal "` + tc.want + `"`; d.Message != want { + t.Fatalf("message = %q, want %q", d.Message, want) + } + }) + } +} + func TestParsePositionAfterMultibyteString(t *testing.T) { _, err := Parse(`index=web msg="café" +`) if err == nil { diff --git a/pkg/parser/spl1/parse.go b/pkg/parser/spl1/parse.go new file mode 100644 index 0000000..afa7b4b --- /dev/null +++ b/pkg/parser/spl1/parse.go @@ -0,0 +1,131 @@ +package spl1 + +import ( + "strings" + + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/ast" + "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/commands" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrsupport" + "github.com/be-thomas/openspl/pkg/parser/spl1/gen" +) + +// Parse parses a classic SPL query into the unified IR. +func Parse(src string) (pl *ast.Pipeline, err error) { + if strings.TrimSpace(src) == "" { + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "empty-query", "query is empty") + } + + m := antlrpos.New(src) + stream, err := newTokenStream(m, src) + if err != nil { + return nil, err + } + + parser := spl1gen.NewSPL1Parser(stream) + parser.RemoveErrorListeners() + parser.AddErrorListener(antlrsupport.New(m)) + + b := &builder{m: m, toks: stream.GetAllTokens(), parser: parser} + + // The listener aborts the parse by panicking on the first syntax error; + // any other panic is a bug and is re-raised by Recover. + defer func() { + if r := recover(); r != nil { + if e, ok := antlrsupport.Recover(r, m); ok { + pl, err = nil, e + } + } + }() + return b.pipeline() +} + +// pipeline drives the entry rules one stage at a time. The grammar owns +// command and expression structure; the driver owns stage sequencing, command +// classification, and the leading/trailing-pipe rules, because fail-fast +// priority depends on stopping at the first stage-level problem. +func (b *builder) pipeline() (*ast.Pipeline, error) { + ts := b.parser.GetTokenStream() + + // A leading pipe is tolerated: `| stats count` means the same as + // `stats count` with an implicit match-all search. + if ts.LA(1) == spl1gen.SPL1ParserPIPE { + ts.Consume() + } + if ts.LA(1) == antlr.TokenEOF { + return nil, diag.NewError(b.pos(ts.LT(1)), "empty-query", "query is empty") + } + + pl := &ast.Pipeline{} + for first := true; ; first = false { + stage, end, err := b.stage(first) + if err != nil { + return nil, err + } + pl.Stages = append(pl.Stages, stage) + + // stageEnd is part of every entry rule and was just consumed. The + // stream does not advance past EOF, so the rule context, not LT(-1), + // says whether the stage ended at a pipe. + if end.EOF() != nil { + return pl, nil + } + if ts.LA(1) == antlr.TokenEOF { + return nil, diag.NewError(b.pos(end.PIPE().GetSymbol()), "syntax", + "expected a command after '|'") + } + } +} + +// stage classifies the stage start and parses exactly one stage. +func (b *builder) stage(first bool) (ast.Stage, spl1gen.IStageEndContext, error) { + ts := b.parser.GetTokenStream() + cur := ts.LT(1) + + if isIdentLikeToken(cur.GetTokenType()) { + name := strings.ToLower(cur.GetText()) + if commands.SPL1Implemented(name) { + ctx := b.parser.StageCommand() + st, err := b.command(ctx) + return st, ctx.StageEnd(), err + } + if commands.SPL1Known(name) { + return nil, nil, diag.NewError(b.pos(cur), "unsupported-command", + "command %q is recognized but not implemented yet; see docs/COMPATIBILITY.md", name) + } + if !first { + return nil, nil, diag.NewError(b.pos(cur), "unknown-command", "unknown command %q", name) + } + ctx := b.parser.StageSearch() + st, err := b.searchStage(ctx) + return st, ctx.StageEnd(), err + } + + if !first { + // Not a command keyword: the grammar reports the unexpected token. + ctx := b.parser.StageCommand() + st, err := b.command(ctx) + return st, ctx.StageEnd(), err + } + ctx := b.parser.StageSearch() + st, err := b.searchStage(ctx) + return st, ctx.StageEnd(), err +} + +// isIdentLikeToken mirrors the grammar's identLike rule for stage dispatch. +func isIdentLikeToken(t int) bool { + switch t { + case spl1gen.SPL1ParserIDENT, spl1gen.SPL1ParserSEARCH, spl1gen.SPL1ParserWHERE, + spl1gen.SPL1ParserSTATS, spl1gen.SPL1ParserTIMECHART, spl1gen.SPL1ParserEVAL, + spl1gen.SPL1ParserREX, spl1gen.SPL1ParserTABLE, spl1gen.SPL1ParserFIELDS, + spl1gen.SPL1ParserSORT, spl1gen.SPL1ParserHEAD, spl1gen.SPL1ParserBIN, + spl1gen.SPL1ParserBY, spl1gen.SPL1ParserAS, spl1gen.SPL1ParserSPAN, + spl1gen.SPL1ParserLIMIT, spl1gen.SPL1ParserFIELD, spl1gen.SPL1ParserAND, + spl1gen.SPL1ParserOR, spl1gen.SPL1ParserNOT, spl1gen.SPL1ParserNOT_WORD: + return true + } + return false +} diff --git a/pkg/parser/spl1/parser.go b/pkg/parser/spl1/parser.go deleted file mode 100644 index fd72bfd..0000000 --- a/pkg/parser/spl1/parser.go +++ /dev/null @@ -1,1143 +0,0 @@ -// Package spl1 implements the classic Splunk SPL front-end. -// -// The parser lowers source syntax into the target-agnostic IR in pkg/ast. It -// deliberately knows nothing about ES|QL, PromQL, or any other back-end. -package spl1 - -import ( - "strconv" - "strings" - - "github.com/be-thomas/openspl/pkg/ast" - "github.com/be-thomas/openspl/pkg/diag" -) - -// implementedCommands are the stages this front-end can parse today. -var implementedCommands = map[string]bool{ - "search": true, - "where": true, - "stats": true, - "timechart": true, - "eval": true, - "rex": true, - "table": true, - "fields": true, - "sort": true, - "head": true, - "bin": true, -} - -// knownCommands are real SPL commands we recognize but do not implement yet. -// Recognizing them produces a precise "not implemented" error instead of a -// confusing parse failure that treats the command as a search term. -var knownCommands = map[string]bool{ - "append": true, "appendcols": true, "addtotals": true, "analyzefields": true, - "anomalydetection": true, "apply": true, "associate": true, "bucket": true, - "chart": true, "cluster": true, "collect": true, "contingency": true, - "correlate": true, "datamodel": true, "dbinspect": true, "dedup": true, - "delete": true, "diff": true, "entitlement": true, "eventcount": true, - "eventstats": true, "extract": true, "fieldformat": true, "fieldsummary": true, - "filldown": true, "fillnull": true, "findtypes": true, "fit": true, - "folderize": true, "foreach": true, "format": true, "from": true, - "geostats": true, "head": true, "highlight": true, "inputcsv": true, - "inputlookup": true, "iplocation": true, "join": true, "kmeans": true, - "kvform": true, "loadjob": true, "localize": true, "lookup": true, - "makecontinuous": true, "makeresults": true, "map": true, "mcollect": true, - "metadata": true, "metasearch": true, "ml": true, "mstats": true, - "multikmeans": true, "multisearch": true, "mvcombine": true, "mvexpand": true, - "nomv": true, "outlier": true, "outputcsv": true, "outputlookup": true, - "outputtext": true, "pivot": true, "predict": true, "rangemap": true, - "rare": true, "regex": true, "reltime": true, "rename": true, "replace": true, - "rest": true, "return": true, "reverse": true, "rex": true, "script": true, - "scrub": true, "search": true, "select": true, "selfjoin": true, - "sendemail": true, "set": true, "setfields": true, "spath": true, - "stats": true, "strcat": true, "streamstats": true, "table": true, - "tags": true, "tail": true, "timechart": true, "top": true, - "transaction": true, "transpose": true, "trendline": true, "tscollect": true, - "tstats": true, "typeahead": true, "typer": true, "union": true, - "uniq": true, "untable": true, "where": true, "x11": true, "xmlkv": true, - "xmlunescape": true, "xpath": true, -} - -func isImplementedCommand(s string) bool { return implementedCommands[s] } -func isKnownCommand(s string) bool { return knownCommands[s] } - -type parser struct { - toks []Token - i int - - // searchLiterals is true while parsing a `search` expression. In that - // context an unquoted identifier on the right of a comparison is a value - // (host=web means host == "web"), whereas in eval/where it is a field. - searchLiterals bool -} - -// Parse parses a classic SPL query into the unified IR. -func Parse(src string) (*ast.Pipeline, error) { - if strings.TrimSpace(src) == "" { - return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "empty-query", "query is empty") - } - toks, err := Lex(src) - if err != nil { - return nil, err - } - p := &parser{toks: toks} - return p.parsePipeline() -} - -func (p *parser) parsePipeline() (*ast.Pipeline, error) { - pl := &ast.Pipeline{} - - // A leading pipe is tolerated: `| stats count` means the same as - // `stats count` with an implicit match-all search. - if p.cur().Kind == Pipe { - p.advance() - } - if p.cur().Kind == EOF { - return nil, diag.NewError(p.cur().Pos, "empty-query", "query is empty") - } - - first, err := p.parseFirstStage() - if err != nil { - return nil, err - } - pl.Stages = append(pl.Stages, first) - - for p.cur().Kind == Pipe { - pipe := p.cur().Pos - p.advance() - if p.cur().Kind == EOF { - return nil, diag.NewError(pipe, "syntax", "expected a command after '|'") - } - st, err := p.parseCommand() - if err != nil { - return nil, err - } - pl.Stages = append(pl.Stages, st) - } - if p.cur().Kind != EOF { - return nil, diag.NewError(p.cur().Pos, "syntax", - "unexpected %s; expected '|' or end of query", p.cur().describe()) - } - return pl, nil -} - -func (p *parser) parseFirstStage() (ast.Stage, error) { - if p.cur().Kind == Ident { - word := strings.ToLower(p.cur().Text) - if isImplementedCommand(word) || isKnownCommand(word) { - return p.parseCommand() - } - } - return p.parseImplicitSearch() -} - -func (p *parser) parseImplicitSearch() (ast.Stage, error) { - pos := p.cur().Pos - expr, err := p.parseExprWith(true) - if err != nil { - return nil, err - } - st := &ast.SearchStage{Expr: expr, Pos: pos} - if err := extractTimeBounds(st); err != nil { - return nil, err - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return st, nil -} - -func (p *parser) parseCommand() (ast.Stage, error) { - pos := p.cur().Pos - if p.cur().Kind != Ident { - return nil, diag.NewError(pos, "syntax", "expected a command, found %s", p.cur().describe()) - } - name := strings.ToLower(p.cur().Text) - p.advance() - - switch name { - case "search": - return p.parseSearchCommand(pos, true) - case "where": - return p.parseSearchCommand(pos, false) - case "stats": - return p.parseStats(pos) - case "timechart": - return p.parseTimechart(pos) - case "eval": - return p.parseEval(pos) - case "rex": - return p.parseRex(pos) - case "table": - return p.parseTable(pos) - case "fields": - return p.parseFields(pos) - case "sort": - return p.parseSort(pos) - case "head": - return p.parseHead(pos) - case "bin": - return p.parseBin(pos) - default: - if isKnownCommand(name) { - return nil, diag.NewError(pos, "unsupported-command", - "command %q is recognized but not implemented yet; see docs/COMPATIBILITY.md", name) - } - return nil, diag.NewError(pos, "unknown-command", "unknown command %q", name) - } -} - -func (p *parser) parseSearchCommand(pos ast.Pos, literals bool) (ast.Stage, error) { - var expr ast.Expr - if !p.atStageEnd() { - var err error - expr, err = p.parseExprWith(literals) - if err != nil { - return nil, err - } - } - st := &ast.SearchStage{Expr: expr, Pos: pos} - if err := extractTimeBounds(st); err != nil { - return nil, err - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return st, nil -} - -func (p *parser) parseStats(pos ast.Pos) (ast.Stage, error) { - aggs, err := p.parseAggregates() - if err != nil { - return nil, err - } - var by []ast.Expr - if p.matchKeyword("by") { - by, err = p.parseFieldExprList() - if err != nil { - return nil, err - } - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return &ast.StatsStage{Aggs: aggs, By: by, Pos: pos}, nil -} - -func (p *parser) parseTimechart(pos ast.Pos) (ast.Stage, error) { - span := "" - if p.matchKeyword("span") { - if err := p.expectKind(Eq, "'='"); err != nil { - return nil, err - } - var err error - span, err = p.parseSpanValue() - if err != nil { - return nil, err - } - } - aggs, err := p.parseAggregates() - if err != nil { - return nil, err - } - var by []ast.Expr - if p.matchKeyword("by") { - by, err = p.parseFieldExprList() - if err != nil { - return nil, err - } - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return &ast.TimechartStage{Aggs: aggs, By: by, Span: span, Pos: pos}, nil -} - -func (p *parser) parseAggregates() ([]ast.Aggregate, error) { - var aggs []ast.Aggregate - for { - if p.cur().Kind != Ident { - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected an aggregation function, found %s", p.cur().describe()) - } - pos := p.cur().Pos - fn := strings.ToLower(p.cur().Text) - p.advance() - - var arg ast.Expr - if p.matchKind(LParen) { - if p.cur().Kind != RParen { - var err error - arg, err = p.parseExprWith(false) - if err != nil { - return nil, err - } - } - if err := p.expectKind(RParen, "')'"); err != nil { - return nil, err - } - } - - alias := "" - if p.matchKeyword("as") { - if p.cur().Kind != Ident { - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected an alias after 'as', found %s", p.cur().describe()) - } - alias = p.cur().Text - p.advance() - } - - aggs = append(aggs, ast.Aggregate{Func: fn, Arg: arg, Alias: alias, Pos: pos}) - - if p.matchKind(Comma) { - continue - } - break - } - if len(aggs) == 0 { - return nil, diag.NewError(p.cur().Pos, "syntax", "stats requires at least one aggregation") - } - return aggs, nil -} - -func (p *parser) parseFieldExprList() ([]ast.Expr, error) { - var out []ast.Expr - for { - switch p.cur().Kind { - case Ident: - out = append(out, &ast.FieldRef{Name: p.cur().Text, Pos: p.cur().Pos}) - p.advance() - case Star: - out = append(out, &ast.WildcardLit{Pos: p.cur().Pos}) - p.advance() - default: - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field name, found %s", p.cur().describe()) - } - if p.matchKind(Comma) { - continue - } - if p.cur().Kind == Ident || p.cur().Kind == Star { - continue // Splunk also accepts space-separated field lists. - } - break - } - if len(out) == 0 { - return nil, diag.NewError(p.cur().Pos, "syntax", "expected at least one field after 'by'") - } - return out, nil -} - -func (p *parser) parseEval(pos ast.Pos) (ast.Stage, error) { - var assignments []ast.Assignment - for { - if p.cur().Kind != Ident { - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field name in eval, found %s", p.cur().describe()) - } - name := p.cur().Text - namePos := p.cur().Pos - p.advance() - if err := p.expectKind(Eq, "'='"); err != nil { - return nil, err - } - expr, err := p.parseExprWith(false) - if err != nil { - return nil, err - } - assignments = append(assignments, ast.Assignment{Name: name, Expr: expr, Pos: namePos}) - if p.matchKind(Comma) { - continue - } - break - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return &ast.EvalStage{Assignments: assignments, Pos: pos}, nil -} - -func (p *parser) parseRex(pos ast.Pos) (ast.Stage, error) { - field := "_raw" - if p.matchKeyword("field") { - if err := p.expectKind(Eq, "'='"); err != nil { - return nil, err - } - if p.cur().Kind != Ident { - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field name after 'field=', found %s", p.cur().describe()) - } - field = p.cur().Text - p.advance() - } - if p.cur().Kind != String { - return nil, diag.NewError(p.cur().Pos, "syntax", - "rex requires a quoted regular expression, found %s", p.cur().describe()) - } - pattern := p.cur().Text - p.advance() - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return &ast.RexStage{Field: field, Pattern: pattern, Pos: pos}, nil -} - -func (p *parser) parseTable(pos ast.Pos) (ast.Stage, error) { - var fields []string - wildcard := false - for !p.atStageEnd() { - switch p.cur().Kind { - case Comma: - p.advance() - case Star: - wildcard = true - p.advance() - case Ident: - fields = append(fields, p.cur().Text) - p.advance() - default: - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field name in table, found %s", p.cur().describe()) - } - } - if len(fields) == 0 && !wildcard { - return nil, diag.NewError(pos, "syntax", "table requires at least one field") - } - return &ast.TableStage{Fields: fields, Wildcard: wildcard, Pos: pos}, nil -} - -func (p *parser) parseFields(pos ast.Pos) (ast.Stage, error) { - exclude := false - if p.matchKind(Minus) { - exclude = true - } else { - p.matchKind(Plus) - } - - var include, excludeFields []string - for !p.atStageEnd() { - if p.matchKind(Comma) { - continue - } - if p.cur().Kind != Ident { - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field name in fields, found %s", p.cur().describe()) - } - if exclude { - excludeFields = append(excludeFields, p.cur().Text) - } else { - include = append(include, p.cur().Text) - } - p.advance() - } - if len(include) == 0 && len(excludeFields) == 0 { - return nil, diag.NewError(pos, "syntax", "fields requires at least one field") - } - return &ast.FieldsStage{Include: include, Exclude: excludeFields, Pos: pos}, nil -} - -func (p *parser) parseSort(pos ast.Pos) (ast.Stage, error) { - limit := 0 - if p.matchKeyword("limit") { - if err := p.expectKind(Eq, "'='"); err != nil { - return nil, err - } - n, err := p.parseNonNegativeInt("sort limit") - if err != nil { - return nil, err - } - limit = n - } else if p.cur().Kind == Number { - n, err := p.parseNonNegativeInt("sort limit") - if err != nil { - return nil, err - } - limit = n - } - - var fields []ast.SortField - for !p.atStageEnd() { - if p.matchKind(Comma) { - continue - } - desc := false - if p.matchKind(Minus) { - desc = true - } else { - p.matchKind(Plus) - } - if p.cur().Kind != Ident { - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field name in sort, found %s", p.cur().describe()) - } - fields = append(fields, ast.SortField{Name: p.cur().Text, Desc: desc}) - p.advance() - } - if len(fields) == 0 && limit == 0 { - return nil, diag.NewError(pos, "syntax", "sort requires at least one field") - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return &ast.SortStage{Fields: fields, Limit: limit, Pos: pos}, nil -} - -func (p *parser) parseHead(pos ast.Pos) (ast.Stage, error) { - count := 10 // Splunk's default - countSet := false - if p.matchKeyword("limit") { - if err := p.expectKind(Eq, "'='"); err != nil { - return nil, err - } - n, err := p.parseNonNegativeInt("head limit") - if err != nil { - return nil, err - } - count, countSet = n, true - } else if p.cur().Kind == Number { - n, err := p.parseNonNegativeInt("head count") - if err != nil { - return nil, err - } - count, countSet = n, true - } - if err := p.expectStageEnd(); err != nil { - return nil, err - } - return &ast.HeadStage{Count: count, CountSet: countSet, Pos: pos}, nil -} - -func (p *parser) parseBin(pos ast.Pos) (ast.Stage, error) { - field, span := "", "" - for !p.atStageEnd() { - switch { - case p.matchKeyword("span"): - if err := p.expectKind(Eq, "'='"); err != nil { - return nil, err - } - var err error - span, err = p.parseSpanValue() - if err != nil { - return nil, err - } - case p.cur().Kind == Ident: - if field != "" { - return nil, diag.NewError(p.cur().Pos, "syntax", - "bin accepts exactly one field; found %q after %q", p.cur().Text, field) - } - field = p.cur().Text - p.advance() - default: - return nil, diag.NewError(p.cur().Pos, "syntax", - "expected a field or span= in bin, found %s", p.cur().describe()) - } - } - if field == "" { - return nil, diag.NewError(pos, "syntax", "bin requires a field") - } - if span == "" { - return nil, diag.NewError(pos, "syntax", "bin requires span=") - } - return &ast.BinStage{Field: field, Span: span, Pos: pos}, nil -} - -func (p *parser) parseSpanValue() (string, error) { - switch p.cur().Kind { - case Duration, Ident: - v := p.cur().Text - p.advance() - return v, nil - default: - return "", diag.NewError(p.cur().Pos, "syntax", - "expected a duration such as 5m, found %s", p.cur().describe()) - } -} - -func (p *parser) parseNonNegativeInt(what string) (int, error) { - if p.cur().Kind != Number { - return 0, diag.NewError(p.cur().Pos, "syntax", - "expected a non-negative integer for %s, found %s", what, p.cur().describe()) - } - n, err := strconv.Atoi(p.cur().Text) - if err != nil || n < 0 { - return 0, diag.NewError(p.cur().Pos, "syntax", - "expected a non-negative integer for %s, found %q", what, p.cur().Text) - } - p.advance() - return n, nil -} - -// --- expressions --------------------------------------------------------- - -func (p *parser) parseExprWith(literals bool) (ast.Expr, error) { - old := p.searchLiterals - p.searchLiterals = literals - defer func() { p.searchLiterals = old }() - return p.parseOr() -} - -func (p *parser) parseOr() (ast.Expr, error) { - left, err := p.parseAnd() - if err != nil { - return nil, err - } - for p.matchKeyword("or") { - pos := p.prevPos() - right, err := p.parseAnd() - if err != nil { - return nil, err - } - left = &ast.BinaryExpr{Op: "or", Left: left, Right: right, Pos: pos} - } - return left, nil -} - -func (p *parser) parseAnd() (ast.Expr, error) { - left, err := p.parseNot() - if err != nil { - return nil, err - } - for { - if p.matchKeyword("and") { - pos := p.prevPos() - right, err := p.parseNot() - if err != nil { - return nil, err - } - left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: pos} - continue - } - // SPL treats adjacent terms as an implicit AND. - if p.startsTerm() { - right, err := p.parseNot() - if err != nil { - return nil, err - } - left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: left.Position()} - continue - } - break - } - return left, nil -} - -func (p *parser) parseNot() (ast.Expr, error) { - if p.matchKeyword("not") || p.matchKind(Bang) { - pos := p.prevPos() - operand, err := p.parseNot() - if err != nil { - return nil, err - } - return &ast.UnaryExpr{Op: "not", Operand: operand, Pos: pos}, nil - } - return p.parseComparison() -} - -func (p *parser) parseComparison() (ast.Expr, error) { - left, err := p.parseAdditive() - if err != nil { - return nil, err - } - for { - var op string - switch p.cur().Kind { - case Eq: - op = "=" - case Ne: - op = "!=" - case Lt: - op = "<" - case Le: - op = "<=" - case Gt: - op = ">" - case Ge: - op = ">=" - default: - return left, nil - } - pos := p.cur().Pos - p.advance() - right, err := p.parseComparisonOperand() - if err != nil { - return nil, err - } - left = &ast.BinaryExpr{Op: op, Left: left, Right: right, Pos: pos} - } -} - -func (p *parser) parseComparisonOperand() (ast.Expr, error) { - // In a search expression `host=web*` and `host=web` use bare values, not - // field references. Wildcards and embedded hyphens bind tightly to the - // value token, so web-*, *error*, web*prod, and logs-2024-01 are single - // values rather than arithmetic. - if p.searchLiterals { - if p.cur().Kind == String { - pos, value := p.cur().Pos, p.cur().Text - p.advance() - return &ast.StringLit{Value: value, Pos: pos}, nil - } - pos := p.cur().Pos - if value, ok := p.scanSearchValue(true); ok { - return &ast.StringLit{Value: value, Pos: pos}, nil - } - } - return p.parseAdditive() -} - -// scanSearchValue consumes an unquoted search value starting at the current -// token. Components must touch: whitespace always ends the run. allowHyphen -// enables comparison-RHS values such as logs-2024-01; free-text terms leave a -// `-` to the additive parser, where it stays arithmetic. The cursor does not -// move when the function reports false. -func (p *parser) scanSearchValue(allowHyphen bool) (string, bool) { - if !p.startsSearchValue(allowHyphen) { - return "", false - } - tok := p.cur() - - var b strings.Builder - b.WriteString(tok.Text) - p.advance() - -scan: - for { - prev, cur := p.prevTok(), p.cur() - if cur.Kind == EOF || prev.Pos.Offset+len(prev.Text) != cur.Pos.Offset { - break - } - switch cur.Kind { - case Star: - b.WriteString("*") - p.advance() - case Ident, Number: - b.WriteString(cur.Text) - p.advance() - case Minus: - if !allowHyphen { - break scan - } - next := p.peek(1) - if (next.Kind != Ident && next.Kind != Number && next.Kind != Star) || - cur.Pos.Offset+len(cur.Text) != next.Pos.Offset { - break scan - } - b.WriteString("-") - b.WriteString(next.Text) - p.advance() - p.advance() - default: - break scan - } - } - return b.String(), true -} - -// startsSearchValue reports whether the current token begins a tight value -// run. Numeric and signed starts are accepted only in comparison-RHS context -// (allowHyphen), so a bare `500` stays a NumberLit while `200-299` and `500*` -// are single literal values. A lone `*` stays a WildcardLit. -func (p *parser) startsSearchValue(allowHyphen bool) bool { - switch p.cur().Kind { - case Ident: - return true - case Number: - // Only start a run when a continuation makes it a hyphen or wildcard - // value; plain numbers keep their numeric literal semantics. - return allowHyphen && p.adjacent(0, 1) && - (p.peek(1).Kind == Minus || p.peek(1).Kind == Star) - case Star: - if !p.adjacent(0, 1) { - return false - } - switch p.peek(1).Kind { - case Ident, Number: - return true - case Minus: - if !allowHyphen || !p.adjacent(1, 1) { - return false - } - switch p.peek(2).Kind { - case Ident, Number, Star: - return true - } - } - return false - case Minus: - if !allowHyphen || !p.adjacent(0, 1) { - return false - } - return p.peek(1).Kind == Ident || p.peek(1).Kind == Star - } - return false -} - -func (p *parser) parseAdditive() (ast.Expr, error) { - left, err := p.parseMultiplicative() - if err != nil { - return nil, err - } - for p.cur().Kind == Plus || p.cur().Kind == Minus { - op := "+" - if p.cur().Kind == Minus { - op = "-" - } - pos := p.cur().Pos - p.advance() - right, err := p.parseMultiplicative() - if err != nil { - return nil, err - } - left = &ast.BinaryExpr{Op: op, Left: left, Right: right, Pos: pos} - } - return left, nil -} - -func (p *parser) parseMultiplicative() (ast.Expr, error) { - left, err := p.parseUnary() - if err != nil { - return nil, err - } - for p.cur().Kind == Star || p.cur().Kind == Slash || p.cur().Kind == Percent { - var op string - switch p.cur().Kind { - case Star: - op = "*" - case Slash: - op = "/" - default: - op = "%" - } - pos := p.cur().Pos - p.advance() - right, err := p.parseUnary() - if err != nil { - return nil, err - } - left = &ast.BinaryExpr{Op: op, Left: left, Right: right, Pos: pos} - } - return left, nil -} - -func (p *parser) parseUnary() (ast.Expr, error) { - if p.matchKind(Minus) { - pos := p.prevPos() - operand, err := p.parseUnary() - if err != nil { - return nil, err - } - return &ast.UnaryExpr{Op: "-", Operand: operand, Pos: pos}, nil - } - if p.matchKind(Plus) { - return p.parseUnary() - } - return p.parsePrimary() -} - -func (p *parser) parsePrimary() (ast.Expr, error) { - tok := p.cur() - switch tok.Kind { - case Ident: - // Base search has no functions: `index=web(status=500)` is a value - // followed by a grouped term, not a call that swallows the filter. - if !p.searchLiterals && p.callAhead(1) { - return p.parseCall() - } - if p.searchLiterals { - // A bare identifier followed by a comparison operator is a field; - // otherwise it is a free-text search term, wildcards included. - if p.comparisonAhead(1) { - p.advance() - return &ast.FieldRef{Name: tok.Text, Pos: tok.Pos}, nil - } - if value, ok := p.scanSearchValue(false); ok { - return &ast.SearchTerm{Value: value, Pos: tok.Pos}, nil - } - } - p.advance() - return &ast.FieldRef{Name: tok.Text, Pos: tok.Pos}, nil - - case String: - if p.searchLiterals { - if p.comparisonAhead(1) { - p.advance() - return &ast.FieldRef{Name: tok.Text, Pos: tok.Pos}, nil - } - p.advance() - return &ast.SearchTerm{Value: tok.Text, Pos: tok.Pos}, nil - } - p.advance() - return &ast.StringLit{Value: tok.Text, Pos: tok.Pos}, nil - - case Number: - value, err := strconv.ParseFloat(tok.Text, 64) - if err != nil { - return nil, diag.NewError(tok.Pos, "syntax", "invalid number %q", tok.Text) - } - p.advance() - return &ast.NumberLit{Raw: tok.Text, Value: value, Pos: tok.Pos}, nil - - case Duration: - p.advance() - return &ast.DurationLit{Raw: tok.Text, Pos: tok.Pos}, nil - - case Star: - if p.searchLiterals { - if value, ok := p.scanSearchValue(false); ok { - return &ast.SearchTerm{Value: value, Pos: tok.Pos}, nil - } - } - p.advance() - return &ast.WildcardLit{Pos: tok.Pos}, nil - - case LParen: - p.advance() - expr, err := p.parseOr() - if err != nil { - return nil, err - } - if err := p.expectKind(RParen, "')'"); err != nil { - return nil, err - } - return expr, nil - - case LBracket: - return nil, diag.NewError(tok.Pos, "unsupported-subsearch", - "subsearches are not implemented yet") - - default: - return nil, diag.NewError(tok.Pos, "syntax", - "expected an expression, found %s", tok.describe()) - } -} - -func (p *parser) parseCall() (ast.Expr, error) { - name := p.cur() - p.advance() // identifier - p.advance() // '(' - - var args []ast.Expr - if p.cur().Kind != RParen { - for { - arg, err := p.parseOr() - if err != nil { - return nil, err - } - args = append(args, arg) - if p.matchKind(Comma) { - continue - } - break - } - } - if err := p.expectKind(RParen, "')'"); err != nil { - return nil, err - } - return &ast.CallExpr{Name: name.Text, Args: args, Pos: name.Pos}, nil -} - -// --- helpers ------------------------------------------------------------- - -func (p *parser) cur() Token { return p.toks[p.i] } - -func (p *parser) peek(n int) Token { - idx := p.i + n - if idx < 0 { - idx = 0 - } - if idx >= len(p.toks) { - return p.toks[len(p.toks)-1] - } - return p.toks[idx] -} - -func (p *parser) advance() { - if p.i < len(p.toks)-1 { - p.i++ - } -} - -func (p *parser) prevPos() ast.Pos { - if p.i == 0 { - return p.toks[0].Pos - } - return p.toks[p.i-1].Pos -} - -// prevTok returns the last consumed token. At the start of input there is -// none, so it returns an EOF token that never touches the current one. -func (p *parser) prevTok() Token { - if p.i == 0 { - return Token{Kind: EOF} - } - return p.toks[p.i-1] -} - -func (p *parser) matchKind(k Kind) bool { - if p.cur().Kind == k { - p.advance() - return true - } - return false -} - -func (p *parser) matchKeyword(word string) bool { - if p.cur().Kind == Ident && strings.EqualFold(p.cur().Text, word) { - p.advance() - return true - } - return false -} - -func (p *parser) expectKind(k Kind, what string) error { - if p.cur().Kind != k { - return diag.NewError(p.cur().Pos, "syntax", "expected %s, found %s", what, p.cur().describe()) - } - p.advance() - return nil -} - -func (p *parser) atStageEnd() bool { - return p.cur().Kind == Pipe || p.cur().Kind == EOF -} - -func (p *parser) expectStageEnd() error { - if !p.atStageEnd() { - return diag.NewError(p.cur().Pos, "syntax", - "unexpected %s; expected '|' or end of query", p.cur().describe()) - } - return nil -} - -func (p *parser) startsTerm() bool { - switch p.cur().Kind { - case Ident: - word := strings.ToLower(p.cur().Text) - return word != "and" && word != "or" && word != "by" && word != "as" - case String, Number, Duration, LParen, LBracket, Star: - return true - } - return false -} - -func (p *parser) comparisonAhead(n int) bool { - switch p.peek(n).Kind { - case Eq, Ne, Lt, Le, Gt, Ge: - return true - } - return false -} - -func (p *parser) callAhead(n int) bool { - return p.peek(n).Kind == LParen -} - -// adjacent reports whether token i ends exactly where token i+n starts. -func (p *parser) adjacent(i, n int) bool { - a, b := p.peek(i), p.peek(i+n) - return a.Pos.Offset+len(a.Text) == b.Pos.Offset -} - -// extractTimeBounds lifts `earliest=` and `latest=` out of the search -// expression and into dedicated IR fields. Splunk treats them as global -// search-time modifiers, so they are lifted out of AND and OR branches alike. -func extractTimeBounds(st *ast.SearchStage) error { - if st.Expr == nil { - return nil - } - expr, err := stripTimeBounds(st.Expr, st) - if err != nil { - return err - } - st.Expr = expr - return nil -} - -func stripTimeBounds(e ast.Expr, st *ast.SearchStage) (ast.Expr, error) { - if u, ok := e.(*ast.UnaryExpr); ok && u.Op == "not" { - inner, err := stripTimeBounds(u.Operand, st) - if err != nil { - return nil, err - } - if inner == nil { - return nil, nil - } - u.Operand = inner - return u, nil - } - b, ok := e.(*ast.BinaryExpr) - if !ok { - return e, nil - } - if b.Op == "and" || b.Op == "or" { - left, err := stripTimeBounds(b.Left, st) - if err != nil { - return nil, err - } - right, err := stripTimeBounds(b.Right, st) - if err != nil { - return nil, err - } - // A lifted bound is TRUE in the row expression. TRUE OR X is TRUE, - // so an OR branch cannot fall back to its sibling; TRUE AND X is X. - if b.Op == "or" { - if left == nil || right == nil { - return nil, nil - } - } else { - if left == nil { - return right, nil - } - if right == nil { - return left, nil - } - } - b.Left, b.Right = left, right - return b, nil - } - if b.Op != "=" { - return e, nil - } - field, ok := b.Left.(*ast.FieldRef) - if !ok { - return e, nil - } - name := strings.ToLower(field.Name) - if name != "earliest" && name != "latest" { - return e, nil - } - raw, ok := timeValue(b.Right) - if !ok { - return e, nil - } - current := &st.Earliest - if name == "latest" { - current = &st.Latest - } - if *current != "" && *current != raw { - return nil, diag.NewError(b.Pos, "conflicting-time-bounds", - "conflicting %s bounds %q and %q", name, *current, raw) - } - *current = raw - return nil, nil -} - -func timeValue(e ast.Expr) (string, bool) { - switch v := e.(type) { - case *ast.StringLit: - return v.Value, true - case *ast.NumberLit: - return v.Raw, true - case *ast.DurationLit: - return v.Raw, true - case *ast.UnaryExpr: - if v.Op == "-" { - if d, ok := v.Operand.(*ast.DurationLit); ok { - return "-" + d.Raw, true - } - } - } - return "", false -} diff --git a/pkg/parser/spl1/parser_test.go b/pkg/parser/spl1/parser_test.go index 360b162..d06d43c 100644 --- a/pkg/parser/spl1/parser_test.go +++ b/pkg/parser/spl1/parser_test.go @@ -177,6 +177,172 @@ func TestSearchTermWildcardRun(t *testing.T) { } } +// TestWildcardTermBeforeStage covers a wildcard that ends a search term right +// before the pipe. It must stay part of the term, not become a multiplication +// whose right operand is missing. +func TestWildcardTermBeforeStage(t *testing.T) { + tests := []struct { + src string + terms []string + }{ + {`a* | stats count`, []string{"a*"}}, + {`a** | stats count`, []string{"a**"}}, + {`a*1 | stats count`, []string{"a*1"}}, + {`a*b | stats count`, []string{"a*b"}}, + {`index=web error* | stats count`, []string{"error*"}}, + {`search a* | stats count`, []string{"a*"}}, + {`*error* | stats count`, []string{"*error*"}}, + {`NOT a* | stats count`, []string{"a*"}}, + {`a* OR b* | stats count`, []string{"a*", "b*"}}, + {`web*prod | stats count`, []string{"web*prod"}}, + } + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + p := mustParse(t, tc.src) + if len(p.Stages) != 2 || p.Stages[1].StageName() != "stats" { + t.Fatalf("stages = %v, want search then stats", p.Stages) + } + expr := p.Stages[0].(*ast.SearchStage).Expr + for _, want := range tc.terms { + if !exprHasTerm(expr, want) { + t.Errorf("expression %#v has no term %q", expr, want) + } + } + }) + } +} + +// TestAdjacentStarStaysMultiplication checks the other side of the boundary: +// a star that does not touch the preceding word is still the multiplication +// operator, as are stars after numbers and durations. +func TestAdjacentStarStaysMultiplication(t *testing.T) { + tests := []string{`a * b | stats count`, `1*2 | stats count`, `5m*2 | stats count`} + for _, src := range tests { + t.Run(src, func(t *testing.T) { + p := mustParse(t, src) + b, ok := p.Stages[0].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + if !ok || b.Op != "*" { + t.Fatalf("expr = %#v, want multiplication", p.Stages[0].(*ast.SearchStage).Expr) + } + }) + } +} + +// TestNotAfterOperatorIsAField covers the NOT_WORD retyping: after an +// arithmetic or comparison operator `not` is a field name, so it does not +// start the negation operator. +func TestNotAfterOperatorIsAField(t *testing.T) { + t.Run("arithmetic right operand", func(t *testing.T) { + p := mustParse(t, `index=web | eval x=1+not`) + e := p.Stages[1].(*ast.EvalStage) + b, ok := e.Assignments[0].Expr.(*ast.BinaryExpr) + if !ok || b.Op != "+" { + t.Fatalf("expr = %#v, want addition", e.Assignments[0].Expr) + } + f, ok := b.Right.(*ast.FieldRef) + if !ok || f.Name != "not" { + t.Fatalf("right side = %#v, want FieldRef not", b.Right) + } + }) + + t.Run("comparison right operand", func(t *testing.T) { + p := mustParse(t, `index=web | where a=not`) + if !exprHasField(p.Stages[1].(*ast.SearchStage).Expr, "not") { + t.Fatalf("expr lost the not field: %#v", p.Stages[1].(*ast.SearchStage).Expr) + } + }) + + t.Run("group key", func(t *testing.T) { + p := mustParse(t, `index=web | stats count by not`) + s := p.Stages[1].(*ast.StatsStage) + if len(s.By) != 1 { + t.Fatalf("by = %#v, want one key", s.By) + } + if f, ok := s.By[0].(*ast.FieldRef); !ok || f.Name != "not" { + t.Fatalf("by[0] = %#v, want FieldRef not", s.By[0]) + } + }) + + t.Run("assignment target", func(t *testing.T) { + p := mustParse(t, `index=web | eval not=1`) + e := p.Stages[1].(*ast.EvalStage) + if e.Assignments[0].Name != "not" { + t.Fatalf("assignment = %#v, want target not", e.Assignments[0]) + } + }) +} + +// TestNotAtExpressionStartIsNegation is the other side of the retyping: at the +// start of an expression `not` is the negation operator, including after an +// `eval` assignment's `=`, and a call with several arguments is then rejected +// at the argument comma instead of becoming a function named `not`. +func TestNotAtExpressionStartIsNegation(t *testing.T) { + tests := []struct { + src string + line int + col int + }{ + {`not%x`, 1, 4}, + {`index=web | eval y=not(x,y)`, 1, 25}, + {`eval y=not(x,y)`, 1, 13}, + {`index=web | eval x=not`, 1, 23}, + } + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + _, err := Parse(tc.src) + if err == nil { + t.Fatal("expected an error") + } + ds, ok := diag.FromError(err) + if !ok || len(ds) != 1 { + t.Fatalf("err = %v, want one diagnostic", err) + } + d := ds[0] + if d.Code != "syntax" || d.Pos.Line != tc.line || d.Pos.Col != tc.col { + t.Fatalf("diagnostic = %#v, want syntax at %d:%d", d, tc.line, tc.col) + } + }) + } + + t.Run("a lone assignment value negates", func(t *testing.T) { + p := mustParse(t, `eval x=not(2)`) + e := p.Stages[0].(*ast.EvalStage) + u, ok := e.Assignments[0].Expr.(*ast.UnaryExpr) + if !ok || u.Op != "not" { + t.Fatalf("expr = %#v, want NOT 2", e.Assignments[0].Expr) + } + }) + + t.Run("assignment value negates a wildcard", func(t *testing.T) { + p := mustParse(t, `eval y=not * b`) + e := p.Stages[0].(*ast.EvalStage) + and, ok := e.Assignments[0].Expr.(*ast.BinaryExpr) + if !ok || and.Op != "and" { + t.Fatalf("expr = %#v, want NOT TRUE AND b", e.Assignments[0].Expr) + } + u, ok := and.Left.(*ast.UnaryExpr) + if !ok || u.Op != "not" { + t.Fatalf("left = %#v, want a negation", and.Left) + } + if _, ok := u.Operand.(*ast.WildcardLit); !ok { + t.Fatalf("operand = %#v, want the wildcard", u.Operand) + } + }) + + t.Run("leading eval keeps a field after an operator", func(t *testing.T) { + p := mustParse(t, `eval x=1+not`) + e := p.Stages[0].(*ast.EvalStage) + b, ok := e.Assignments[0].Expr.(*ast.BinaryExpr) + if !ok || b.Op != "+" { + t.Fatalf("expr = %#v, want addition", e.Assignments[0].Expr) + } + f, ok := b.Right.(*ast.FieldRef) + if !ok || f.Name != "not" { + t.Fatalf("right side = %#v, want FieldRef not", b.Right) + } + }) +} + func TestCallRequiresAdjacency(t *testing.T) { t.Run("grouped term after a value is not a call", func(t *testing.T) { p := mustParse(t, `index=web (status=500)`) @@ -528,3 +694,176 @@ func TestParseErrors(t *testing.T) { }) } } + +// TestValuePositionStarMultiplies pins the star in value position. The driver +// retypes a star that touches the preceding word as STAR_TERM so `a*` stays one +// search term, but in an expression the same spelling is multiplication. +func TestValuePositionStarMultiplies(t *testing.T) { + t.Run("eval assignment", func(t *testing.T) { + p := mustParse(t, `eval x=a*b`) + e := p.Stages[0].(*ast.EvalStage) + b, ok := e.Assignments[0].Expr.(*ast.BinaryExpr) + if !ok || b.Op != "*" { + t.Fatalf("expr = %#v, want multiplication", e.Assignments[0].Expr) + } + if f, ok := b.Left.(*ast.FieldRef); !ok || f.Name != "a" { + t.Fatalf("left = %#v, want FieldRef a", b.Left) + } + if f, ok := b.Right.(*ast.FieldRef); !ok || f.Name != "b" { + t.Fatalf("right = %#v, want FieldRef b", b.Right) + } + }) + + t.Run("comparison left operand", func(t *testing.T) { + p := mustParse(t, `where a*b>2`) + cmp, ok := p.Stages[0].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + if !ok || cmp.Op != ">" { + t.Fatalf("expr = %#v, want a comparison", p.Stages[0].(*ast.SearchStage).Expr) + } + if b, ok := cmp.Left.(*ast.BinaryExpr); !ok || b.Op != "*" { + t.Fatalf("left = %#v, want a product", cmp.Left) + } + }) + + t.Run("aggregate argument", func(t *testing.T) { + p := mustParse(t, `stats sum(a*b)`) + s := p.Stages[0].(*ast.StatsStage) + if b, ok := s.Aggs[0].Arg.(*ast.BinaryExpr); !ok || b.Op != "*" { + t.Fatalf("arg = %#v, want a product", s.Aggs[0].Arg) + } + }) + + t.Run("left associativity", func(t *testing.T) { + p := mustParse(t, `eval pct=count/total*100`) + e := p.Stages[0].(*ast.EvalStage) + b, ok := e.Assignments[0].Expr.(*ast.BinaryExpr) + if !ok || b.Op != "*" { + t.Fatalf("expr = %#v, want (count/total)*100", e.Assignments[0].Expr) + } + if div, ok := b.Left.(*ast.BinaryExpr); !ok || div.Op != "/" { + t.Fatalf("left = %#v, want a division", b.Left) + } + }) +} + +// TestStarAfterOperandIsMultiplication covers the operator role on the other +// side: a star with an operand to its left is a multiplication operator, so the +// star after it is that product's right operand (a wildcard), not the start of +// an implicit-AND term. +func TestStarAfterOperandIsMultiplication(t *testing.T) { + t.Run("wildcard operand", func(t *testing.T) { + p := mustParse(t, `a * * | stats count`) + expr := p.Stages[0].(*ast.SearchStage).Expr + b, ok := expr.(*ast.BinaryExpr) + if !ok || b.Op != "*" { + t.Fatalf("expr = %#v, want multiplication", expr) + } + if _, ok := b.Left.(*ast.SearchTerm); !ok { + t.Fatalf("left = %#v, want the search term a", b.Left) + } + if _, ok := b.Right.(*ast.WildcardLit); !ok { + t.Fatalf("right = %#v, want the wildcard", b.Right) + } + }) + + t.Run("field operand", func(t *testing.T) { + p := mustParse(t, `where a * not`) + b, ok := p.Stages[0].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + if !ok || b.Op != "*" { + t.Fatalf("expr = %#v, want multiplication", p.Stages[0].(*ast.SearchStage).Expr) + } + if f, ok := b.Right.(*ast.FieldRef); !ok || f.Name != "not" { + t.Fatalf("right = %#v, want FieldRef not", b.Right) + } + }) +} + +// TestStarNeedsAValueAfterTheOperator checks where the parser stops when a +// multiplication star has no operand: at the token that cannot begin one, in +// both term position and value position. +func TestStarNeedsAValueAfterTheOperator(t *testing.T) { + tests := []struct { + src string + line int + col int + }{ + {`a * * *`, 1, 8}, + {`a * * * | stats count`, 1, 9}, + {`where * *`, 1, 10}, + {`where (a*)`, 1, 10}, + {`where (a * )`, 1, 12}, + {`stats sum(a*)`, 1, 13}, + {`stats sum(a * )`, 1, 15}, + {`where * not`, 1, 12}, + } + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + _, err := Parse(tc.src) + if err == nil { + t.Fatal("expected an error") + } + ds, ok := diag.FromError(err) + if !ok || len(ds) != 1 { + t.Fatalf("err = %v, want one diagnostic", err) + } + d := ds[0] + if d.Code != "syntax" || d.Pos.Line != tc.line || d.Pos.Col != tc.col { + t.Fatalf("diagnostic = %#v, want syntax at %d:%d", d, tc.line, tc.col) + } + }) + } +} + +// TestSortSignOnAKeywordField covers `sort` with a sign before a word that is +// otherwise the limit keyword or the negation keyword: the sign rules the +// keyword reading out, so the word is a field name. +func TestSortSignOnAKeywordField(t *testing.T) { + tests := []struct { + src string + name string + desc bool + }{ + {`head 5 | sort -limit`, "limit", true}, + {`head 5 | sort +limit`, "limit", false}, + {`head 5 | sort -not`, "not", true}, + {`head 5 | sort -limit, +host`, "limit", true}, + } + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + p := mustParse(t, tc.src) + s, ok := p.Stages[len(p.Stages)-1].(*ast.SortStage) + if !ok || len(s.Fields) == 0 { + t.Fatalf("last stage = %#v, want a sort field", p.Stages[len(p.Stages)-1]) + } + if s.Fields[0].Name != tc.name || s.Fields[0].Desc != tc.desc { + t.Fatalf("field = %#v, want %s desc=%v", s.Fields[0], tc.name, tc.desc) + } + }) + } +} + +// TestBinRejectsSecondField covers the single-field rule: the second field is +// refused at its own token, before any later argument error can be reported. +func TestBinRejectsSecondField(t *testing.T) { + const want = `bin accepts exactly one field; found "b" after "a"` + tests := []string{`bin a b(`, `bin a b +`, `bin a b span=1h x(`, `bin a b where x ==`} + for _, src := range tests { + t.Run(src, func(t *testing.T) { + _, err := Parse(src) + if err == nil { + t.Fatal("expected an error") + } + ds, ok := diag.FromError(err) + if !ok || len(ds) != 1 { + t.Fatalf("err = %v, want one diagnostic", err) + } + d := ds[0] + if d.Code != "syntax" || d.Pos.Line != 1 || d.Pos.Col != 7 { + t.Fatalf("diagnostic = %#v, want syntax at 1:7", d) + } + if d.Message != want { + t.Fatalf("message = %q, want %q", d.Message, want) + } + }) + } +} diff --git a/pkg/parser/spl1/tight.go b/pkg/parser/spl1/tight.go new file mode 100644 index 0000000..2dd44a4 --- /dev/null +++ b/pkg/parser/spl1/tight.go @@ -0,0 +1,336 @@ +package spl1 + +import ( + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/parser/spl1/gen" +) + +// tightStream retypes the tokens that begin a comparison-RHS value run. +// +// Classic SPL decides between a literal value run and an expression on the +// right of a comparison by what the value tokens look like: `host=web*` is the +// literal `web*`, while `host=1+1` is an expression. The grammar cannot make +// that choice with a predicate, because ANTLR's SLL prediction never uses a +// semantic predicate to prune a simulation: alternatives that share a first +// token and differ only by predicates are simulated together to the end of the +// entry rule, and when both die there the parser reports no viable alternative +// instead of asking the predicates. That is exactly what happened to +// `host=web* | head`, where the value and expression alternatives both reach +// the stage pipe and then run out of input. +// +// So the driver retypes the STAR, MINUS, and NUMBER tokens that begin a value +// run — the same test as the hand parser's startsSearchValue — and the grammar +// decides on the token type alone. +// +// Only the parser's lookahead is retyped. The token stream, the parse tree, +// and the Lex adapter keep the tokens the lexer produced, so the lowering code +// still reads STAR, MINUS, and NUMBER for operators and the public token API +// is unchanged; the tight spelling exists only for grammar decisions. +type tightStream struct { + *antlr.CommonTokenStream + types map[int]int +} + +// tightToken is a token with a rewritten type. Every other method is the +// lexer's token, so text, spans, and positions are unchanged. +type tightToken struct { + antlr.Token + typ int +} + +func (t tightToken) GetTokenType() int { return t.typ } + +func (s *tightStream) LT(k int) antlr.Token { + t := s.CommonTokenStream.LT(k) + if t == nil { + return nil + } + if typ, ok := s.types[t.GetTokenIndex()]; ok { + return tightToken{Token: t, typ: typ} + } + return t +} + +func (s *tightStream) LA(k int) int { + t := s.LT(k) + if t == nil { + return antlr.TokenInvalidType + } + return t.GetTokenType() +} + +// tightTokenTypes reports the retyping for a filled token stream. +// +// A STAR that touches a preceding word is STAR_TERM: the wildcard is part of +// that word's search term (`error*`, `*error*`, `a**`). This is decided before +// the value-run rules and takes precedence, because such a star touches a word +// on the left even when it also touches one on the right (`a*b`, where the hand +// parser reads one term, not a product). +// +// The remaining tokens start a value run only when they touch what follows: +// +// NUMBER followed by MINUS or STAR +// STAR followed by a word or number, or by MINUS and then a word, number, +// or another STAR +// MINUS followed by a word or STAR +// +// A duration is a word for neither a star nor a hyphen: `*1h` and `-1h` do not +// start a value run. A hyphen never merges a number, so `host=-1` stays unary +// minus, exactly as startsSearchValue has it. A number is not a word for +// STAR_TERM either, so `1*2` and `5m*2` stay multiplication, like `(a)*b`. +// +// A NOT that follows an arithmetic or comparison operator is NOT_WORD: there +// it is a field name (`eval x=1+not`), while at the start of an expression it +// is the negation operator and must commit (`not%x` is an error). An `eval` +// assignment's `=` starts an expression, so `eval x=not(2)` stays a negation. +// The grammar's expression primaries accept NOT_WORD and reject a bare NOT, so +// the choice does not depend on prediction. +func tightTokenTypes(toks []antlr.Token) map[int]int { + types := make(map[int]int) + assignments := evalAssignmentEquals(toks) + for i, t := range toks { + if t.GetTokenType() != spl1gen.SPL1ParserNOT { + continue + } + prev := tokenAt(toks, i-1) + if prev == nil || !notFollowsOperator(toks, i-1, assignments) { + continue + } + // An assignment's '=' starts an expression, so `eval x=not` is the + // negation operator; only an operator inside an expression makes a + // following `not` a field name. + if prev.GetTokenType() == spl1gen.SPL1ParserEQ && assignments[prev.GetTokenIndex()] { + continue + } + types[t.GetTokenIndex()] = spl1gen.SPL1ParserNOT_WORD + } + + for i, t := range toks { + if t.GetTokenType() != spl1gen.SPL1ParserSTAR { + continue + } + prev := tokenAt(toks, i-1) + if prev == nil || prev.GetStop()+1 != t.GetStart() { + continue + } + prevType := prev.GetTokenType() + if isIdentLikeToken(prevType) || types[prev.GetTokenIndex()] == spl1gen.SPL1ParserSTAR_TERM { + types[t.GetTokenIndex()] = spl1gen.SPL1ParserSTAR_TERM + } + } + + // A star with an operand on its left can only multiply, never begin a + // term, and the grammar says so with its own token type. A predicate + // cannot: SLL prediction simulates the implicit-AND alternative whenever + // both start with a star, and ignores the predicate. Two stars in a row + // alternate roles, and the alternation differs between term position and + // value position, so a star that follows a star keeps its plain type and + // the grammar's own loops decide (`a * *` is `a * TRUE`). + for i, t := range toks { + if t.GetTokenType() != spl1gen.SPL1ParserSTAR { + continue + } + if _, ok := types[t.GetTokenIndex()]; ok { + continue + } + if !starHasLeftOperand(toks, i, assignments) { + continue + } + if prev := tokenAt(toks, i-1); prev != nil && + prev.GetTokenType() == spl1gen.SPL1ParserSTAR { + continue + } + types[t.GetTokenIndex()] = spl1gen.SPL1ParserSTAR_OP + } + + for i, t := range toks { + if _, ok := types[t.GetTokenIndex()]; ok { + continue + } + next := tokenAt(toks, i+1) + if next == nil || t.GetStop()+1 != next.GetStart() { + continue + } + switch t.GetTokenType() { + case spl1gen.SPL1ParserNUMBER: + if isStarOrMinus(next.GetTokenType()) { + types[t.GetTokenIndex()] = spl1gen.SPL1ParserNUMBER_TIGHT + } + + case spl1gen.SPL1ParserSTAR: + if isValueWord(next.GetTokenType()) { + types[t.GetTokenIndex()] = spl1gen.SPL1ParserSTAR_TIGHT + continue + } + if next.GetTokenType() != spl1gen.SPL1ParserMINUS { + continue + } + after := tokenAt(toks, i+2) + if after != nil && next.GetStop()+1 == after.GetStart() && + (isValueWord(after.GetTokenType()) || after.GetTokenType() == spl1gen.SPL1ParserSTAR) { + types[t.GetTokenIndex()] = spl1gen.SPL1ParserSTAR_TIGHT + } + + case spl1gen.SPL1ParserMINUS: + if isIdentLikeToken(next.GetTokenType()) || next.GetTokenType() == spl1gen.SPL1ParserSTAR { + types[t.GetTokenIndex()] = spl1gen.SPL1ParserMINUS_TIGHT + } + } + } + return types +} + +// isValueWord reports whether t is a word or number as a value run sees it. +// Keywords are words too; a duration is not. +func isValueWord(t int) bool { + return isIdentLikeToken(t) || t == spl1gen.SPL1ParserNUMBER +} + +// evalAssignmentEquals reports which EQ tokens are `eval` assignment +// separators rather than comparisons. Only those start an expression, where a +// following `not` is the negation operator. +func evalAssignmentEquals(toks []antlr.Token) map[int]bool { + eqs := make(map[int]bool) + // A pipeline may also begin with `eval`, with no pipe before it. + inEval := false + expectLHS := false + if first := tokenAt(toks, 0); first != nil && + first.GetTokenType() == spl1gen.SPL1ParserEVAL { + inEval = true + expectLHS = true + } + depth := 0 + for i, t := range toks { + switch t.GetTokenType() { + case spl1gen.SPL1ParserPIPE: + inEval = false + expectLHS = false + depth = 0 + if cmd := tokenAt(toks, i+1); cmd != nil && + cmd.GetTokenType() == spl1gen.SPL1ParserEVAL { + inEval = true + expectLHS = true + } + case spl1gen.SPL1ParserLPAREN: + depth++ + case spl1gen.SPL1ParserRPAREN: + if depth > 0 { + depth-- + } + case spl1gen.SPL1ParserCOMMA: + if inEval && depth == 0 { + expectLHS = true + } + case spl1gen.SPL1ParserEQ: + if inEval && depth == 0 && expectLHS { + eqs[t.GetTokenIndex()] = true + expectLHS = false + } + } + } + return eqs +} + +// notFollowsOperator reports whether the token at index j puts a following +// `not` in field position, as opposed to the start of an expression where it is +// the negation keyword. +func notFollowsOperator(toks []antlr.Token, j int, assignments map[int]bool) bool { + switch t := toks[j].GetTokenType(); t { + case spl1gen.SPL1ParserSTAR: + // A star only multiplies when it has a left operand. `where a * not` + // reads `not` as a field, while `where * not` is a wildcard term + // followed by the negation keyword. + return starHasLeftOperand(toks, j, assignments) + case spl1gen.SPL1ParserPLUS, spl1gen.SPL1ParserMINUS, + spl1gen.SPL1ParserSLASH, spl1gen.SPL1ParserPERCENT, + spl1gen.SPL1ParserEQ2, spl1gen.SPL1ParserEQ, spl1gen.SPL1ParserNE, + spl1gen.SPL1ParserLT, spl1gen.SPL1ParserLE, spl1gen.SPL1ParserGT, + spl1gen.SPL1ParserGE: + return true + } + return false +} + +// starHasLeftOperand reports whether the star at index j multiplies an operand +// to its left rather than starting an expression. A star after a completed +// operand is multiplication; a star after a command keyword that starts the +// stage, or after an operator or `(`, begins a wildcard term. +func starHasLeftOperand(toks []antlr.Token, j int, assignments map[int]bool) bool { + prev := tokenAt(toks, j-1) + if prev == nil { + return false + } + t := prev.GetTokenType() + switch { + case t == spl1gen.SPL1ParserNOT: + // `not` is the negation keyword where an expression starts and a + // field name only after an arithmetic or comparison operator. An + // assignment's '=' starts an expression, so it does not make the + // `not` a field: `eval y=not * b` negates the wildcard. + before := tokenAt(toks, j-2) + if before == nil || !isArithmeticOrComparison(before.GetTokenType()) { + return false + } + return !(before.GetTokenType() == spl1gen.SPL1ParserEQ && + assignments[before.GetTokenIndex()]) + case isIdentLikeToken(t): + // A command keyword at the start of a stage is the command itself, + // not a field: `where * not` starts with a wildcard term. + return !(isCommandKeyword(t) && isStageStart(toks, j-1)) + case t == spl1gen.SPL1ParserSTRING || t == spl1gen.SPL1ParserNUMBER || + t == spl1gen.SPL1ParserDURATION || t == spl1gen.SPL1ParserRPAREN || + t == spl1gen.SPL1ParserRBRACKET || t == spl1gen.SPL1ParserSTAR: + return true + } + return false +} + +// isArithmeticOrComparison reports whether t is an operator whose right operand +// is a primary, so a following `not` is a field name there. +func isArithmeticOrComparison(t int) bool { + switch t { + case spl1gen.SPL1ParserPLUS, spl1gen.SPL1ParserMINUS, + spl1gen.SPL1ParserSLASH, spl1gen.SPL1ParserPERCENT, + spl1gen.SPL1ParserEQ2, spl1gen.SPL1ParserEQ, spl1gen.SPL1ParserNE, + spl1gen.SPL1ParserLT, spl1gen.SPL1ParserLE, spl1gen.SPL1ParserGT, + spl1gen.SPL1ParserGE: + return true + } + return false +} + +// isCommandKeyword reports whether t names a command the grammar implements. +func isCommandKeyword(t int) bool { + switch t { + case spl1gen.SPL1ParserSEARCH, spl1gen.SPL1ParserWHERE, + spl1gen.SPL1ParserSTATS, spl1gen.SPL1ParserTIMECHART, + spl1gen.SPL1ParserEVAL, spl1gen.SPL1ParserREX, + spl1gen.SPL1ParserTABLE, spl1gen.SPL1ParserFIELDS, + spl1gen.SPL1ParserSORT, spl1gen.SPL1ParserHEAD, + spl1gen.SPL1ParserBIN: + return true + } + return false +} + +// isStageStart reports whether index j begins a stage: the first token of the +// query, or the first token after a pipe. +func isStageStart(toks []antlr.Token, j int) bool { + if j == 0 { + return true + } + prev := tokenAt(toks, j-1) + return prev != nil && prev.GetTokenType() == spl1gen.SPL1ParserPIPE +} + +func isStarOrMinus(t int) bool { + return t == spl1gen.SPL1ParserSTAR || t == spl1gen.SPL1ParserMINUS +} + +func tokenAt(toks []antlr.Token, i int) antlr.Token { + if i >= 0 && i < len(toks) { + return toks[i] + } + return nil +} diff --git a/pkg/parser/spl2/bench_test.go b/pkg/parser/spl2/bench_test.go new file mode 100644 index 0000000..f9624fc --- /dev/null +++ b/pkg/parser/spl2/bench_test.go @@ -0,0 +1,17 @@ +package spl2 + +import "testing" + +// benchmarkQuery exercises every stage of the subset: a dataset, a compound +// condition, and a grouped aggregation with an alias. +const benchmarkQuery = `from logs-2024-01 | where status=500 AND host="web" ` + + `| stats count() AS failures, dc(user) AS users BY host, status` + +func BenchmarkParse(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := Parse(benchmarkQuery); err != nil { + b.Fatal(err) + } + } +} diff --git a/pkg/parser/spl2/build.go b/pkg/parser/spl2/build.go new file mode 100644 index 0000000..9967feb --- /dev/null +++ b/pkg/parser/spl2/build.go @@ -0,0 +1,351 @@ +package spl2 + +import ( + "strconv" + "strings" + + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/ast" + "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" + "github.com/be-thomas/openspl/pkg/parser/spl2/gen" +) + +// builder lowers parsed rule contexts into the IR. The grammar decides what +// the query means; the builder carries the SPL2 defaults (aggregate name +// normalization, alias spelling), converts positions through the source map, +// and reports the semantic refusals the grammar deliberately leaves out. +type builder struct { + m *antlrpos.SourceMap + toks []antlr.Token + parser *spl2gen.SPL2Parser +} + +func (b *builder) pos(t antlr.Token) ast.Pos { return b.m.Pos(t) } + +// text returns the source text of a rule context, sliced from the first to the +// last token so a dataset name keeps its exact spelling. +func (b *builder) text(ctx antlr.ParserRuleContext) string { + return b.m.Slice(ctx.GetStart(), ctx.GetStop()) +} + +// --- stages --------------------------------------------------------------- + +// from lowers `from ` to the same IR shape classic SPL produces for +// `index=`, so the emitters resolve the index through one path. +func (b *builder) from(ctx spl2gen.IStageFromContext) (ast.Stage, error) { + fromTok := ctx.FROM().GetSymbol() + name := ctx.IndexName() + first := name.GetStart() + dataset := b.text(name) + + if strings.ContainsAny(dataset, ":") { + return nil, diag.NewError(b.pos(first), "unsupported-dataset", + "dataset %q is namespaced; only plain index names are supported", dataset) + } + + expr := &ast.BinaryExpr{ + Op: "=", + Left: &ast.FieldRef{Name: "index", Pos: b.pos(fromTok)}, + Right: &ast.StringLit{Value: dataset, Pos: b.pos(first)}, + Pos: b.pos(fromTok), + } + return &ast.SearchStage{Expr: expr, Pos: b.pos(fromTok)}, nil +} + +func (b *builder) where(ctx spl2gen.IStageWhereContext) (ast.Stage, error) { + whereTok := ctx.WHERE().GetSymbol() + expr, err := b.expr(ctx.Expr()) + if err != nil { + return nil, err + } + return &ast.SearchStage{Expr: expr, Pos: b.pos(whereTok)}, nil +} + +func (b *builder) stats(ctx spl2gen.IStageStatsContext) (ast.Stage, error) { + statsTok := ctx.STATS().GetSymbol() + aggs, err := b.aggList(ctx.AggList()) + if err != nil { + return nil, err + } + var by []ast.Expr + if clause := ctx.ByClause(); clause != nil { + by, err = b.byClause(clause) + if err != nil { + return nil, err + } + } + return &ast.StatsStage{Aggs: aggs, By: by, Pos: b.pos(statsTok)}, nil +} + +// --- aggregates ----------------------------------------------------------- + +func (b *builder) aggList(ctx spl2gen.IAggListContext) ([]ast.Aggregate, error) { + out := make([]ast.Aggregate, 0, len(ctx.AllAgg())) + for _, a := range ctx.AllAgg() { + agg, err := b.agg(a) + if err != nil { + return nil, err + } + out = append(out, agg) + } + return out, nil +} + +func (b *builder) agg(ctx spl2gen.IAggContext) (ast.Aggregate, error) { + fnTok := ctx.IdentLike().GetStart() + agg := ast.Aggregate{ + Func: normalizeAggFunc(strings.ToLower(fnTok.GetText())), + Pos: b.pos(fnTok), + } + if arg := ctx.Expr(); arg != nil { + expr, err := b.expr(arg) + if err != nil { + return ast.Aggregate{}, err + } + agg.Arg = expr + } + if alias := ctx.AliasClause(); alias != nil { + agg.Alias = alias.IdentLike().GetStart().GetText() + } + return agg, nil +} + +// normalizeAggFunc maps the SPL2 spellings of an aggregate onto the IR name the +// emitters know. An unknown name is left as written: the emitter refuses it +// with its own diagnostic. +func normalizeAggFunc(name string) string { + switch name { + case "distinct_count": + return "dc" + } + return name +} + +func (b *builder) byClause(ctx spl2gen.IByClauseContext) ([]ast.Expr, error) { + list := ctx.FieldList() + out := make([]ast.Expr, 0, len(list.AllField())) + for _, fe := range list.AllField() { + tok := fe.IdentLike().GetStart() + out = append(out, &ast.FieldRef{Name: tok.GetText(), Pos: b.pos(tok)}) + } + return out, nil +} + +// --- expressions ---------------------------------------------------------- + +func (b *builder) expr(ctx spl2gen.IExprContext) (ast.Expr, error) { + return b.orExpr(ctx.OrExpr()) +} + +func (b *builder) orExpr(ctx spl2gen.IOrExprContext) (ast.Expr, error) { + left, err := b.andExpr(ctx.AndExpr()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllOrTail() { + right, err := b.andExpr(tail.AndExpr()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "or", Left: left, Right: right, Pos: b.pos(tail.OR().GetSymbol())} + } + return left, nil +} + +func (b *builder) andExpr(ctx spl2gen.IAndExprContext) (ast.Expr, error) { + left, err := b.notExpr(ctx.NotExpr()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllAndTail() { + right, err := b.notExpr(tail.NotExpr()) + if err != nil { + return nil, err + } + left = &ast.BinaryExpr{Op: "and", Left: left, Right: right, Pos: b.pos(tail.AND().GetSymbol())} + } + return left, nil +} + +func (b *builder) notExpr(ctx spl2gen.INotExprContext) (ast.Expr, error) { + if ctx.Comparison() != nil { + return b.comparison(ctx.Comparison()) + } + opTok := notOperator(ctx.NOT(), ctx.BANG()) + operand, err := b.notExpr(ctx.NotExpr()) + if err != nil { + return nil, err + } + return &ast.UnaryExpr{Op: "not", Operand: operand, Pos: b.pos(opTok)}, nil +} + +func (b *builder) comparison(ctx spl2gen.IComparisonContext) (ast.Expr, error) { + left, err := b.additive(ctx.Additive()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllComparisonTail() { + right, err := b.additive(tail.Additive()) + if err != nil { + return nil, err + } + opTok := tail.CompOp().GetStart() + left = &ast.BinaryExpr{ + Op: comparisonOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) additive(ctx spl2gen.IAdditiveContext) (ast.Expr, error) { + left, err := b.multiplicative(ctx.Multiplicative()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllAdditiveTail() { + right, err := b.multiplicative(tail.Multiplicative()) + if err != nil { + return nil, err + } + opTok := tail.AddOp().GetStart() + left = &ast.BinaryExpr{ + Op: additiveOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) multiplicative(ctx spl2gen.IMultiplicativeContext) (ast.Expr, error) { + left, err := b.unary(ctx.Unary()) + if err != nil { + return nil, err + } + for _, tail := range ctx.AllMultiplicativeTail() { + right, err := b.unary(tail.Unary()) + if err != nil { + return nil, err + } + opTok := tail.MulOp().GetStart() + left = &ast.BinaryExpr{ + Op: multiplicativeOperator(opTok.GetTokenType()), + Left: left, + Right: right, + Pos: b.pos(opTok), + } + } + return left, nil +} + +func (b *builder) unary(ctx spl2gen.IUnaryContext) (ast.Expr, error) { + if ctx.Primary() != nil { + return b.primary(ctx.Primary()) + } + signTok := ctx.Sign().GetStart() + operand, err := b.unary(ctx.Unary()) + if err != nil { + return nil, err + } + op := "+" + if signTok.GetTokenType() == spl2gen.SPL2ParserMINUS { + op = "-" + } + return &ast.UnaryExpr{Op: op, Operand: operand, Pos: b.pos(signTok)}, nil +} + +func (b *builder) primary(ctx spl2gen.IPrimaryContext) (ast.Expr, error) { + switch ctx.GetStart().GetTokenType() { + case spl2gen.SPL2ParserLPAREN: + return b.expr(ctx.Expr(0)) + + case spl2gen.SPL2ParserSTRING: + tok := ctx.STRING().GetSymbol() + return &ast.StringLit{Value: decodeString(tok.GetText()), Pos: b.pos(tok)}, nil + + case spl2gen.SPL2ParserNUMBER: + tok := ctx.NUMBER().GetSymbol() + value, err := strconv.ParseFloat(tok.GetText(), 64) + if err != nil { + return nil, diag.NewError(b.pos(tok), "syntax", "invalid number %q", tok.GetText()) + } + return &ast.NumberLit{Raw: tok.GetText(), Value: value, Pos: b.pos(tok)}, nil + + case spl2gen.SPL2ParserDURATION: + tok := ctx.DURATION().GetSymbol() + return &ast.DurationLit{Raw: tok.GetText(), Pos: b.pos(tok)}, nil + + case spl2gen.SPL2ParserLBRACKET: + // The grammar aborts at the bracket; this path is unreachable but + // keeps the switch total without a nil dereference. + return nil, diag.NewError(b.pos(ctx.GetStart()), "unsupported-subsearch", + "subsearches are not supported") + } + + name := ctx.IdentLike().GetStart() + if ctx.LPAREN() == nil { + return &ast.FieldRef{Name: name.GetText(), Pos: b.pos(name)}, nil + } + + args := make([]ast.Expr, 0, len(ctx.AllExpr())) + for _, arg := range ctx.AllExpr() { + expr, err := b.expr(arg) + if err != nil { + return nil, err + } + args = append(args, expr) + } + return &ast.CallExpr{Name: name.GetText(), Args: args, Pos: b.pos(name)}, nil +} + +// --- helpers -------------------------------------------------------------- + +func notOperator(not antlr.TerminalNode, bang antlr.TerminalNode) antlr.Token { + if not != nil { + return not.GetSymbol() + } + return bang.GetSymbol() +} + +func comparisonOperator(t int) string { + switch t { + case spl2gen.SPL2ParserEQ2, spl2gen.SPL2ParserEQ: + return "=" + case spl2gen.SPL2ParserNE: + return "!=" + case spl2gen.SPL2ParserLT: + return "<" + case spl2gen.SPL2ParserLE: + return "<=" + case spl2gen.SPL2ParserGT: + return ">" + case spl2gen.SPL2ParserGE: + return ">=" + } + return "" +} + +func additiveOperator(t int) string { + if t == spl2gen.SPL2ParserMINUS { + return "-" + } + return "+" +} + +func multiplicativeOperator(t int) string { + switch t { + case spl2gen.SPL2ParserSTAR: + return "*" + case spl2gen.SPL2ParserSLASH: + return "/" + case spl2gen.SPL2ParserPERCENT: + return "%" + } + return "" +} diff --git a/pkg/parser/spl2/fuzz_test.go b/pkg/parser/spl2/fuzz_test.go new file mode 100644 index 0000000..4ff8c6c --- /dev/null +++ b/pkg/parser/spl2/fuzz_test.go @@ -0,0 +1,96 @@ +package spl2 + +import ( + "strings" + "testing" + "unicode/utf8" + + "github.com/be-thomas/openspl/pkg/diag" +) + +// FuzzParseSPL2 checks the SPL2 subset's contract for arbitrary input: it +// returns either a pipeline or a *diag.Error carrying at least one positioned +// diagnostic. A panic, an unpositioned error, or a nil pipeline with a nil +// error is a failure. Everything outside the subset must be refused rather +// than approximated, so a successful parse is also checked for its shape: the +// first stage is always `from`. +func FuzzParseSPL2(f *testing.F) { + seeds := []string{ + `from main`, + `from main | where status=500`, + `from main | where status=500 AND host="web" | stats count() AS n BY host`, + `from logs-2024-01 | stats dc(user) BY host`, + `from logs*`, + `from *`, + `from datamodel:events`, + `from main | eval x=1`, + `from main | where status=*`, + `from main | stats count(*)`, + `from a | from b`, + `from main |`, + `| from main`, + `index=web | stats count`, + ` `, + `from main | where (a=1`, + `from main | where a in (1,2)`, + `from main | stats count()`, + `from main | where a=1 or b=2`, + `from main | where not a=1`, + `from main | stats sum(bytes) AS total BY host, status`, + `from "quoted"`, + `from main | stats`, + "from main\r\n| where status=500\r\n", + } + for _, s := range seeds { + f.Add(s) + } + + f.Fuzz(func(t *testing.T, src string) { + // Keep the corpus bounded: the point is parser shape, not a stress test. + if len(src) > 1<<16 || !utf8.ValidString(src) { + t.Skip() + } + + p, err := Parse(src) + if err != nil { + assertDiagError(t, src, err) + return + } + if p == nil { + t.Fatalf("Parse(%q) returned no pipeline and no error", src) + } + if len(p.Stages) == 0 { + t.Fatalf("Parse(%q) returned an empty pipeline", src) + } + if got := p.Stages[0].StageName(); got != "search" { + t.Fatalf("Parse(%q) starts with stage %q, want the lowered from search", src, got) + } + for _, s := range p.Stages { + if pos := s.Position(); pos.Line < 1 || pos.Col < 1 || pos.Offset < 0 { + t.Fatalf("Parse(%q) produced stage position %+v", src, pos) + } + } + }) +} + +// assertDiagError requires a positioned *diag.Error. The parser is expected to +// report invalid input rather than fail in a way the caller cannot print. +func assertDiagError(t *testing.T, src string, err error) { + t.Helper() + + ds, ok := diag.FromError(err) + if !ok { + t.Fatalf("Parse(%q) returned %T %v, want *diag.Error", src, err, err) + } + if len(ds) == 0 { + t.Fatalf("Parse(%q) returned an empty diagnostic list", src) + } + for _, d := range ds { + if d.Pos.Line < 1 || d.Pos.Col < 1 || d.Pos.Offset < 0 { + t.Fatalf("Parse(%q) produced diagnostic %+v at %+v", src, d, d.Pos) + } + if d.Code == "" || strings.TrimSpace(d.Code) != d.Code { + t.Fatalf("Parse(%q) produced diagnostic with code %q", src, d.Code) + } + } +} diff --git a/pkg/parser/spl2/gen/spl2_base_visitor.go b/pkg/parser/spl2/gen/spl2_base_visitor.go new file mode 100644 index 0000000..cf66950 --- /dev/null +++ b/pkg/parser/spl2/gen/spl2_base_visitor.go @@ -0,0 +1,140 @@ +// Code generated from pkg/parser/spl2/grammar/SPL2.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl2gen // SPL2 +import "github.com/antlr4-go/antlr/v4" + +type BaseSPL2Visitor struct { + *antlr.BaseParseTreeVisitor +} + +func (v *BaseSPL2Visitor) VisitStageFrom(ctx *StageFromContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitStageWhere(ctx *StageWhereContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitStageStats(ctx *StageStatsContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitStageEnd(ctx *StageEndContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitIndexName(ctx *IndexNameContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitIndexTail(ctx *IndexTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitExpr(ctx *ExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitOrExpr(ctx *OrExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitOrTail(ctx *OrTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAndExpr(ctx *AndExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAndTail(ctx *AndTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitNotExpr(ctx *NotExprContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitComparison(ctx *ComparisonContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitComparisonTail(ctx *ComparisonTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAdditive(ctx *AdditiveContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAdditiveTail(ctx *AdditiveTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitMultiplicative(ctx *MultiplicativeContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitMultiplicativeTail(ctx *MultiplicativeTailContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitUnary(ctx *UnaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitPrimary(ctx *PrimaryContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitSubsearch(ctx *SubsearchContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAbsentOperand(ctx *AbsentOperandContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAggList(ctx *AggListContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAgg(ctx *AggContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAliasClause(ctx *AliasClauseContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitByClause(ctx *ByClauseContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitFieldList(ctx *FieldListContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitField(ctx *FieldContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitCompOp(ctx *CompOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitAddOp(ctx *AddOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitMulOp(ctx *MulOpContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitSign(ctx *SignContext) interface{} { + return v.VisitChildren(ctx) +} + +func (v *BaseSPL2Visitor) VisitIdentLike(ctx *IdentLikeContext) interface{} { + return v.VisitChildren(ctx) +} diff --git a/pkg/parser/spl2/gen/spl2_lexer.go b/pkg/parser/spl2/gen/spl2_lexer.go new file mode 100644 index 0000000..dcb05d9 --- /dev/null +++ b/pkg/parser/spl2/gen/spl2_lexer.go @@ -0,0 +1,258 @@ +// Code generated from pkg/parser/spl2/grammar/SPL2.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl2gen + +import ( + "fmt" + "github.com/antlr4-go/antlr/v4" + "sync" + "unicode" +) + +// Suppress unused import error +var _ = fmt.Printf +var _ = sync.Once{} +var _ = unicode.IsLetter + +type SPL2Lexer struct { + *antlr.BaseLexer + channelNames []string + modeNames []string + // TODO: EOF string +} + +var SPL2LexerLexerStaticData struct { + once sync.Once + serializedATN []int32 + ChannelNames []string + ModeNames []string + LiteralNames []string + SymbolicNames []string + RuleNames []string + PredictionContextCache *antlr.PredictionContextCache + atn *antlr.ATN + decisionToDFA []*antlr.DFA +} + +func spl2lexerLexerInit() { + staticData := &SPL2LexerLexerStaticData + staticData.ChannelNames = []string{ + "DEFAULT_TOKEN_CHANNEL", "HIDDEN", + } + staticData.ModeNames = []string{ + "DEFAULT_MODE", + } + staticData.LiteralNames = []string{ + "", "", "", "", "", "", "", "", "", "", "", "", "", "'=='", "'!='", + "'<='", "'>='", "'='", "'<'", "'>'", "'!'", "'|'", "','", "'('", "')'", + "'['", "']'", "'+'", "'-'", "'*'", "'/'", "'%'", + } + staticData.SymbolicNames = []string{ + "", "FROM", "WHERE", "STATS", "BY", "AS", "AND", "OR", "NOT", "DURATION", + "NUMBER", "STRING", "IDENT", "EQ2", "NE", "LE", "GE", "EQ", "LT", "GT", + "BANG", "PIPE", "COMMA", "LPAREN", "RPAREN", "LBRACKET", "RBRACKET", + "PLUS", "MINUS", "STAR", "SLASH", "PERCENT", "WS", "UNKNOWN", + } + staticData.RuleNames = []string{ + "FROM", "WHERE", "STATS", "BY", "AS", "AND", "OR", "NOT", "DURATION", + "NUMBER", "STRING", "DQ_BODY", "SQ_BODY", "IDENT", "EQ2", "NE", "LE", + "GE", "EQ", "LT", "GT", "BANG", "PIPE", "COMMA", "LPAREN", "RPAREN", + "LBRACKET", "RBRACKET", "PLUS", "MINUS", "STAR", "SLASH", "PERCENT", + "WS", "UNKNOWN", "DIGITS", "EXPONENT", "UNIT", + } + staticData.PredictionContextCache = antlr.NewPredictionContextCache() + staticData.serializedATN = []int32{ + 4, 0, 33, 255, 6, -1, 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, 2, + 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, + 7, 36, 2, 37, 7, 37, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, + 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, + 7, 1, 7, 1, 8, 1, 8, 1, 8, 3, 8, 115, 8, 8, 1, 8, 3, 8, 118, 8, 8, 1, 8, + 1, 8, 1, 9, 1, 9, 1, 9, 3, 9, 125, 8, 9, 1, 9, 3, 9, 128, 8, 9, 1, 10, + 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 138, 8, 10, 1, + 11, 4, 11, 141, 8, 11, 11, 11, 12, 11, 142, 1, 11, 1, 11, 4, 11, 147, 8, + 11, 11, 11, 12, 11, 148, 1, 11, 1, 11, 5, 11, 153, 8, 11, 10, 11, 12, 11, + 156, 9, 11, 1, 12, 4, 12, 159, 8, 12, 11, 12, 12, 12, 160, 1, 12, 1, 12, + 4, 12, 165, 8, 12, 11, 12, 12, 12, 166, 1, 12, 1, 12, 5, 12, 171, 8, 12, + 10, 12, 12, 12, 174, 9, 12, 1, 13, 1, 13, 5, 13, 178, 8, 13, 10, 13, 12, + 13, 181, 9, 13, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, + 1, 16, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, + 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, + 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, + 31, 1, 32, 1, 32, 1, 33, 4, 33, 226, 8, 33, 11, 33, 12, 33, 227, 1, 33, + 1, 33, 1, 34, 1, 34, 1, 35, 4, 35, 235, 8, 35, 11, 35, 12, 35, 236, 1, + 36, 1, 36, 3, 36, 241, 8, 36, 1, 36, 4, 36, 244, 8, 36, 11, 36, 12, 36, + 245, 1, 37, 1, 37, 1, 37, 1, 37, 1, 37, 1, 37, 3, 37, 254, 8, 37, 0, 0, + 38, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, + 11, 23, 0, 25, 0, 27, 12, 29, 13, 31, 14, 33, 15, 35, 16, 37, 17, 39, 18, + 41, 19, 43, 20, 45, 21, 47, 22, 49, 23, 51, 24, 53, 25, 55, 26, 57, 27, + 59, 28, 61, 29, 63, 30, 65, 31, 67, 32, 69, 33, 71, 0, 73, 0, 75, 0, 1, + 0, 22, 2, 0, 70, 70, 102, 102, 2, 0, 82, 82, 114, 114, 2, 0, 79, 79, 111, + 111, 2, 0, 77, 77, 109, 109, 2, 0, 87, 87, 119, 119, 2, 0, 72, 72, 104, + 104, 2, 0, 69, 69, 101, 101, 2, 0, 83, 83, 115, 115, 2, 0, 84, 84, 116, + 116, 2, 0, 65, 65, 97, 97, 2, 0, 66, 66, 98, 98, 2, 0, 89, 89, 121, 121, + 2, 0, 78, 78, 110, 110, 2, 0, 68, 68, 100, 100, 2, 0, 34, 34, 92, 92, 2, + 0, 39, 39, 92, 92, 3, 0, 64, 90, 95, 95, 97, 122, 5, 0, 46, 46, 48, 58, + 64, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 1, 0, 48, 57, 2, + 0, 43, 43, 45, 45, 6, 0, 100, 100, 104, 104, 109, 109, 115, 115, 119, 119, + 121, 121, 271, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, + 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, + 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, + 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, + 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, + 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, + 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, + 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, + 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 1, 77, 1, 0, 0, + 0, 3, 82, 1, 0, 0, 0, 5, 88, 1, 0, 0, 0, 7, 94, 1, 0, 0, 0, 9, 97, 1, 0, + 0, 0, 11, 100, 1, 0, 0, 0, 13, 104, 1, 0, 0, 0, 15, 107, 1, 0, 0, 0, 17, + 111, 1, 0, 0, 0, 19, 121, 1, 0, 0, 0, 21, 137, 1, 0, 0, 0, 23, 154, 1, + 0, 0, 0, 25, 172, 1, 0, 0, 0, 27, 175, 1, 0, 0, 0, 29, 182, 1, 0, 0, 0, + 31, 185, 1, 0, 0, 0, 33, 188, 1, 0, 0, 0, 35, 191, 1, 0, 0, 0, 37, 194, + 1, 0, 0, 0, 39, 196, 1, 0, 0, 0, 41, 198, 1, 0, 0, 0, 43, 200, 1, 0, 0, + 0, 45, 202, 1, 0, 0, 0, 47, 204, 1, 0, 0, 0, 49, 206, 1, 0, 0, 0, 51, 208, + 1, 0, 0, 0, 53, 210, 1, 0, 0, 0, 55, 212, 1, 0, 0, 0, 57, 214, 1, 0, 0, + 0, 59, 216, 1, 0, 0, 0, 61, 218, 1, 0, 0, 0, 63, 220, 1, 0, 0, 0, 65, 222, + 1, 0, 0, 0, 67, 225, 1, 0, 0, 0, 69, 231, 1, 0, 0, 0, 71, 234, 1, 0, 0, + 0, 73, 238, 1, 0, 0, 0, 75, 253, 1, 0, 0, 0, 77, 78, 7, 0, 0, 0, 78, 79, + 7, 1, 0, 0, 79, 80, 7, 2, 0, 0, 80, 81, 7, 3, 0, 0, 81, 2, 1, 0, 0, 0, + 82, 83, 7, 4, 0, 0, 83, 84, 7, 5, 0, 0, 84, 85, 7, 6, 0, 0, 85, 86, 7, + 1, 0, 0, 86, 87, 7, 6, 0, 0, 87, 4, 1, 0, 0, 0, 88, 89, 7, 7, 0, 0, 89, + 90, 7, 8, 0, 0, 90, 91, 7, 9, 0, 0, 91, 92, 7, 8, 0, 0, 92, 93, 7, 7, 0, + 0, 93, 6, 1, 0, 0, 0, 94, 95, 7, 10, 0, 0, 95, 96, 7, 11, 0, 0, 96, 8, + 1, 0, 0, 0, 97, 98, 7, 9, 0, 0, 98, 99, 7, 7, 0, 0, 99, 10, 1, 0, 0, 0, + 100, 101, 7, 9, 0, 0, 101, 102, 7, 12, 0, 0, 102, 103, 7, 13, 0, 0, 103, + 12, 1, 0, 0, 0, 104, 105, 7, 2, 0, 0, 105, 106, 7, 1, 0, 0, 106, 14, 1, + 0, 0, 0, 107, 108, 7, 12, 0, 0, 108, 109, 7, 2, 0, 0, 109, 110, 7, 8, 0, + 0, 110, 16, 1, 0, 0, 0, 111, 114, 3, 71, 35, 0, 112, 113, 5, 46, 0, 0, + 113, 115, 3, 71, 35, 0, 114, 112, 1, 0, 0, 0, 114, 115, 1, 0, 0, 0, 115, + 117, 1, 0, 0, 0, 116, 118, 3, 73, 36, 0, 117, 116, 1, 0, 0, 0, 117, 118, + 1, 0, 0, 0, 118, 119, 1, 0, 0, 0, 119, 120, 3, 75, 37, 0, 120, 18, 1, 0, + 0, 0, 121, 124, 3, 71, 35, 0, 122, 123, 5, 46, 0, 0, 123, 125, 3, 71, 35, + 0, 124, 122, 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 127, 1, 0, 0, 0, 126, + 128, 3, 73, 36, 0, 127, 126, 1, 0, 0, 0, 127, 128, 1, 0, 0, 0, 128, 20, + 1, 0, 0, 0, 129, 130, 5, 34, 0, 0, 130, 131, 3, 23, 11, 0, 131, 132, 5, + 34, 0, 0, 132, 138, 1, 0, 0, 0, 133, 134, 5, 39, 0, 0, 134, 135, 3, 25, + 12, 0, 135, 136, 5, 39, 0, 0, 136, 138, 1, 0, 0, 0, 137, 129, 1, 0, 0, + 0, 137, 133, 1, 0, 0, 0, 138, 22, 1, 0, 0, 0, 139, 141, 5, 92, 0, 0, 140, + 139, 1, 0, 0, 0, 141, 142, 1, 0, 0, 0, 142, 140, 1, 0, 0, 0, 142, 143, + 1, 0, 0, 0, 143, 144, 1, 0, 0, 0, 144, 153, 5, 34, 0, 0, 145, 147, 5, 92, + 0, 0, 146, 145, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, + 148, 149, 1, 0, 0, 0, 149, 150, 1, 0, 0, 0, 150, 153, 8, 14, 0, 0, 151, + 153, 8, 14, 0, 0, 152, 140, 1, 0, 0, 0, 152, 146, 1, 0, 0, 0, 152, 151, + 1, 0, 0, 0, 153, 156, 1, 0, 0, 0, 154, 152, 1, 0, 0, 0, 154, 155, 1, 0, + 0, 0, 155, 24, 1, 0, 0, 0, 156, 154, 1, 0, 0, 0, 157, 159, 5, 92, 0, 0, + 158, 157, 1, 0, 0, 0, 159, 160, 1, 0, 0, 0, 160, 158, 1, 0, 0, 0, 160, + 161, 1, 0, 0, 0, 161, 162, 1, 0, 0, 0, 162, 171, 5, 39, 0, 0, 163, 165, + 5, 92, 0, 0, 164, 163, 1, 0, 0, 0, 165, 166, 1, 0, 0, 0, 166, 164, 1, 0, + 0, 0, 166, 167, 1, 0, 0, 0, 167, 168, 1, 0, 0, 0, 168, 171, 8, 15, 0, 0, + 169, 171, 8, 15, 0, 0, 170, 158, 1, 0, 0, 0, 170, 164, 1, 0, 0, 0, 170, + 169, 1, 0, 0, 0, 171, 174, 1, 0, 0, 0, 172, 170, 1, 0, 0, 0, 172, 173, + 1, 0, 0, 0, 173, 26, 1, 0, 0, 0, 174, 172, 1, 0, 0, 0, 175, 179, 7, 16, + 0, 0, 176, 178, 7, 17, 0, 0, 177, 176, 1, 0, 0, 0, 178, 181, 1, 0, 0, 0, + 179, 177, 1, 0, 0, 0, 179, 180, 1, 0, 0, 0, 180, 28, 1, 0, 0, 0, 181, 179, + 1, 0, 0, 0, 182, 183, 5, 61, 0, 0, 183, 184, 5, 61, 0, 0, 184, 30, 1, 0, + 0, 0, 185, 186, 5, 33, 0, 0, 186, 187, 5, 61, 0, 0, 187, 32, 1, 0, 0, 0, + 188, 189, 5, 60, 0, 0, 189, 190, 5, 61, 0, 0, 190, 34, 1, 0, 0, 0, 191, + 192, 5, 62, 0, 0, 192, 193, 5, 61, 0, 0, 193, 36, 1, 0, 0, 0, 194, 195, + 5, 61, 0, 0, 195, 38, 1, 0, 0, 0, 196, 197, 5, 60, 0, 0, 197, 40, 1, 0, + 0, 0, 198, 199, 5, 62, 0, 0, 199, 42, 1, 0, 0, 0, 200, 201, 5, 33, 0, 0, + 201, 44, 1, 0, 0, 0, 202, 203, 5, 124, 0, 0, 203, 46, 1, 0, 0, 0, 204, + 205, 5, 44, 0, 0, 205, 48, 1, 0, 0, 0, 206, 207, 5, 40, 0, 0, 207, 50, + 1, 0, 0, 0, 208, 209, 5, 41, 0, 0, 209, 52, 1, 0, 0, 0, 210, 211, 5, 91, + 0, 0, 211, 54, 1, 0, 0, 0, 212, 213, 5, 93, 0, 0, 213, 56, 1, 0, 0, 0, + 214, 215, 5, 43, 0, 0, 215, 58, 1, 0, 0, 0, 216, 217, 5, 45, 0, 0, 217, + 60, 1, 0, 0, 0, 218, 219, 5, 42, 0, 0, 219, 62, 1, 0, 0, 0, 220, 221, 5, + 47, 0, 0, 221, 64, 1, 0, 0, 0, 222, 223, 5, 37, 0, 0, 223, 66, 1, 0, 0, + 0, 224, 226, 7, 18, 0, 0, 225, 224, 1, 0, 0, 0, 226, 227, 1, 0, 0, 0, 227, + 225, 1, 0, 0, 0, 227, 228, 1, 0, 0, 0, 228, 229, 1, 0, 0, 0, 229, 230, + 6, 33, 0, 0, 230, 68, 1, 0, 0, 0, 231, 232, 9, 0, 0, 0, 232, 70, 1, 0, + 0, 0, 233, 235, 7, 19, 0, 0, 234, 233, 1, 0, 0, 0, 235, 236, 1, 0, 0, 0, + 236, 234, 1, 0, 0, 0, 236, 237, 1, 0, 0, 0, 237, 72, 1, 0, 0, 0, 238, 240, + 7, 6, 0, 0, 239, 241, 7, 20, 0, 0, 240, 239, 1, 0, 0, 0, 240, 241, 1, 0, + 0, 0, 241, 243, 1, 0, 0, 0, 242, 244, 7, 19, 0, 0, 243, 242, 1, 0, 0, 0, + 244, 245, 1, 0, 0, 0, 245, 243, 1, 0, 0, 0, 245, 246, 1, 0, 0, 0, 246, + 74, 1, 0, 0, 0, 247, 248, 5, 109, 0, 0, 248, 249, 5, 111, 0, 0, 249, 254, + 5, 110, 0, 0, 250, 251, 5, 109, 0, 0, 251, 254, 5, 115, 0, 0, 252, 254, + 7, 21, 0, 0, 253, 247, 1, 0, 0, 0, 253, 250, 1, 0, 0, 0, 253, 252, 1, 0, + 0, 0, 254, 76, 1, 0, 0, 0, 20, 0, 114, 117, 124, 127, 137, 142, 148, 152, + 154, 160, 166, 170, 172, 179, 227, 236, 240, 245, 253, 1, 6, 0, 0, + } + deserializer := antlr.NewATNDeserializer(nil) + staticData.atn = deserializer.Deserialize(staticData.serializedATN) + atn := staticData.atn + staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) + decisionToDFA := staticData.decisionToDFA + for index, state := range atn.DecisionToState { + decisionToDFA[index] = antlr.NewDFA(state, index) + } +} + +// SPL2LexerInit initializes any static state used to implement SPL2Lexer. By default the +// static state used to implement the lexer is lazily initialized during the first call to +// NewSPL2Lexer(). You can call this function if you wish to initialize the static state ahead +// of time. +func SPL2LexerInit() { + staticData := &SPL2LexerLexerStaticData + staticData.once.Do(spl2lexerLexerInit) +} + +// NewSPL2Lexer produces a new lexer instance for the optional input antlr.CharStream. +func NewSPL2Lexer(input antlr.CharStream) *SPL2Lexer { + SPL2LexerInit() + l := new(SPL2Lexer) + l.BaseLexer = antlr.NewBaseLexer(input) + staticData := &SPL2LexerLexerStaticData + l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) + l.channelNames = staticData.ChannelNames + l.modeNames = staticData.ModeNames + l.RuleNames = staticData.RuleNames + l.LiteralNames = staticData.LiteralNames + l.SymbolicNames = staticData.SymbolicNames + l.GrammarFileName = "SPL2.g4" + // TODO: l.EOF = antlr.TokenEOF + + return l +} + +// SPL2Lexer tokens. +const ( + SPL2LexerFROM = 1 + SPL2LexerWHERE = 2 + SPL2LexerSTATS = 3 + SPL2LexerBY = 4 + SPL2LexerAS = 5 + SPL2LexerAND = 6 + SPL2LexerOR = 7 + SPL2LexerNOT = 8 + SPL2LexerDURATION = 9 + SPL2LexerNUMBER = 10 + SPL2LexerSTRING = 11 + SPL2LexerIDENT = 12 + SPL2LexerEQ2 = 13 + SPL2LexerNE = 14 + SPL2LexerLE = 15 + SPL2LexerGE = 16 + SPL2LexerEQ = 17 + SPL2LexerLT = 18 + SPL2LexerGT = 19 + SPL2LexerBANG = 20 + SPL2LexerPIPE = 21 + SPL2LexerCOMMA = 22 + SPL2LexerLPAREN = 23 + SPL2LexerRPAREN = 24 + SPL2LexerLBRACKET = 25 + SPL2LexerRBRACKET = 26 + SPL2LexerPLUS = 27 + SPL2LexerMINUS = 28 + SPL2LexerSTAR = 29 + SPL2LexerSLASH = 30 + SPL2LexerPERCENT = 31 + SPL2LexerWS = 32 + SPL2LexerUNKNOWN = 33 +) diff --git a/pkg/parser/spl2/gen/spl2_parser.go b/pkg/parser/spl2/gen/spl2_parser.go new file mode 100644 index 0000000..78244fb --- /dev/null +++ b/pkg/parser/spl2/gen/spl2_parser.go @@ -0,0 +1,5699 @@ +// Code generated from pkg/parser/spl2/grammar/SPL2.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl2gen // SPL2 +import ( + "fmt" + "strconv" + "sync" + + "github.com/antlr4-go/antlr/v4" +) + +// Suppress unused import errors +var _ = fmt.Printf +var _ = strconv.Itoa +var _ = sync.Once{} + +type SPL2Parser struct { + *antlr.BaseParser +} + +var SPL2ParserStaticData struct { + once sync.Once + serializedATN []int32 + LiteralNames []string + SymbolicNames []string + RuleNames []string + PredictionContextCache *antlr.PredictionContextCache + atn *antlr.ATN + decisionToDFA []*antlr.DFA +} + +func spl2ParserInit() { + staticData := &SPL2ParserStaticData + staticData.LiteralNames = []string{ + "", "", "", "", "", "", "", "", "", "", "", "", "", "'=='", "'!='", + "'<='", "'>='", "'='", "'<'", "'>'", "'!'", "'|'", "','", "'('", "')'", + "'['", "']'", "'+'", "'-'", "'*'", "'/'", "'%'", + } + staticData.SymbolicNames = []string{ + "", "FROM", "WHERE", "STATS", "BY", "AS", "AND", "OR", "NOT", "DURATION", + "NUMBER", "STRING", "IDENT", "EQ2", "NE", "LE", "GE", "EQ", "LT", "GT", + "BANG", "PIPE", "COMMA", "LPAREN", "RPAREN", "LBRACKET", "RBRACKET", + "PLUS", "MINUS", "STAR", "SLASH", "PERCENT", "WS", "UNKNOWN", + } + staticData.RuleNames = []string{ + "stageFrom", "stageWhere", "stageStats", "stageEnd", "indexName", "indexTail", + "expr", "orExpr", "orTail", "andExpr", "andTail", "notExpr", "comparison", + "comparisonTail", "additive", "additiveTail", "multiplicative", "multiplicativeTail", + "unary", "primary", "subsearch", "absentOperand", "aggList", "agg", + "aliasClause", "byClause", "fieldList", "field", "compOp", "addOp", + "mulOp", "sign", "identLike", + } + staticData.PredictionContextCache = antlr.NewPredictionContextCache() + staticData.serializedATN = []int32{ + 4, 1, 33, 265, 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, 2, 31, 7, + 31, 2, 32, 7, 32, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 2, 1, 2, 3, 2, 78, 8, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 5, 4, 86, + 8, 4, 10, 4, 12, 4, 89, 9, 4, 1, 4, 1, 4, 3, 4, 93, 8, 4, 1, 5, 1, 5, 1, + 5, 1, 5, 1, 5, 3, 5, 100, 8, 5, 1, 6, 1, 6, 1, 7, 1, 7, 5, 7, 106, 8, 7, + 10, 7, 12, 7, 109, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 115, 8, 8, 1, 9, + 1, 9, 5, 9, 119, 8, 9, 10, 9, 12, 9, 122, 9, 9, 1, 10, 1, 10, 1, 10, 1, + 10, 3, 10, 128, 8, 10, 1, 11, 1, 11, 1, 11, 3, 11, 133, 8, 11, 1, 11, 3, + 11, 136, 8, 11, 1, 12, 1, 12, 5, 12, 140, 8, 12, 10, 12, 12, 12, 143, 9, + 12, 1, 13, 1, 13, 1, 13, 1, 13, 3, 13, 149, 8, 13, 1, 14, 1, 14, 5, 14, + 153, 8, 14, 10, 14, 12, 14, 156, 9, 14, 1, 15, 1, 15, 1, 15, 1, 15, 3, + 15, 162, 8, 15, 1, 16, 1, 16, 5, 16, 166, 8, 16, 10, 16, 12, 16, 169, 9, + 16, 1, 17, 1, 17, 1, 17, 1, 17, 3, 17, 175, 8, 17, 1, 18, 1, 18, 1, 18, + 3, 18, 180, 8, 18, 1, 18, 3, 18, 183, 8, 18, 1, 19, 1, 19, 1, 19, 1, 19, + 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 5, 19, 195, 8, 19, 10, 19, 12, + 19, 198, 9, 19, 3, 19, 200, 8, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 1, + 19, 1, 19, 3, 19, 209, 8, 19, 1, 20, 1, 20, 1, 20, 5, 20, 214, 8, 20, 10, + 20, 12, 20, 217, 9, 20, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 5, 22, + 225, 8, 22, 10, 22, 12, 22, 228, 9, 22, 1, 23, 1, 23, 1, 23, 3, 23, 233, + 8, 23, 1, 23, 1, 23, 3, 23, 237, 8, 23, 1, 24, 1, 24, 1, 24, 1, 25, 1, + 25, 1, 25, 1, 26, 1, 26, 1, 26, 5, 26, 248, 8, 26, 10, 26, 12, 26, 251, + 9, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, + 31, 1, 32, 1, 32, 1, 32, 0, 0, 33, 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, 62, 64, 0, 7, 1, 1, 21, 21, 2, 0, 8, 8, 20, 20, 4, 1, 13, 19, 21, + 22, 24, 24, 26, 26, 1, 0, 13, 19, 1, 0, 27, 28, 1, 0, 29, 31, 2, 0, 1, + 8, 12, 12, 263, 0, 66, 1, 0, 0, 0, 2, 70, 1, 0, 0, 0, 4, 74, 1, 0, 0, 0, + 6, 81, 1, 0, 0, 0, 8, 83, 1, 0, 0, 0, 10, 94, 1, 0, 0, 0, 12, 101, 1, 0, + 0, 0, 14, 103, 1, 0, 0, 0, 16, 110, 1, 0, 0, 0, 18, 116, 1, 0, 0, 0, 20, + 123, 1, 0, 0, 0, 22, 135, 1, 0, 0, 0, 24, 137, 1, 0, 0, 0, 26, 144, 1, + 0, 0, 0, 28, 150, 1, 0, 0, 0, 30, 157, 1, 0, 0, 0, 32, 163, 1, 0, 0, 0, + 34, 170, 1, 0, 0, 0, 36, 182, 1, 0, 0, 0, 38, 208, 1, 0, 0, 0, 40, 210, + 1, 0, 0, 0, 42, 218, 1, 0, 0, 0, 44, 221, 1, 0, 0, 0, 46, 229, 1, 0, 0, + 0, 48, 238, 1, 0, 0, 0, 50, 241, 1, 0, 0, 0, 52, 244, 1, 0, 0, 0, 54, 252, + 1, 0, 0, 0, 56, 254, 1, 0, 0, 0, 58, 256, 1, 0, 0, 0, 60, 258, 1, 0, 0, + 0, 62, 260, 1, 0, 0, 0, 64, 262, 1, 0, 0, 0, 66, 67, 5, 1, 0, 0, 67, 68, + 3, 8, 4, 0, 68, 69, 3, 6, 3, 0, 69, 1, 1, 0, 0, 0, 70, 71, 5, 2, 0, 0, + 71, 72, 3, 12, 6, 0, 72, 73, 3, 6, 3, 0, 73, 3, 1, 0, 0, 0, 74, 75, 5, + 3, 0, 0, 75, 77, 3, 44, 22, 0, 76, 78, 3, 50, 25, 0, 77, 76, 1, 0, 0, 0, + 77, 78, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 80, 3, 6, 3, 0, 80, 5, 1, 0, + 0, 0, 81, 82, 7, 0, 0, 0, 82, 7, 1, 0, 0, 0, 83, 87, 3, 64, 32, 0, 84, + 86, 3, 10, 5, 0, 85, 84, 1, 0, 0, 0, 86, 89, 1, 0, 0, 0, 87, 85, 1, 0, + 0, 0, 87, 88, 1, 0, 0, 0, 88, 92, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 90, 91, + 4, 4, 0, 0, 91, 93, 5, 29, 0, 0, 92, 90, 1, 0, 0, 0, 92, 93, 1, 0, 0, 0, + 93, 9, 1, 0, 0, 0, 94, 95, 4, 5, 1, 0, 95, 99, 5, 28, 0, 0, 96, 100, 3, + 64, 32, 0, 97, 100, 5, 10, 0, 0, 98, 100, 5, 29, 0, 0, 99, 96, 1, 0, 0, + 0, 99, 97, 1, 0, 0, 0, 99, 98, 1, 0, 0, 0, 100, 11, 1, 0, 0, 0, 101, 102, + 3, 14, 7, 0, 102, 13, 1, 0, 0, 0, 103, 107, 3, 18, 9, 0, 104, 106, 3, 16, + 8, 0, 105, 104, 1, 0, 0, 0, 106, 109, 1, 0, 0, 0, 107, 105, 1, 0, 0, 0, + 107, 108, 1, 0, 0, 0, 108, 15, 1, 0, 0, 0, 109, 107, 1, 0, 0, 0, 110, 111, + 4, 8, 2, 0, 111, 114, 5, 7, 0, 0, 112, 115, 3, 18, 9, 0, 113, 115, 3, 42, + 21, 0, 114, 112, 1, 0, 0, 0, 114, 113, 1, 0, 0, 0, 115, 17, 1, 0, 0, 0, + 116, 120, 3, 22, 11, 0, 117, 119, 3, 20, 10, 0, 118, 117, 1, 0, 0, 0, 119, + 122, 1, 0, 0, 0, 120, 118, 1, 0, 0, 0, 120, 121, 1, 0, 0, 0, 121, 19, 1, + 0, 0, 0, 122, 120, 1, 0, 0, 0, 123, 124, 4, 10, 3, 0, 124, 127, 5, 6, 0, + 0, 125, 128, 3, 22, 11, 0, 126, 128, 3, 42, 21, 0, 127, 125, 1, 0, 0, 0, + 127, 126, 1, 0, 0, 0, 128, 21, 1, 0, 0, 0, 129, 132, 7, 1, 0, 0, 130, 133, + 3, 22, 11, 0, 131, 133, 3, 42, 21, 0, 132, 130, 1, 0, 0, 0, 132, 131, 1, + 0, 0, 0, 133, 136, 1, 0, 0, 0, 134, 136, 3, 24, 12, 0, 135, 129, 1, 0, + 0, 0, 135, 134, 1, 0, 0, 0, 136, 23, 1, 0, 0, 0, 137, 141, 3, 28, 14, 0, + 138, 140, 3, 26, 13, 0, 139, 138, 1, 0, 0, 0, 140, 143, 1, 0, 0, 0, 141, + 139, 1, 0, 0, 0, 141, 142, 1, 0, 0, 0, 142, 25, 1, 0, 0, 0, 143, 141, 1, + 0, 0, 0, 144, 145, 4, 13, 4, 0, 145, 148, 3, 56, 28, 0, 146, 149, 3, 28, + 14, 0, 147, 149, 3, 42, 21, 0, 148, 146, 1, 0, 0, 0, 148, 147, 1, 0, 0, + 0, 149, 27, 1, 0, 0, 0, 150, 154, 3, 32, 16, 0, 151, 153, 3, 30, 15, 0, + 152, 151, 1, 0, 0, 0, 153, 156, 1, 0, 0, 0, 154, 152, 1, 0, 0, 0, 154, + 155, 1, 0, 0, 0, 155, 29, 1, 0, 0, 0, 156, 154, 1, 0, 0, 0, 157, 158, 4, + 15, 5, 0, 158, 161, 3, 58, 29, 0, 159, 162, 3, 32, 16, 0, 160, 162, 3, + 42, 21, 0, 161, 159, 1, 0, 0, 0, 161, 160, 1, 0, 0, 0, 162, 31, 1, 0, 0, + 0, 163, 167, 3, 36, 18, 0, 164, 166, 3, 34, 17, 0, 165, 164, 1, 0, 0, 0, + 166, 169, 1, 0, 0, 0, 167, 165, 1, 0, 0, 0, 167, 168, 1, 0, 0, 0, 168, + 33, 1, 0, 0, 0, 169, 167, 1, 0, 0, 0, 170, 171, 4, 17, 6, 0, 171, 174, + 3, 60, 30, 0, 172, 175, 3, 36, 18, 0, 173, 175, 3, 42, 21, 0, 174, 172, + 1, 0, 0, 0, 174, 173, 1, 0, 0, 0, 175, 35, 1, 0, 0, 0, 176, 179, 3, 62, + 31, 0, 177, 180, 3, 36, 18, 0, 178, 180, 3, 42, 21, 0, 179, 177, 1, 0, + 0, 0, 179, 178, 1, 0, 0, 0, 180, 183, 1, 0, 0, 0, 181, 183, 3, 38, 19, + 0, 182, 176, 1, 0, 0, 0, 182, 181, 1, 0, 0, 0, 183, 37, 1, 0, 0, 0, 184, + 185, 5, 23, 0, 0, 185, 186, 3, 12, 6, 0, 186, 187, 5, 24, 0, 0, 187, 209, + 1, 0, 0, 0, 188, 189, 4, 19, 7, 0, 189, 190, 3, 64, 32, 0, 190, 199, 5, + 23, 0, 0, 191, 196, 3, 12, 6, 0, 192, 193, 5, 22, 0, 0, 193, 195, 3, 12, + 6, 0, 194, 192, 1, 0, 0, 0, 195, 198, 1, 0, 0, 0, 196, 194, 1, 0, 0, 0, + 196, 197, 1, 0, 0, 0, 197, 200, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 199, + 191, 1, 0, 0, 0, 199, 200, 1, 0, 0, 0, 200, 201, 1, 0, 0, 0, 201, 202, + 5, 24, 0, 0, 202, 209, 1, 0, 0, 0, 203, 209, 3, 64, 32, 0, 204, 209, 5, + 11, 0, 0, 205, 209, 5, 10, 0, 0, 206, 209, 5, 9, 0, 0, 207, 209, 3, 40, + 20, 0, 208, 184, 1, 0, 0, 0, 208, 188, 1, 0, 0, 0, 208, 203, 1, 0, 0, 0, + 208, 204, 1, 0, 0, 0, 208, 205, 1, 0, 0, 0, 208, 206, 1, 0, 0, 0, 208, + 207, 1, 0, 0, 0, 209, 39, 1, 0, 0, 0, 210, 211, 5, 25, 0, 0, 211, 215, + 6, 20, -1, 0, 212, 214, 8, 0, 0, 0, 213, 212, 1, 0, 0, 0, 214, 217, 1, + 0, 0, 0, 215, 213, 1, 0, 0, 0, 215, 216, 1, 0, 0, 0, 216, 41, 1, 0, 0, + 0, 217, 215, 1, 0, 0, 0, 218, 219, 6, 21, -1, 0, 219, 220, 7, 2, 0, 0, + 220, 43, 1, 0, 0, 0, 221, 226, 3, 46, 23, 0, 222, 223, 5, 22, 0, 0, 223, + 225, 3, 46, 23, 0, 224, 222, 1, 0, 0, 0, 225, 228, 1, 0, 0, 0, 226, 224, + 1, 0, 0, 0, 226, 227, 1, 0, 0, 0, 227, 45, 1, 0, 0, 0, 228, 226, 1, 0, + 0, 0, 229, 230, 3, 64, 32, 0, 230, 232, 5, 23, 0, 0, 231, 233, 3, 12, 6, + 0, 232, 231, 1, 0, 0, 0, 232, 233, 1, 0, 0, 0, 233, 234, 1, 0, 0, 0, 234, + 236, 5, 24, 0, 0, 235, 237, 3, 48, 24, 0, 236, 235, 1, 0, 0, 0, 236, 237, + 1, 0, 0, 0, 237, 47, 1, 0, 0, 0, 238, 239, 5, 5, 0, 0, 239, 240, 3, 64, + 32, 0, 240, 49, 1, 0, 0, 0, 241, 242, 5, 4, 0, 0, 242, 243, 3, 52, 26, + 0, 243, 51, 1, 0, 0, 0, 244, 249, 3, 54, 27, 0, 245, 246, 5, 22, 0, 0, + 246, 248, 3, 54, 27, 0, 247, 245, 1, 0, 0, 0, 248, 251, 1, 0, 0, 0, 249, + 247, 1, 0, 0, 0, 249, 250, 1, 0, 0, 0, 250, 53, 1, 0, 0, 0, 251, 249, 1, + 0, 0, 0, 252, 253, 3, 64, 32, 0, 253, 55, 1, 0, 0, 0, 254, 255, 7, 3, 0, + 0, 255, 57, 1, 0, 0, 0, 256, 257, 7, 4, 0, 0, 257, 59, 1, 0, 0, 0, 258, + 259, 7, 5, 0, 0, 259, 61, 1, 0, 0, 0, 260, 261, 7, 4, 0, 0, 261, 63, 1, + 0, 0, 0, 262, 263, 7, 6, 0, 0, 263, 65, 1, 0, 0, 0, 26, 77, 87, 92, 99, + 107, 114, 120, 127, 132, 135, 141, 148, 154, 161, 167, 174, 179, 182, 196, + 199, 208, 215, 226, 232, 236, 249, + } + deserializer := antlr.NewATNDeserializer(nil) + staticData.atn = deserializer.Deserialize(staticData.serializedATN) + atn := staticData.atn + staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) + decisionToDFA := staticData.decisionToDFA + for index, state := range atn.DecisionToState { + decisionToDFA[index] = antlr.NewDFA(state, index) + } +} + +// SPL2ParserInit initializes any static state used to implement SPL2Parser. By default the +// static state used to implement the parser is lazily initialized during the first call to +// NewSPL2Parser(). You can call this function if you wish to initialize the static state ahead +// of time. +func SPL2ParserInit() { + staticData := &SPL2ParserStaticData + staticData.once.Do(spl2ParserInit) +} + +// NewSPL2Parser produces a new parser instance for the optional input antlr.TokenStream. +func NewSPL2Parser(input antlr.TokenStream) *SPL2Parser { + SPL2ParserInit() + this := new(SPL2Parser) + this.BaseParser = antlr.NewBaseParser(input) + staticData := &SPL2ParserStaticData + this.Interpreter = antlr.NewParserATNSimulator(this, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) + this.RuleNames = staticData.RuleNames + this.LiteralNames = staticData.LiteralNames + this.SymbolicNames = staticData.SymbolicNames + this.GrammarFileName = "SPL2.g4" + + return this +} + +// Note that '@members' cannot be changed now, but this should have been 'globals' +// If you are looking to have variables for each instance, use '@structmembers' + +// la returns the token type at lookahead k. +func (p *SPL2Parser) la(k int) int { return p.GetTokenStream().LA(k) } + +// tok returns the token at lookahead k; k may be negative. +func (p *SPL2Parser) tok(k int) antlr.Token { return p.GetTokenStream().LT(k) } + +// at reports whether the current token has type t. +func (p *SPL2Parser) at(t int) bool { return p.la(1) == t } + +// isIdentLike reports whether token type t is accepted by identLike. +func (p *SPL2Parser) isIdentLike(t int) bool { + switch t { + case SPL2ParserIDENT, SPL2ParserFROM, SPL2ParserWHERE, SPL2ParserSTATS, + SPL2ParserBY, SPL2ParserAS, SPL2ParserAND, SPL2ParserOR, SPL2ParserNOT: + return true + } + return false +} + +// touches reports whether the tokens at k and k+1 are adjacent in the source. +// Token offsets are rune indexes, so this is exact. +func (p *SPL2Parser) touches(k int) bool { + a, b := p.tok(k), p.tok(k+1) + if a == nil || b == nil { + return false + } + return a.GetStop()+1 == b.GetStart() +} + +// touchingPrev reports whether the current token starts exactly where the +// last consumed token ended. +func (p *SPL2Parser) touchingPrev() bool { + prev, cur := p.tok(-1), p.tok(1) + if prev == nil || cur == nil { + return false + } + return prev.GetStop()+1 == cur.GetStart() +} + +// hyphenRun reports whether a '-' continues a dataset name: it must touch the +// previous component and be followed, without a space, by a word, number, or +// wildcard. Whitespace therefore ends the name, and `from logs- *` is a +// syntax error at the '-'. +func (p *SPL2Parser) hyphenRun() bool { + return p.touchingPrev() && p.touches(1) && + (p.isIdentLike(p.la(2)) || p.la(2) == SPL2ParserNUMBER || p.la(2) == SPL2ParserSTAR) +} + +// callAhead reports whether an identifier is followed by '('. Adjacency is +// not required: `where lower (msg)="x"` is a call. +func (p *SPL2Parser) callAhead() bool { return p.la(2) == SPL2ParserLPAREN } + +// atNot, atCompare, atAdd, and atMul report whether the current token is an +// operator of that kind. The binary and unary rules gate on them so the parser +// commits to the operator and blames the missing operand after it. +func (p *SPL2Parser) atNot() bool { return p.at(SPL2ParserNOT) || p.at(SPL2ParserBANG) } + +func (p *SPL2Parser) atCompare() bool { + switch p.la(1) { + case SPL2ParserEQ2, SPL2ParserEQ, SPL2ParserNE, SPL2ParserLT, SPL2ParserLE, + SPL2ParserGT, SPL2ParserGE: + return true + } + return false +} + +func (p *SPL2Parser) atAdd() bool { return p.at(SPL2ParserPLUS) || p.at(SPL2ParserMINUS) } + +func (p *SPL2Parser) atMul() bool { + return p.at(SPL2ParserSTAR) || p.at(SPL2ParserSLASH) || p.at(SPL2ParserPERCENT) +} + +// parseAbort is the panic value for a grammar action that ends the parse at a +// token. The front-end recovers it structurally and maps the token through its +// SourceMap; generated code cannot import the front-end, so the methods below +// are the whole contract. +type parseAbort struct { + token antlr.Token + code string + message string +} + +func (a parseAbort) AbortToken() antlr.Token { return a.token } +func (a parseAbort) AbortCode() string { return a.code } +func (a parseAbort) AbortMessage() string { return a.message } + +// abortMissingOperand ends the parse at the token where an operand was +// required. +func (p *SPL2Parser) abortMissingOperand() { + t := p.tok(1) + message := "expected an expression, found end of query" + if t != nil && t.GetTokenType() != antlr.TokenEOF { + message = "expected an expression, found " + fmt.Sprintf("%q", t.GetText()) + } + panic(parseAbort{token: t, code: "syntax", message: message}) +} + +// abortSubsearch refuses a subsearch at its opening bracket, before the rest of +// the stage is parsed. +func (p *SPL2Parser) abortSubsearch() { + panic(parseAbort{ + token: p.tok(-1), + code: "unsupported-subsearch", + message: "subsearches are not supported", + }) +} + +// SPL2Parser tokens. +const ( + SPL2ParserEOF = antlr.TokenEOF + SPL2ParserFROM = 1 + SPL2ParserWHERE = 2 + SPL2ParserSTATS = 3 + SPL2ParserBY = 4 + SPL2ParserAS = 5 + SPL2ParserAND = 6 + SPL2ParserOR = 7 + SPL2ParserNOT = 8 + SPL2ParserDURATION = 9 + SPL2ParserNUMBER = 10 + SPL2ParserSTRING = 11 + SPL2ParserIDENT = 12 + SPL2ParserEQ2 = 13 + SPL2ParserNE = 14 + SPL2ParserLE = 15 + SPL2ParserGE = 16 + SPL2ParserEQ = 17 + SPL2ParserLT = 18 + SPL2ParserGT = 19 + SPL2ParserBANG = 20 + SPL2ParserPIPE = 21 + SPL2ParserCOMMA = 22 + SPL2ParserLPAREN = 23 + SPL2ParserRPAREN = 24 + SPL2ParserLBRACKET = 25 + SPL2ParserRBRACKET = 26 + SPL2ParserPLUS = 27 + SPL2ParserMINUS = 28 + SPL2ParserSTAR = 29 + SPL2ParserSLASH = 30 + SPL2ParserPERCENT = 31 + SPL2ParserWS = 32 + SPL2ParserUNKNOWN = 33 +) + +// SPL2Parser rules. +const ( + SPL2ParserRULE_stageFrom = 0 + SPL2ParserRULE_stageWhere = 1 + SPL2ParserRULE_stageStats = 2 + SPL2ParserRULE_stageEnd = 3 + SPL2ParserRULE_indexName = 4 + SPL2ParserRULE_indexTail = 5 + SPL2ParserRULE_expr = 6 + SPL2ParserRULE_orExpr = 7 + SPL2ParserRULE_orTail = 8 + SPL2ParserRULE_andExpr = 9 + SPL2ParserRULE_andTail = 10 + SPL2ParserRULE_notExpr = 11 + SPL2ParserRULE_comparison = 12 + SPL2ParserRULE_comparisonTail = 13 + SPL2ParserRULE_additive = 14 + SPL2ParserRULE_additiveTail = 15 + SPL2ParserRULE_multiplicative = 16 + SPL2ParserRULE_multiplicativeTail = 17 + SPL2ParserRULE_unary = 18 + SPL2ParserRULE_primary = 19 + SPL2ParserRULE_subsearch = 20 + SPL2ParserRULE_absentOperand = 21 + SPL2ParserRULE_aggList = 22 + SPL2ParserRULE_agg = 23 + SPL2ParserRULE_aliasClause = 24 + SPL2ParserRULE_byClause = 25 + SPL2ParserRULE_fieldList = 26 + SPL2ParserRULE_field = 27 + SPL2ParserRULE_compOp = 28 + SPL2ParserRULE_addOp = 29 + SPL2ParserRULE_mulOp = 30 + SPL2ParserRULE_sign = 31 + SPL2ParserRULE_identLike = 32 +) + +// IStageFromContext is an interface to support dynamic dispatch. +type IStageFromContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + FROM() antlr.TerminalNode + IndexName() IIndexNameContext + StageEnd() IStageEndContext + + // IsStageFromContext differentiates from other interfaces. + IsStageFromContext() +} + +type StageFromContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageFromContext() *StageFromContext { + var p = new(StageFromContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageFrom + return p +} + +func InitEmptyStageFromContext(p *StageFromContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageFrom +} + +func (*StageFromContext) IsStageFromContext() {} + +func NewStageFromContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageFromContext { + var p = new(StageFromContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_stageFrom + + return p +} + +func (s *StageFromContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageFromContext) FROM() antlr.TerminalNode { + return s.GetToken(SPL2ParserFROM, 0) +} + +func (s *StageFromContext) IndexName() IIndexNameContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIndexNameContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIndexNameContext) +} + +func (s *StageFromContext) StageEnd() IStageEndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStageEndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStageEndContext) +} + +func (s *StageFromContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageFromContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageFromContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitStageFrom(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) StageFrom() (localctx IStageFromContext) { + localctx = NewStageFromContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 0, SPL2ParserRULE_stageFrom) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(66) + p.Match(SPL2ParserFROM) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(67) + p.IndexName() + } + { + p.SetState(68) + p.StageEnd() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IStageWhereContext is an interface to support dynamic dispatch. +type IStageWhereContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + WHERE() antlr.TerminalNode + Expr() IExprContext + StageEnd() IStageEndContext + + // IsStageWhereContext differentiates from other interfaces. + IsStageWhereContext() +} + +type StageWhereContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageWhereContext() *StageWhereContext { + var p = new(StageWhereContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageWhere + return p +} + +func InitEmptyStageWhereContext(p *StageWhereContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageWhere +} + +func (*StageWhereContext) IsStageWhereContext() {} + +func NewStageWhereContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageWhereContext { + var p = new(StageWhereContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_stageWhere + + return p +} + +func (s *StageWhereContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageWhereContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL2ParserWHERE, 0) +} + +func (s *StageWhereContext) Expr() IExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IExprContext) +} + +func (s *StageWhereContext) StageEnd() IStageEndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStageEndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStageEndContext) +} + +func (s *StageWhereContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageWhereContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageWhereContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitStageWhere(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) StageWhere() (localctx IStageWhereContext) { + localctx = NewStageWhereContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 2, SPL2ParserRULE_stageWhere) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(70) + p.Match(SPL2ParserWHERE) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(71) + p.Expr() + } + { + p.SetState(72) + p.StageEnd() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IStageStatsContext is an interface to support dynamic dispatch. +type IStageStatsContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + STATS() antlr.TerminalNode + AggList() IAggListContext + StageEnd() IStageEndContext + ByClause() IByClauseContext + + // IsStageStatsContext differentiates from other interfaces. + IsStageStatsContext() +} + +type StageStatsContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageStatsContext() *StageStatsContext { + var p = new(StageStatsContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageStats + return p +} + +func InitEmptyStageStatsContext(p *StageStatsContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageStats +} + +func (*StageStatsContext) IsStageStatsContext() {} + +func NewStageStatsContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageStatsContext { + var p = new(StageStatsContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_stageStats + + return p +} + +func (s *StageStatsContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageStatsContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL2ParserSTATS, 0) +} + +func (s *StageStatsContext) AggList() IAggListContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggListContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAggListContext) +} + +func (s *StageStatsContext) StageEnd() IStageEndContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IStageEndContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IStageEndContext) +} + +func (s *StageStatsContext) ByClause() IByClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IByClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IByClauseContext) +} + +func (s *StageStatsContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageStatsContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageStatsContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitStageStats(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) StageStats() (localctx IStageStatsContext) { + localctx = NewStageStatsContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 4, SPL2ParserRULE_stageStats) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(74) + p.Match(SPL2ParserSTATS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(75) + p.AggList() + } + p.SetState(77) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL2ParserBY { + { + p.SetState(76) + p.ByClause() + } + + } + { + p.SetState(79) + p.StageEnd() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IStageEndContext is an interface to support dynamic dispatch. +type IStageEndContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + PIPE() antlr.TerminalNode + EOF() antlr.TerminalNode + + // IsStageEndContext differentiates from other interfaces. + IsStageEndContext() +} + +type StageEndContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyStageEndContext() *StageEndContext { + var p = new(StageEndContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageEnd + return p +} + +func InitEmptyStageEndContext(p *StageEndContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_stageEnd +} + +func (*StageEndContext) IsStageEndContext() {} + +func NewStageEndContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StageEndContext { + var p = new(StageEndContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_stageEnd + + return p +} + +func (s *StageEndContext) GetParser() antlr.Parser { return s.parser } + +func (s *StageEndContext) PIPE() antlr.TerminalNode { + return s.GetToken(SPL2ParserPIPE, 0) +} + +func (s *StageEndContext) EOF() antlr.TerminalNode { + return s.GetToken(SPL2ParserEOF, 0) +} + +func (s *StageEndContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *StageEndContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *StageEndContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitStageEnd(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) StageEnd() (localctx IStageEndContext) { + localctx = NewStageEndContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 6, SPL2ParserRULE_stageEnd) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(81) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL2ParserEOF || _la == SPL2ParserPIPE) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IIndexNameContext is an interface to support dynamic dispatch. +type IIndexNameContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + AllIndexTail() []IIndexTailContext + IndexTail(i int) IIndexTailContext + STAR() antlr.TerminalNode + + // IsIndexNameContext differentiates from other interfaces. + IsIndexNameContext() +} + +type IndexNameContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyIndexNameContext() *IndexNameContext { + var p = new(IndexNameContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_indexName + return p +} + +func InitEmptyIndexNameContext(p *IndexNameContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_indexName +} + +func (*IndexNameContext) IsIndexNameContext() {} + +func NewIndexNameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IndexNameContext { + var p = new(IndexNameContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_indexName + + return p +} + +func (s *IndexNameContext) GetParser() antlr.Parser { return s.parser } + +func (s *IndexNameContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *IndexNameContext) AllIndexTail() []IIndexTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IIndexTailContext); ok { + len++ + } + } + + tst := make([]IIndexTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IIndexTailContext); ok { + tst[i] = t.(IIndexTailContext) + i++ + } + } + + return tst +} + +func (s *IndexNameContext) IndexTail(i int) IIndexTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIndexTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IIndexTailContext) +} + +func (s *IndexNameContext) STAR() antlr.TerminalNode { + return s.GetToken(SPL2ParserSTAR, 0) +} + +func (s *IndexNameContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *IndexNameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *IndexNameContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitIndexName(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) IndexName() (localctx IIndexNameContext) { + localctx = NewIndexNameContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 8, SPL2ParserRULE_indexName) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(83) + p.IdentLike() + } + p.SetState(87) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 1, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(84) + p.IndexTail() + } + + } + p.SetState(89) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 1, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + p.SetState(92) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 2, p.GetParserRuleContext()) == 1 { + p.SetState(90) + + if !(p.touchingPrev()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.touchingPrev()", "")) + goto errorExit + } + { + p.SetState(91) + p.Match(SPL2ParserSTAR) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + } else if p.HasError() { // JIM + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IIndexTailContext is an interface to support dynamic dispatch. +type IIndexTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + MINUS() antlr.TerminalNode + IdentLike() IIdentLikeContext + NUMBER() antlr.TerminalNode + STAR() antlr.TerminalNode + + // IsIndexTailContext differentiates from other interfaces. + IsIndexTailContext() +} + +type IndexTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyIndexTailContext() *IndexTailContext { + var p = new(IndexTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_indexTail + return p +} + +func InitEmptyIndexTailContext(p *IndexTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_indexTail +} + +func (*IndexTailContext) IsIndexTailContext() {} + +func NewIndexTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IndexTailContext { + var p = new(IndexTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_indexTail + + return p +} + +func (s *IndexTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *IndexTailContext) MINUS() antlr.TerminalNode { + return s.GetToken(SPL2ParserMINUS, 0) +} + +func (s *IndexTailContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *IndexTailContext) NUMBER() antlr.TerminalNode { + return s.GetToken(SPL2ParserNUMBER, 0) +} + +func (s *IndexTailContext) STAR() antlr.TerminalNode { + return s.GetToken(SPL2ParserSTAR, 0) +} + +func (s *IndexTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *IndexTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *IndexTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitIndexTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) IndexTail() (localctx IIndexTailContext) { + localctx = NewIndexTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 10, SPL2ParserRULE_indexTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(94) + + if !(p.hyphenRun()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.hyphenRun()", "")) + goto errorExit + } + { + p.SetState(95) + p.Match(SPL2ParserMINUS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(99) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetTokenStream().LA(1) { + case SPL2ParserFROM, SPL2ParserWHERE, SPL2ParserSTATS, SPL2ParserBY, SPL2ParserAS, SPL2ParserAND, SPL2ParserOR, SPL2ParserNOT, SPL2ParserIDENT: + { + p.SetState(96) + p.IdentLike() + } + + case SPL2ParserNUMBER: + { + p.SetState(97) + p.Match(SPL2ParserNUMBER) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case SPL2ParserSTAR: + { + p.SetState(98) + p.Match(SPL2ParserSTAR) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + default: + p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IExprContext is an interface to support dynamic dispatch. +type IExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + OrExpr() IOrExprContext + + // IsExprContext differentiates from other interfaces. + IsExprContext() +} + +type ExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyExprContext() *ExprContext { + var p = new(ExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_expr + return p +} + +func InitEmptyExprContext(p *ExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_expr +} + +func (*ExprContext) IsExprContext() {} + +func NewExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ExprContext { + var p = new(ExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_expr + + return p +} + +func (s *ExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *ExprContext) OrExpr() IOrExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IOrExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IOrExprContext) +} + +func (s *ExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Expr() (localctx IExprContext) { + localctx = NewExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 12, SPL2ParserRULE_expr) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(101) + p.OrExpr() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IOrExprContext is an interface to support dynamic dispatch. +type IOrExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AndExpr() IAndExprContext + AllOrTail() []IOrTailContext + OrTail(i int) IOrTailContext + + // IsOrExprContext differentiates from other interfaces. + IsOrExprContext() +} + +type OrExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyOrExprContext() *OrExprContext { + var p = new(OrExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_orExpr + return p +} + +func InitEmptyOrExprContext(p *OrExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_orExpr +} + +func (*OrExprContext) IsOrExprContext() {} + +func NewOrExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *OrExprContext { + var p = new(OrExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_orExpr + + return p +} + +func (s *OrExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *OrExprContext) AndExpr() IAndExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAndExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAndExprContext) +} + +func (s *OrExprContext) AllOrTail() []IOrTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IOrTailContext); ok { + len++ + } + } + + tst := make([]IOrTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IOrTailContext); ok { + tst[i] = t.(IOrTailContext) + i++ + } + } + + return tst +} + +func (s *OrExprContext) OrTail(i int) IOrTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IOrTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IOrTailContext) +} + +func (s *OrExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *OrExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *OrExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitOrExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) OrExpr() (localctx IOrExprContext) { + localctx = NewOrExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 14, SPL2ParserRULE_orExpr) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(103) + p.AndExpr() + } + p.SetState(107) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(104) + p.OrTail() + } + + } + p.SetState(109) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IOrTailContext is an interface to support dynamic dispatch. +type IOrTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + OR() antlr.TerminalNode + AndExpr() IAndExprContext + AbsentOperand() IAbsentOperandContext + + // IsOrTailContext differentiates from other interfaces. + IsOrTailContext() +} + +type OrTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyOrTailContext() *OrTailContext { + var p = new(OrTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_orTail + return p +} + +func InitEmptyOrTailContext(p *OrTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_orTail +} + +func (*OrTailContext) IsOrTailContext() {} + +func NewOrTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *OrTailContext { + var p = new(OrTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_orTail + + return p +} + +func (s *OrTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *OrTailContext) OR() antlr.TerminalNode { + return s.GetToken(SPL2ParserOR, 0) +} + +func (s *OrTailContext) AndExpr() IAndExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAndExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAndExprContext) +} + +func (s *OrTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *OrTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *OrTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *OrTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitOrTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) OrTail() (localctx IOrTailContext) { + localctx = NewOrTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 16, SPL2ParserRULE_orTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(110) + + if !(p.at(SPL2ParserOR)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL2ParserOR)", "")) + goto errorExit + } + { + p.SetState(111) + p.Match(SPL2ParserOR) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(114) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 5, p.GetParserRuleContext()) { + case 1: + { + p.SetState(112) + p.AndExpr() + } + + case 2: + { + p.SetState(113) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAndExprContext is an interface to support dynamic dispatch. +type IAndExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + NotExpr() INotExprContext + AllAndTail() []IAndTailContext + AndTail(i int) IAndTailContext + + // IsAndExprContext differentiates from other interfaces. + IsAndExprContext() +} + +type AndExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAndExprContext() *AndExprContext { + var p = new(AndExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_andExpr + return p +} + +func InitEmptyAndExprContext(p *AndExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_andExpr +} + +func (*AndExprContext) IsAndExprContext() {} + +func NewAndExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AndExprContext { + var p = new(AndExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_andExpr + + return p +} + +func (s *AndExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *AndExprContext) NotExpr() INotExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INotExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INotExprContext) +} + +func (s *AndExprContext) AllAndTail() []IAndTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IAndTailContext); ok { + len++ + } + } + + tst := make([]IAndTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IAndTailContext); ok { + tst[i] = t.(IAndTailContext) + i++ + } + } + + return tst +} + +func (s *AndExprContext) AndTail(i int) IAndTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAndTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IAndTailContext) +} + +func (s *AndExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AndExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AndExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAndExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AndExpr() (localctx IAndExprContext) { + localctx = NewAndExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 18, SPL2ParserRULE_andExpr) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(116) + p.NotExpr() + } + p.SetState(120) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 6, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(117) + p.AndTail() + } + + } + p.SetState(122) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 6, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAndTailContext is an interface to support dynamic dispatch. +type IAndTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AND() antlr.TerminalNode + NotExpr() INotExprContext + AbsentOperand() IAbsentOperandContext + + // IsAndTailContext differentiates from other interfaces. + IsAndTailContext() +} + +type AndTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAndTailContext() *AndTailContext { + var p = new(AndTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_andTail + return p +} + +func InitEmptyAndTailContext(p *AndTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_andTail +} + +func (*AndTailContext) IsAndTailContext() {} + +func NewAndTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AndTailContext { + var p = new(AndTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_andTail + + return p +} + +func (s *AndTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *AndTailContext) AND() antlr.TerminalNode { + return s.GetToken(SPL2ParserAND, 0) +} + +func (s *AndTailContext) NotExpr() INotExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INotExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INotExprContext) +} + +func (s *AndTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *AndTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AndTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AndTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAndTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AndTail() (localctx IAndTailContext) { + localctx = NewAndTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 20, SPL2ParserRULE_andTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(123) + + if !(p.at(SPL2ParserAND)) { + p.SetError(antlr.NewFailedPredicateException(p, "p.at(SPL2ParserAND)", "")) + goto errorExit + } + { + p.SetState(124) + p.Match(SPL2ParserAND) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(127) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 7, p.GetParserRuleContext()) { + case 1: + { + p.SetState(125) + p.NotExpr() + } + + case 2: + { + p.SetState(126) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// INotExprContext is an interface to support dynamic dispatch. +type INotExprContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + NOT() antlr.TerminalNode + BANG() antlr.TerminalNode + NotExpr() INotExprContext + AbsentOperand() IAbsentOperandContext + Comparison() IComparisonContext + + // IsNotExprContext differentiates from other interfaces. + IsNotExprContext() +} + +type NotExprContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyNotExprContext() *NotExprContext { + var p = new(NotExprContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_notExpr + return p +} + +func InitEmptyNotExprContext(p *NotExprContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_notExpr +} + +func (*NotExprContext) IsNotExprContext() {} + +func NewNotExprContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *NotExprContext { + var p = new(NotExprContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_notExpr + + return p +} + +func (s *NotExprContext) GetParser() antlr.Parser { return s.parser } + +func (s *NotExprContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL2ParserNOT, 0) +} + +func (s *NotExprContext) BANG() antlr.TerminalNode { + return s.GetToken(SPL2ParserBANG, 0) +} + +func (s *NotExprContext) NotExpr() INotExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(INotExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(INotExprContext) +} + +func (s *NotExprContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *NotExprContext) Comparison() IComparisonContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IComparisonContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IComparisonContext) +} + +func (s *NotExprContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *NotExprContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *NotExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitNotExpr(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) NotExpr() (localctx INotExprContext) { + localctx = NewNotExprContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 22, SPL2ParserRULE_notExpr) + var _la int + + p.SetState(135) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) { + case 1: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(129) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL2ParserNOT || _la == SPL2ParserBANG) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + p.SetState(132) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 8, p.GetParserRuleContext()) { + case 1: + { + p.SetState(130) + p.NotExpr() + } + + case 2: + { + p.SetState(131) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(134) + p.Comparison() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IComparisonContext is an interface to support dynamic dispatch. +type IComparisonContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Additive() IAdditiveContext + AllComparisonTail() []IComparisonTailContext + ComparisonTail(i int) IComparisonTailContext + + // IsComparisonContext differentiates from other interfaces. + IsComparisonContext() +} + +type ComparisonContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyComparisonContext() *ComparisonContext { + var p = new(ComparisonContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_comparison + return p +} + +func InitEmptyComparisonContext(p *ComparisonContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_comparison +} + +func (*ComparisonContext) IsComparisonContext() {} + +func NewComparisonContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ComparisonContext { + var p = new(ComparisonContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_comparison + + return p +} + +func (s *ComparisonContext) GetParser() antlr.Parser { return s.parser } + +func (s *ComparisonContext) Additive() IAdditiveContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAdditiveContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAdditiveContext) +} + +func (s *ComparisonContext) AllComparisonTail() []IComparisonTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IComparisonTailContext); ok { + len++ + } + } + + tst := make([]IComparisonTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IComparisonTailContext); ok { + tst[i] = t.(IComparisonTailContext) + i++ + } + } + + return tst +} + +func (s *ComparisonContext) ComparisonTail(i int) IComparisonTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IComparisonTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IComparisonTailContext) +} + +func (s *ComparisonContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ComparisonContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ComparisonContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitComparison(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Comparison() (localctx IComparisonContext) { + localctx = NewComparisonContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 24, SPL2ParserRULE_comparison) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(137) + p.Additive() + } + p.SetState(141) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 10, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(138) + p.ComparisonTail() + } + + } + p.SetState(143) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 10, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IComparisonTailContext is an interface to support dynamic dispatch. +type IComparisonTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + CompOp() ICompOpContext + Additive() IAdditiveContext + AbsentOperand() IAbsentOperandContext + + // IsComparisonTailContext differentiates from other interfaces. + IsComparisonTailContext() +} + +type ComparisonTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyComparisonTailContext() *ComparisonTailContext { + var p = new(ComparisonTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_comparisonTail + return p +} + +func InitEmptyComparisonTailContext(p *ComparisonTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_comparisonTail +} + +func (*ComparisonTailContext) IsComparisonTailContext() {} + +func NewComparisonTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ComparisonTailContext { + var p = new(ComparisonTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_comparisonTail + + return p +} + +func (s *ComparisonTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *ComparisonTailContext) CompOp() ICompOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ICompOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ICompOpContext) +} + +func (s *ComparisonTailContext) Additive() IAdditiveContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAdditiveContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAdditiveContext) +} + +func (s *ComparisonTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *ComparisonTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ComparisonTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ComparisonTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitComparisonTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) ComparisonTail() (localctx IComparisonTailContext) { + localctx = NewComparisonTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 26, SPL2ParserRULE_comparisonTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(144) + + if !(p.atCompare()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atCompare()", "")) + goto errorExit + } + { + p.SetState(145) + p.CompOp() + } + p.SetState(148) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 11, p.GetParserRuleContext()) { + case 1: + { + p.SetState(146) + p.Additive() + } + + case 2: + { + p.SetState(147) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAdditiveContext is an interface to support dynamic dispatch. +type IAdditiveContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Multiplicative() IMultiplicativeContext + AllAdditiveTail() []IAdditiveTailContext + AdditiveTail(i int) IAdditiveTailContext + + // IsAdditiveContext differentiates from other interfaces. + IsAdditiveContext() +} + +type AdditiveContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAdditiveContext() *AdditiveContext { + var p = new(AdditiveContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_additive + return p +} + +func InitEmptyAdditiveContext(p *AdditiveContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_additive +} + +func (*AdditiveContext) IsAdditiveContext() {} + +func NewAdditiveContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AdditiveContext { + var p = new(AdditiveContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_additive + + return p +} + +func (s *AdditiveContext) GetParser() antlr.Parser { return s.parser } + +func (s *AdditiveContext) Multiplicative() IMultiplicativeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMultiplicativeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMultiplicativeContext) +} + +func (s *AdditiveContext) AllAdditiveTail() []IAdditiveTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IAdditiveTailContext); ok { + len++ + } + } + + tst := make([]IAdditiveTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IAdditiveTailContext); ok { + tst[i] = t.(IAdditiveTailContext) + i++ + } + } + + return tst +} + +func (s *AdditiveContext) AdditiveTail(i int) IAdditiveTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAdditiveTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IAdditiveTailContext) +} + +func (s *AdditiveContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AdditiveContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AdditiveContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAdditive(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Additive() (localctx IAdditiveContext) { + localctx = NewAdditiveContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 28, SPL2ParserRULE_additive) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(150) + p.Multiplicative() + } + p.SetState(154) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 12, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(151) + p.AdditiveTail() + } + + } + p.SetState(156) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 12, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAdditiveTailContext is an interface to support dynamic dispatch. +type IAdditiveTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AddOp() IAddOpContext + Multiplicative() IMultiplicativeContext + AbsentOperand() IAbsentOperandContext + + // IsAdditiveTailContext differentiates from other interfaces. + IsAdditiveTailContext() +} + +type AdditiveTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAdditiveTailContext() *AdditiveTailContext { + var p = new(AdditiveTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_additiveTail + return p +} + +func InitEmptyAdditiveTailContext(p *AdditiveTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_additiveTail +} + +func (*AdditiveTailContext) IsAdditiveTailContext() {} + +func NewAdditiveTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AdditiveTailContext { + var p = new(AdditiveTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_additiveTail + + return p +} + +func (s *AdditiveTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *AdditiveTailContext) AddOp() IAddOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAddOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAddOpContext) +} + +func (s *AdditiveTailContext) Multiplicative() IMultiplicativeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMultiplicativeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMultiplicativeContext) +} + +func (s *AdditiveTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *AdditiveTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AdditiveTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AdditiveTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAdditiveTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AdditiveTail() (localctx IAdditiveTailContext) { + localctx = NewAdditiveTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 30, SPL2ParserRULE_additiveTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(157) + + if !(p.atAdd()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atAdd()", "")) + goto errorExit + } + { + p.SetState(158) + p.AddOp() + } + p.SetState(161) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 13, p.GetParserRuleContext()) { + case 1: + { + p.SetState(159) + p.Multiplicative() + } + + case 2: + { + p.SetState(160) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IMultiplicativeContext is an interface to support dynamic dispatch. +type IMultiplicativeContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Unary() IUnaryContext + AllMultiplicativeTail() []IMultiplicativeTailContext + MultiplicativeTail(i int) IMultiplicativeTailContext + + // IsMultiplicativeContext differentiates from other interfaces. + IsMultiplicativeContext() +} + +type MultiplicativeContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyMultiplicativeContext() *MultiplicativeContext { + var p = new(MultiplicativeContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_multiplicative + return p +} + +func InitEmptyMultiplicativeContext(p *MultiplicativeContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_multiplicative +} + +func (*MultiplicativeContext) IsMultiplicativeContext() {} + +func NewMultiplicativeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MultiplicativeContext { + var p = new(MultiplicativeContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_multiplicative + + return p +} + +func (s *MultiplicativeContext) GetParser() antlr.Parser { return s.parser } + +func (s *MultiplicativeContext) Unary() IUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IUnaryContext) +} + +func (s *MultiplicativeContext) AllMultiplicativeTail() []IMultiplicativeTailContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IMultiplicativeTailContext); ok { + len++ + } + } + + tst := make([]IMultiplicativeTailContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IMultiplicativeTailContext); ok { + tst[i] = t.(IMultiplicativeTailContext) + i++ + } + } + + return tst +} + +func (s *MultiplicativeContext) MultiplicativeTail(i int) IMultiplicativeTailContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMultiplicativeTailContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IMultiplicativeTailContext) +} + +func (s *MultiplicativeContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *MultiplicativeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *MultiplicativeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitMultiplicative(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Multiplicative() (localctx IMultiplicativeContext) { + localctx = NewMultiplicativeContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 32, SPL2ParserRULE_multiplicative) + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(163) + p.Unary() + } + p.SetState(167) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 14, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(164) + p.MultiplicativeTail() + } + + } + p.SetState(169) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 14, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IMultiplicativeTailContext is an interface to support dynamic dispatch. +type IMultiplicativeTailContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + MulOp() IMulOpContext + Unary() IUnaryContext + AbsentOperand() IAbsentOperandContext + + // IsMultiplicativeTailContext differentiates from other interfaces. + IsMultiplicativeTailContext() +} + +type MultiplicativeTailContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyMultiplicativeTailContext() *MultiplicativeTailContext { + var p = new(MultiplicativeTailContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_multiplicativeTail + return p +} + +func InitEmptyMultiplicativeTailContext(p *MultiplicativeTailContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_multiplicativeTail +} + +func (*MultiplicativeTailContext) IsMultiplicativeTailContext() {} + +func NewMultiplicativeTailContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MultiplicativeTailContext { + var p = new(MultiplicativeTailContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_multiplicativeTail + + return p +} + +func (s *MultiplicativeTailContext) GetParser() antlr.Parser { return s.parser } + +func (s *MultiplicativeTailContext) MulOp() IMulOpContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IMulOpContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IMulOpContext) +} + +func (s *MultiplicativeTailContext) Unary() IUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IUnaryContext) +} + +func (s *MultiplicativeTailContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *MultiplicativeTailContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *MultiplicativeTailContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *MultiplicativeTailContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitMultiplicativeTail(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) MultiplicativeTail() (localctx IMultiplicativeTailContext) { + localctx = NewMultiplicativeTailContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 34, SPL2ParserRULE_multiplicativeTail) + p.EnterOuterAlt(localctx, 1) + p.SetState(170) + + if !(p.atMul()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.atMul()", "")) + goto errorExit + } + { + p.SetState(171) + p.MulOp() + } + p.SetState(174) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 15, p.GetParserRuleContext()) { + case 1: + { + p.SetState(172) + p.Unary() + } + + case 2: + { + p.SetState(173) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IUnaryContext is an interface to support dynamic dispatch. +type IUnaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + Sign() ISignContext + Unary() IUnaryContext + AbsentOperand() IAbsentOperandContext + Primary() IPrimaryContext + + // IsUnaryContext differentiates from other interfaces. + IsUnaryContext() +} + +type UnaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyUnaryContext() *UnaryContext { + var p = new(UnaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_unary + return p +} + +func InitEmptyUnaryContext(p *UnaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_unary +} + +func (*UnaryContext) IsUnaryContext() {} + +func NewUnaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *UnaryContext { + var p = new(UnaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_unary + + return p +} + +func (s *UnaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *UnaryContext) Sign() ISignContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISignContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISignContext) +} + +func (s *UnaryContext) Unary() IUnaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IUnaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IUnaryContext) +} + +func (s *UnaryContext) AbsentOperand() IAbsentOperandContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAbsentOperandContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAbsentOperandContext) +} + +func (s *UnaryContext) Primary() IPrimaryContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IPrimaryContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IPrimaryContext) +} + +func (s *UnaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *UnaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *UnaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitUnary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Unary() (localctx IUnaryContext) { + localctx = NewUnaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 36, SPL2ParserRULE_unary) + p.SetState(182) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 17, p.GetParserRuleContext()) { + case 1: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(176) + p.Sign() + } + p.SetState(179) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 16, p.GetParserRuleContext()) { + case 1: + { + p.SetState(177) + p.Unary() + } + + case 2: + { + p.SetState(178) + p.AbsentOperand() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + + case 2: + p.EnterOuterAlt(localctx, 2) + { + p.SetState(181) + p.Primary() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IPrimaryContext is an interface to support dynamic dispatch. +type IPrimaryContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + LPAREN() antlr.TerminalNode + AllExpr() []IExprContext + Expr(i int) IExprContext + RPAREN() antlr.TerminalNode + IdentLike() IIdentLikeContext + AllCOMMA() []antlr.TerminalNode + COMMA(i int) antlr.TerminalNode + STRING() antlr.TerminalNode + NUMBER() antlr.TerminalNode + DURATION() antlr.TerminalNode + Subsearch() ISubsearchContext + + // IsPrimaryContext differentiates from other interfaces. + IsPrimaryContext() +} + +type PrimaryContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyPrimaryContext() *PrimaryContext { + var p = new(PrimaryContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_primary + return p +} + +func InitEmptyPrimaryContext(p *PrimaryContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_primary +} + +func (*PrimaryContext) IsPrimaryContext() {} + +func NewPrimaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PrimaryContext { + var p = new(PrimaryContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_primary + + return p +} + +func (s *PrimaryContext) GetParser() antlr.Parser { return s.parser } + +func (s *PrimaryContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL2ParserLPAREN, 0) +} + +func (s *PrimaryContext) AllExpr() []IExprContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IExprContext); ok { + len++ + } + } + + tst := make([]IExprContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IExprContext); ok { + tst[i] = t.(IExprContext) + i++ + } + } + + return tst +} + +func (s *PrimaryContext) Expr(i int) IExprContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IExprContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IExprContext) +} + +func (s *PrimaryContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL2ParserRPAREN, 0) +} + +func (s *PrimaryContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *PrimaryContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL2ParserCOMMA) +} + +func (s *PrimaryContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL2ParserCOMMA, i) +} + +func (s *PrimaryContext) STRING() antlr.TerminalNode { + return s.GetToken(SPL2ParserSTRING, 0) +} + +func (s *PrimaryContext) NUMBER() antlr.TerminalNode { + return s.GetToken(SPL2ParserNUMBER, 0) +} + +func (s *PrimaryContext) DURATION() antlr.TerminalNode { + return s.GetToken(SPL2ParserDURATION, 0) +} + +func (s *PrimaryContext) Subsearch() ISubsearchContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(ISubsearchContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(ISubsearchContext) +} + +func (s *PrimaryContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *PrimaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *PrimaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitPrimary(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Primary() (localctx IPrimaryContext) { + localctx = NewPrimaryContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 38, SPL2ParserRULE_primary) + var _la int + + p.SetState(208) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + + switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 20, p.GetParserRuleContext()) { + case 1: + p.EnterOuterAlt(localctx, 1) + { + p.SetState(184) + p.Match(SPL2ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(185) + p.Expr() + } + { + p.SetState(186) + p.Match(SPL2ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 2: + p.EnterOuterAlt(localctx, 2) + p.SetState(188) + + if !(p.callAhead()) { + p.SetError(antlr.NewFailedPredicateException(p, "p.callAhead()", "")) + goto errorExit + } + { + p.SetState(189) + p.IdentLike() + } + { + p.SetState(190) + p.Match(SPL2ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(199) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 19, p.GetParserRuleContext()) == 1 { + { + p.SetState(191) + p.Expr() + } + p.SetState(196) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL2ParserCOMMA { + { + p.SetState(192) + p.Match(SPL2ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(193) + p.Expr() + } + + p.SetState(198) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + + } else if p.HasError() { // JIM + goto errorExit + } + { + p.SetState(201) + p.Match(SPL2ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 3: + p.EnterOuterAlt(localctx, 3) + { + p.SetState(203) + p.IdentLike() + } + + case 4: + p.EnterOuterAlt(localctx, 4) + { + p.SetState(204) + p.Match(SPL2ParserSTRING) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 5: + p.EnterOuterAlt(localctx, 5) + { + p.SetState(205) + p.Match(SPL2ParserNUMBER) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 6: + p.EnterOuterAlt(localctx, 6) + { + p.SetState(206) + p.Match(SPL2ParserDURATION) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + + case 7: + p.EnterOuterAlt(localctx, 7) + { + p.SetState(207) + p.Subsearch() + } + + case antlr.ATNInvalidAltNumber: + goto errorExit + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISubsearchContext is an interface to support dynamic dispatch. +type ISubsearchContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + LBRACKET() antlr.TerminalNode + AllPIPE() []antlr.TerminalNode + PIPE(i int) antlr.TerminalNode + AllEOF() []antlr.TerminalNode + EOF(i int) antlr.TerminalNode + + // IsSubsearchContext differentiates from other interfaces. + IsSubsearchContext() +} + +type SubsearchContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySubsearchContext() *SubsearchContext { + var p = new(SubsearchContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_subsearch + return p +} + +func InitEmptySubsearchContext(p *SubsearchContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_subsearch +} + +func (*SubsearchContext) IsSubsearchContext() {} + +func NewSubsearchContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SubsearchContext { + var p = new(SubsearchContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_subsearch + + return p +} + +func (s *SubsearchContext) GetParser() antlr.Parser { return s.parser } + +func (s *SubsearchContext) LBRACKET() antlr.TerminalNode { + return s.GetToken(SPL2ParserLBRACKET, 0) +} + +func (s *SubsearchContext) AllPIPE() []antlr.TerminalNode { + return s.GetTokens(SPL2ParserPIPE) +} + +func (s *SubsearchContext) PIPE(i int) antlr.TerminalNode { + return s.GetToken(SPL2ParserPIPE, i) +} + +func (s *SubsearchContext) AllEOF() []antlr.TerminalNode { + return s.GetTokens(SPL2ParserEOF) +} + +func (s *SubsearchContext) EOF(i int) antlr.TerminalNode { + return s.GetToken(SPL2ParserEOF, i) +} + +func (s *SubsearchContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SubsearchContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SubsearchContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitSubsearch(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Subsearch() (localctx ISubsearchContext) { + localctx = NewSubsearchContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 40, SPL2ParserRULE_subsearch) + var _la int + + var _alt int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(210) + p.Match(SPL2ParserLBRACKET) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.abortSubsearch() + p.SetState(215) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 21, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + for _alt != 2 && _alt != antlr.ATNInvalidAltNumber { + if _alt == 1 { + { + p.SetState(212) + _la = p.GetTokenStream().LA(1) + + if _la <= 0 || _la == SPL2ParserEOF || _la == SPL2ParserPIPE { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + + } + p.SetState(217) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 21, p.GetParserRuleContext()) + if p.HasError() { + goto errorExit + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAbsentOperandContext is an interface to support dynamic dispatch. +type IAbsentOperandContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EQ2() antlr.TerminalNode + EQ() antlr.TerminalNode + NE() antlr.TerminalNode + LT() antlr.TerminalNode + LE() antlr.TerminalNode + GT() antlr.TerminalNode + GE() antlr.TerminalNode + COMMA() antlr.TerminalNode + RPAREN() antlr.TerminalNode + RBRACKET() antlr.TerminalNode + PIPE() antlr.TerminalNode + EOF() antlr.TerminalNode + + // IsAbsentOperandContext differentiates from other interfaces. + IsAbsentOperandContext() +} + +type AbsentOperandContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAbsentOperandContext() *AbsentOperandContext { + var p = new(AbsentOperandContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_absentOperand + return p +} + +func InitEmptyAbsentOperandContext(p *AbsentOperandContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_absentOperand +} + +func (*AbsentOperandContext) IsAbsentOperandContext() {} + +func NewAbsentOperandContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AbsentOperandContext { + var p = new(AbsentOperandContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_absentOperand + + return p +} + +func (s *AbsentOperandContext) GetParser() antlr.Parser { return s.parser } + +func (s *AbsentOperandContext) EQ2() antlr.TerminalNode { + return s.GetToken(SPL2ParserEQ2, 0) +} + +func (s *AbsentOperandContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL2ParserEQ, 0) +} + +func (s *AbsentOperandContext) NE() antlr.TerminalNode { + return s.GetToken(SPL2ParserNE, 0) +} + +func (s *AbsentOperandContext) LT() antlr.TerminalNode { + return s.GetToken(SPL2ParserLT, 0) +} + +func (s *AbsentOperandContext) LE() antlr.TerminalNode { + return s.GetToken(SPL2ParserLE, 0) +} + +func (s *AbsentOperandContext) GT() antlr.TerminalNode { + return s.GetToken(SPL2ParserGT, 0) +} + +func (s *AbsentOperandContext) GE() antlr.TerminalNode { + return s.GetToken(SPL2ParserGE, 0) +} + +func (s *AbsentOperandContext) COMMA() antlr.TerminalNode { + return s.GetToken(SPL2ParserCOMMA, 0) +} + +func (s *AbsentOperandContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL2ParserRPAREN, 0) +} + +func (s *AbsentOperandContext) RBRACKET() antlr.TerminalNode { + return s.GetToken(SPL2ParserRBRACKET, 0) +} + +func (s *AbsentOperandContext) PIPE() antlr.TerminalNode { + return s.GetToken(SPL2ParserPIPE, 0) +} + +func (s *AbsentOperandContext) EOF() antlr.TerminalNode { + return s.GetToken(SPL2ParserEOF, 0) +} + +func (s *AbsentOperandContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AbsentOperandContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AbsentOperandContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAbsentOperand(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AbsentOperand() (localctx IAbsentOperandContext) { + localctx = NewAbsentOperandContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 42, SPL2ParserRULE_absentOperand) + var _la int + + p.EnterOuterAlt(localctx, 1) + p.abortMissingOperand() + { + p.SetState(219) + _la = p.GetTokenStream().LA(1) + + if !((int64((_la - -1)) & ^0x3f) == 0 && ((int64(1)<<(_la - -1))&182435841) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAggListContext is an interface to support dynamic dispatch. +type IAggListContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AllAgg() []IAggContext + Agg(i int) IAggContext + AllCOMMA() []antlr.TerminalNode + COMMA(i int) antlr.TerminalNode + + // IsAggListContext differentiates from other interfaces. + IsAggListContext() +} + +type AggListContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAggListContext() *AggListContext { + var p = new(AggListContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_aggList + return p +} + +func InitEmptyAggListContext(p *AggListContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_aggList +} + +func (*AggListContext) IsAggListContext() {} + +func NewAggListContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AggListContext { + var p = new(AggListContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_aggList + + return p +} + +func (s *AggListContext) GetParser() antlr.Parser { return s.parser } + +func (s *AggListContext) AllAgg() []IAggContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IAggContext); ok { + len++ + } + } + + tst := make([]IAggContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IAggContext); ok { + tst[i] = t.(IAggContext) + i++ + } + } + + return tst +} + +func (s *AggListContext) Agg(i int) IAggContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAggContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IAggContext) +} + +func (s *AggListContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL2ParserCOMMA) +} + +func (s *AggListContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL2ParserCOMMA, i) +} + +func (s *AggListContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AggListContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AggListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAggList(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AggList() (localctx IAggListContext) { + localctx = NewAggListContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 44, SPL2ParserRULE_aggList) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(221) + p.Agg() + } + p.SetState(226) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL2ParserCOMMA { + { + p.SetState(222) + p.Match(SPL2ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(223) + p.Agg() + } + + p.SetState(228) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAggContext is an interface to support dynamic dispatch. +type IAggContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + LPAREN() antlr.TerminalNode + RPAREN() antlr.TerminalNode + Expr() IExprContext + AliasClause() IAliasClauseContext + + // IsAggContext differentiates from other interfaces. + IsAggContext() +} + +type AggContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAggContext() *AggContext { + var p = new(AggContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_agg + return p +} + +func InitEmptyAggContext(p *AggContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_agg +} + +func (*AggContext) IsAggContext() {} + +func NewAggContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AggContext { + var p = new(AggContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_agg + + return p +} + +func (s *AggContext) GetParser() antlr.Parser { return s.parser } + +func (s *AggContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *AggContext) LPAREN() antlr.TerminalNode { + return s.GetToken(SPL2ParserLPAREN, 0) +} + +func (s *AggContext) RPAREN() antlr.TerminalNode { + return s.GetToken(SPL2ParserRPAREN, 0) +} + +func (s *AggContext) Expr() IExprContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IExprContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IExprContext) +} + +func (s *AggContext) AliasClause() IAliasClauseContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IAliasClauseContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IAliasClauseContext) +} + +func (s *AggContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AggContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AggContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAgg(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Agg() (localctx IAggContext) { + localctx = NewAggContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 46, SPL2ParserRULE_agg) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(229) + p.IdentLike() + } + { + p.SetState(230) + p.Match(SPL2ParserLPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(232) + p.GetErrorHandler().Sync(p) + + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 23, p.GetParserRuleContext()) == 1 { + { + p.SetState(231) + p.Expr() + } + + } else if p.HasError() { // JIM + goto errorExit + } + { + p.SetState(234) + p.Match(SPL2ParserRPAREN) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + p.SetState(236) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + if _la == SPL2ParserAS { + { + p.SetState(235) + p.AliasClause() + } + + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAliasClauseContext is an interface to support dynamic dispatch. +type IAliasClauseContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AS() antlr.TerminalNode + IdentLike() IIdentLikeContext + + // IsAliasClauseContext differentiates from other interfaces. + IsAliasClauseContext() +} + +type AliasClauseContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAliasClauseContext() *AliasClauseContext { + var p = new(AliasClauseContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_aliasClause + return p +} + +func InitEmptyAliasClauseContext(p *AliasClauseContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_aliasClause +} + +func (*AliasClauseContext) IsAliasClauseContext() {} + +func NewAliasClauseContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AliasClauseContext { + var p = new(AliasClauseContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_aliasClause + + return p +} + +func (s *AliasClauseContext) GetParser() antlr.Parser { return s.parser } + +func (s *AliasClauseContext) AS() antlr.TerminalNode { + return s.GetToken(SPL2ParserAS, 0) +} + +func (s *AliasClauseContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *AliasClauseContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AliasClauseContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AliasClauseContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAliasClause(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AliasClause() (localctx IAliasClauseContext) { + localctx = NewAliasClauseContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 48, SPL2ParserRULE_aliasClause) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(238) + p.Match(SPL2ParserAS) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(239) + p.IdentLike() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IByClauseContext is an interface to support dynamic dispatch. +type IByClauseContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + BY() antlr.TerminalNode + FieldList() IFieldListContext + + // IsByClauseContext differentiates from other interfaces. + IsByClauseContext() +} + +type ByClauseContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyByClauseContext() *ByClauseContext { + var p = new(ByClauseContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_byClause + return p +} + +func InitEmptyByClauseContext(p *ByClauseContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_byClause +} + +func (*ByClauseContext) IsByClauseContext() {} + +func NewByClauseContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ByClauseContext { + var p = new(ByClauseContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_byClause + + return p +} + +func (s *ByClauseContext) GetParser() antlr.Parser { return s.parser } + +func (s *ByClauseContext) BY() antlr.TerminalNode { + return s.GetToken(SPL2ParserBY, 0) +} + +func (s *ByClauseContext) FieldList() IFieldListContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFieldListContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IFieldListContext) +} + +func (s *ByClauseContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *ByClauseContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *ByClauseContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitByClause(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) ByClause() (localctx IByClauseContext) { + localctx = NewByClauseContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 50, SPL2ParserRULE_byClause) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(241) + p.Match(SPL2ParserBY) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(242) + p.FieldList() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IFieldListContext is an interface to support dynamic dispatch. +type IFieldListContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + AllField() []IFieldContext + Field(i int) IFieldContext + AllCOMMA() []antlr.TerminalNode + COMMA(i int) antlr.TerminalNode + + // IsFieldListContext differentiates from other interfaces. + IsFieldListContext() +} + +type FieldListContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyFieldListContext() *FieldListContext { + var p = new(FieldListContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_fieldList + return p +} + +func InitEmptyFieldListContext(p *FieldListContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_fieldList +} + +func (*FieldListContext) IsFieldListContext() {} + +func NewFieldListContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldListContext { + var p = new(FieldListContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_fieldList + + return p +} + +func (s *FieldListContext) GetParser() antlr.Parser { return s.parser } + +func (s *FieldListContext) AllField() []IFieldContext { + children := s.GetChildren() + len := 0 + for _, ctx := range children { + if _, ok := ctx.(IFieldContext); ok { + len++ + } + } + + tst := make([]IFieldContext, len) + i := 0 + for _, ctx := range children { + if t, ok := ctx.(IFieldContext); ok { + tst[i] = t.(IFieldContext) + i++ + } + } + + return tst +} + +func (s *FieldListContext) Field(i int) IFieldContext { + var t antlr.RuleContext + j := 0 + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IFieldContext); ok { + if j == i { + t = ctx.(antlr.RuleContext) + break + } + j++ + } + } + + if t == nil { + return nil + } + + return t.(IFieldContext) +} + +func (s *FieldListContext) AllCOMMA() []antlr.TerminalNode { + return s.GetTokens(SPL2ParserCOMMA) +} + +func (s *FieldListContext) COMMA(i int) antlr.TerminalNode { + return s.GetToken(SPL2ParserCOMMA, i) +} + +func (s *FieldListContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *FieldListContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *FieldListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitFieldList(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) FieldList() (localctx IFieldListContext) { + localctx = NewFieldListContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 52, SPL2ParserRULE_fieldList) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(244) + p.Field() + } + p.SetState(249) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + + for _la == SPL2ParserCOMMA { + { + p.SetState(245) + p.Match(SPL2ParserCOMMA) + if p.HasError() { + // Recognition error - abort rule + goto errorExit + } + } + { + p.SetState(246) + p.Field() + } + + p.SetState(251) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit + } + _la = p.GetTokenStream().LA(1) + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IFieldContext is an interface to support dynamic dispatch. +type IFieldContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IdentLike() IIdentLikeContext + + // IsFieldContext differentiates from other interfaces. + IsFieldContext() +} + +type FieldContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyFieldContext() *FieldContext { + var p = new(FieldContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_field + return p +} + +func InitEmptyFieldContext(p *FieldContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_field +} + +func (*FieldContext) IsFieldContext() {} + +func NewFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldContext { + var p = new(FieldContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_field + + return p +} + +func (s *FieldContext) GetParser() antlr.Parser { return s.parser } + +func (s *FieldContext) IdentLike() IIdentLikeContext { + var t antlr.RuleContext + for _, ctx := range s.GetChildren() { + if _, ok := ctx.(IIdentLikeContext); ok { + t = ctx.(antlr.RuleContext) + break + } + } + + if t == nil { + return nil + } + + return t.(IIdentLikeContext) +} + +func (s *FieldContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *FieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *FieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitField(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Field() (localctx IFieldContext) { + localctx = NewFieldContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 54, SPL2ParserRULE_field) + p.EnterOuterAlt(localctx, 1) + { + p.SetState(252) + p.IdentLike() + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ICompOpContext is an interface to support dynamic dispatch. +type ICompOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + EQ2() antlr.TerminalNode + EQ() antlr.TerminalNode + NE() antlr.TerminalNode + LT() antlr.TerminalNode + LE() antlr.TerminalNode + GT() antlr.TerminalNode + GE() antlr.TerminalNode + + // IsCompOpContext differentiates from other interfaces. + IsCompOpContext() +} + +type CompOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyCompOpContext() *CompOpContext { + var p = new(CompOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_compOp + return p +} + +func InitEmptyCompOpContext(p *CompOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_compOp +} + +func (*CompOpContext) IsCompOpContext() {} + +func NewCompOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *CompOpContext { + var p = new(CompOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_compOp + + return p +} + +func (s *CompOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *CompOpContext) EQ2() antlr.TerminalNode { + return s.GetToken(SPL2ParserEQ2, 0) +} + +func (s *CompOpContext) EQ() antlr.TerminalNode { + return s.GetToken(SPL2ParserEQ, 0) +} + +func (s *CompOpContext) NE() antlr.TerminalNode { + return s.GetToken(SPL2ParserNE, 0) +} + +func (s *CompOpContext) LT() antlr.TerminalNode { + return s.GetToken(SPL2ParserLT, 0) +} + +func (s *CompOpContext) LE() antlr.TerminalNode { + return s.GetToken(SPL2ParserLE, 0) +} + +func (s *CompOpContext) GT() antlr.TerminalNode { + return s.GetToken(SPL2ParserGT, 0) +} + +func (s *CompOpContext) GE() antlr.TerminalNode { + return s.GetToken(SPL2ParserGE, 0) +} + +func (s *CompOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *CompOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *CompOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitCompOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) CompOp() (localctx ICompOpContext) { + localctx = NewCompOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 56, SPL2ParserRULE_compOp) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(254) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1040384) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IAddOpContext is an interface to support dynamic dispatch. +type IAddOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + PLUS() antlr.TerminalNode + MINUS() antlr.TerminalNode + + // IsAddOpContext differentiates from other interfaces. + IsAddOpContext() +} + +type AddOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyAddOpContext() *AddOpContext { + var p = new(AddOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_addOp + return p +} + +func InitEmptyAddOpContext(p *AddOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_addOp +} + +func (*AddOpContext) IsAddOpContext() {} + +func NewAddOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AddOpContext { + var p = new(AddOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_addOp + + return p +} + +func (s *AddOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *AddOpContext) PLUS() antlr.TerminalNode { + return s.GetToken(SPL2ParserPLUS, 0) +} + +func (s *AddOpContext) MINUS() antlr.TerminalNode { + return s.GetToken(SPL2ParserMINUS, 0) +} + +func (s *AddOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *AddOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *AddOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitAddOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) AddOp() (localctx IAddOpContext) { + localctx = NewAddOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 58, SPL2ParserRULE_addOp) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(256) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL2ParserPLUS || _la == SPL2ParserMINUS) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IMulOpContext is an interface to support dynamic dispatch. +type IMulOpContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + STAR() antlr.TerminalNode + SLASH() antlr.TerminalNode + PERCENT() antlr.TerminalNode + + // IsMulOpContext differentiates from other interfaces. + IsMulOpContext() +} + +type MulOpContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyMulOpContext() *MulOpContext { + var p = new(MulOpContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_mulOp + return p +} + +func InitEmptyMulOpContext(p *MulOpContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_mulOp +} + +func (*MulOpContext) IsMulOpContext() {} + +func NewMulOpContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MulOpContext { + var p = new(MulOpContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_mulOp + + return p +} + +func (s *MulOpContext) GetParser() antlr.Parser { return s.parser } + +func (s *MulOpContext) STAR() antlr.TerminalNode { + return s.GetToken(SPL2ParserSTAR, 0) +} + +func (s *MulOpContext) SLASH() antlr.TerminalNode { + return s.GetToken(SPL2ParserSLASH, 0) +} + +func (s *MulOpContext) PERCENT() antlr.TerminalNode { + return s.GetToken(SPL2ParserPERCENT, 0) +} + +func (s *MulOpContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *MulOpContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *MulOpContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitMulOp(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) MulOp() (localctx IMulOpContext) { + localctx = NewMulOpContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 60, SPL2ParserRULE_mulOp) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(258) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&3758096384) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// ISignContext is an interface to support dynamic dispatch. +type ISignContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + MINUS() antlr.TerminalNode + PLUS() antlr.TerminalNode + + // IsSignContext differentiates from other interfaces. + IsSignContext() +} + +type SignContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptySignContext() *SignContext { + var p = new(SignContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_sign + return p +} + +func InitEmptySignContext(p *SignContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_sign +} + +func (*SignContext) IsSignContext() {} + +func NewSignContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SignContext { + var p = new(SignContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_sign + + return p +} + +func (s *SignContext) GetParser() antlr.Parser { return s.parser } + +func (s *SignContext) MINUS() antlr.TerminalNode { + return s.GetToken(SPL2ParserMINUS, 0) +} + +func (s *SignContext) PLUS() antlr.TerminalNode { + return s.GetToken(SPL2ParserPLUS, 0) +} + +func (s *SignContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *SignContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *SignContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitSign(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) Sign() (localctx ISignContext) { + localctx = NewSignContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 62, SPL2ParserRULE_sign) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(260) + _la = p.GetTokenStream().LA(1) + + if !(_la == SPL2ParserPLUS || _la == SPL2ParserMINUS) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +// IIdentLikeContext is an interface to support dynamic dispatch. +type IIdentLikeContext interface { + antlr.ParserRuleContext + + // GetParser returns the parser. + GetParser() antlr.Parser + + // Getter signatures + IDENT() antlr.TerminalNode + FROM() antlr.TerminalNode + WHERE() antlr.TerminalNode + STATS() antlr.TerminalNode + BY() antlr.TerminalNode + AS() antlr.TerminalNode + AND() antlr.TerminalNode + OR() antlr.TerminalNode + NOT() antlr.TerminalNode + + // IsIdentLikeContext differentiates from other interfaces. + IsIdentLikeContext() +} + +type IdentLikeContext struct { + antlr.BaseParserRuleContext + parser antlr.Parser +} + +func NewEmptyIdentLikeContext() *IdentLikeContext { + var p = new(IdentLikeContext) + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_identLike + return p +} + +func InitEmptyIdentLikeContext(p *IdentLikeContext) { + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) + p.RuleIndex = SPL2ParserRULE_identLike +} + +func (*IdentLikeContext) IsIdentLikeContext() {} + +func NewIdentLikeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IdentLikeContext { + var p = new(IdentLikeContext) + + antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) + + p.parser = parser + p.RuleIndex = SPL2ParserRULE_identLike + + return p +} + +func (s *IdentLikeContext) GetParser() antlr.Parser { return s.parser } + +func (s *IdentLikeContext) IDENT() antlr.TerminalNode { + return s.GetToken(SPL2ParserIDENT, 0) +} + +func (s *IdentLikeContext) FROM() antlr.TerminalNode { + return s.GetToken(SPL2ParserFROM, 0) +} + +func (s *IdentLikeContext) WHERE() antlr.TerminalNode { + return s.GetToken(SPL2ParserWHERE, 0) +} + +func (s *IdentLikeContext) STATS() antlr.TerminalNode { + return s.GetToken(SPL2ParserSTATS, 0) +} + +func (s *IdentLikeContext) BY() antlr.TerminalNode { + return s.GetToken(SPL2ParserBY, 0) +} + +func (s *IdentLikeContext) AS() antlr.TerminalNode { + return s.GetToken(SPL2ParserAS, 0) +} + +func (s *IdentLikeContext) AND() antlr.TerminalNode { + return s.GetToken(SPL2ParserAND, 0) +} + +func (s *IdentLikeContext) OR() antlr.TerminalNode { + return s.GetToken(SPL2ParserOR, 0) +} + +func (s *IdentLikeContext) NOT() antlr.TerminalNode { + return s.GetToken(SPL2ParserNOT, 0) +} + +func (s *IdentLikeContext) GetRuleContext() antlr.RuleContext { + return s +} + +func (s *IdentLikeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { + return antlr.TreesStringTree(s, ruleNames, recog) +} + +func (s *IdentLikeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { + switch t := visitor.(type) { + case SPL2Visitor: + return t.VisitIdentLike(s) + + default: + return t.VisitChildren(s) + } +} + +func (p *SPL2Parser) IdentLike() (localctx IIdentLikeContext) { + localctx = NewIdentLikeContext(p, p.GetParserRuleContext(), p.GetState()) + p.EnterRule(localctx, 64, SPL2ParserRULE_identLike) + var _la int + + p.EnterOuterAlt(localctx, 1) + { + p.SetState(262) + _la = p.GetTokenStream().LA(1) + + if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&4606) != 0) { + p.GetErrorHandler().RecoverInline(p) + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() + } + } + +errorExit: + if p.HasError() { + v := p.GetError() + localctx.SetException(v) + p.GetErrorHandler().ReportError(p, v) + p.GetErrorHandler().Recover(p, v) + p.SetError(nil) + } + p.ExitRule() + return localctx + goto errorExit // Trick to prevent compiler error if the label is not used +} + +func (p *SPL2Parser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { + switch ruleIndex { + case 4: + var t *IndexNameContext = nil + if localctx != nil { + t = localctx.(*IndexNameContext) + } + return p.IndexName_Sempred(t, predIndex) + + case 5: + var t *IndexTailContext = nil + if localctx != nil { + t = localctx.(*IndexTailContext) + } + return p.IndexTail_Sempred(t, predIndex) + + case 8: + var t *OrTailContext = nil + if localctx != nil { + t = localctx.(*OrTailContext) + } + return p.OrTail_Sempred(t, predIndex) + + case 10: + var t *AndTailContext = nil + if localctx != nil { + t = localctx.(*AndTailContext) + } + return p.AndTail_Sempred(t, predIndex) + + case 13: + var t *ComparisonTailContext = nil + if localctx != nil { + t = localctx.(*ComparisonTailContext) + } + return p.ComparisonTail_Sempred(t, predIndex) + + case 15: + var t *AdditiveTailContext = nil + if localctx != nil { + t = localctx.(*AdditiveTailContext) + } + return p.AdditiveTail_Sempred(t, predIndex) + + case 17: + var t *MultiplicativeTailContext = nil + if localctx != nil { + t = localctx.(*MultiplicativeTailContext) + } + return p.MultiplicativeTail_Sempred(t, predIndex) + + case 19: + var t *PrimaryContext = nil + if localctx != nil { + t = localctx.(*PrimaryContext) + } + return p.Primary_Sempred(t, predIndex) + + default: + panic("No predicate with index: " + fmt.Sprint(ruleIndex)) + } +} + +func (p *SPL2Parser) IndexName_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 0: + return p.touchingPrev() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) IndexTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 1: + return p.hyphenRun() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) OrTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 2: + return p.at(SPL2ParserOR) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) AndTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 3: + return p.at(SPL2ParserAND) + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) ComparisonTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 4: + return p.atCompare() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) AdditiveTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 5: + return p.atAdd() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) MultiplicativeTail_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 6: + return p.atMul() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} + +func (p *SPL2Parser) Primary_Sempred(localctx antlr.RuleContext, predIndex int) bool { + switch predIndex { + case 7: + return p.callAhead() + + default: + panic("No predicate with index: " + fmt.Sprint(predIndex)) + } +} diff --git a/pkg/parser/spl2/gen/spl2_visitor.go b/pkg/parser/spl2/gen/spl2_visitor.go new file mode 100644 index 0000000..7fe12d8 --- /dev/null +++ b/pkg/parser/spl2/gen/spl2_visitor.go @@ -0,0 +1,108 @@ +// Code generated from pkg/parser/spl2/grammar/SPL2.g4 by ANTLR 4.13.2. DO NOT EDIT. + +package spl2gen // SPL2 +import "github.com/antlr4-go/antlr/v4" + +// A complete Visitor for a parse tree produced by SPL2Parser. +type SPL2Visitor interface { + antlr.ParseTreeVisitor + + // Visit a parse tree produced by SPL2Parser#stageFrom. + VisitStageFrom(ctx *StageFromContext) interface{} + + // Visit a parse tree produced by SPL2Parser#stageWhere. + VisitStageWhere(ctx *StageWhereContext) interface{} + + // Visit a parse tree produced by SPL2Parser#stageStats. + VisitStageStats(ctx *StageStatsContext) interface{} + + // Visit a parse tree produced by SPL2Parser#stageEnd. + VisitStageEnd(ctx *StageEndContext) interface{} + + // Visit a parse tree produced by SPL2Parser#indexName. + VisitIndexName(ctx *IndexNameContext) interface{} + + // Visit a parse tree produced by SPL2Parser#indexTail. + VisitIndexTail(ctx *IndexTailContext) interface{} + + // Visit a parse tree produced by SPL2Parser#expr. + VisitExpr(ctx *ExprContext) interface{} + + // Visit a parse tree produced by SPL2Parser#orExpr. + VisitOrExpr(ctx *OrExprContext) interface{} + + // Visit a parse tree produced by SPL2Parser#orTail. + VisitOrTail(ctx *OrTailContext) interface{} + + // Visit a parse tree produced by SPL2Parser#andExpr. + VisitAndExpr(ctx *AndExprContext) interface{} + + // Visit a parse tree produced by SPL2Parser#andTail. + VisitAndTail(ctx *AndTailContext) interface{} + + // Visit a parse tree produced by SPL2Parser#notExpr. + VisitNotExpr(ctx *NotExprContext) interface{} + + // Visit a parse tree produced by SPL2Parser#comparison. + VisitComparison(ctx *ComparisonContext) interface{} + + // Visit a parse tree produced by SPL2Parser#comparisonTail. + VisitComparisonTail(ctx *ComparisonTailContext) interface{} + + // Visit a parse tree produced by SPL2Parser#additive. + VisitAdditive(ctx *AdditiveContext) interface{} + + // Visit a parse tree produced by SPL2Parser#additiveTail. + VisitAdditiveTail(ctx *AdditiveTailContext) interface{} + + // Visit a parse tree produced by SPL2Parser#multiplicative. + VisitMultiplicative(ctx *MultiplicativeContext) interface{} + + // Visit a parse tree produced by SPL2Parser#multiplicativeTail. + VisitMultiplicativeTail(ctx *MultiplicativeTailContext) interface{} + + // Visit a parse tree produced by SPL2Parser#unary. + VisitUnary(ctx *UnaryContext) interface{} + + // Visit a parse tree produced by SPL2Parser#primary. + VisitPrimary(ctx *PrimaryContext) interface{} + + // Visit a parse tree produced by SPL2Parser#subsearch. + VisitSubsearch(ctx *SubsearchContext) interface{} + + // Visit a parse tree produced by SPL2Parser#absentOperand. + VisitAbsentOperand(ctx *AbsentOperandContext) interface{} + + // Visit a parse tree produced by SPL2Parser#aggList. + VisitAggList(ctx *AggListContext) interface{} + + // Visit a parse tree produced by SPL2Parser#agg. + VisitAgg(ctx *AggContext) interface{} + + // Visit a parse tree produced by SPL2Parser#aliasClause. + VisitAliasClause(ctx *AliasClauseContext) interface{} + + // Visit a parse tree produced by SPL2Parser#byClause. + VisitByClause(ctx *ByClauseContext) interface{} + + // Visit a parse tree produced by SPL2Parser#fieldList. + VisitFieldList(ctx *FieldListContext) interface{} + + // Visit a parse tree produced by SPL2Parser#field. + VisitField(ctx *FieldContext) interface{} + + // Visit a parse tree produced by SPL2Parser#compOp. + VisitCompOp(ctx *CompOpContext) interface{} + + // Visit a parse tree produced by SPL2Parser#addOp. + VisitAddOp(ctx *AddOpContext) interface{} + + // Visit a parse tree produced by SPL2Parser#mulOp. + VisitMulOp(ctx *MulOpContext) interface{} + + // Visit a parse tree produced by SPL2Parser#sign. + VisitSign(ctx *SignContext) interface{} + + // Visit a parse tree produced by SPL2Parser#identLike. + VisitIdentLike(ctx *IdentLikeContext) interface{} +} diff --git a/pkg/parser/spl2/grammar/SPL2.g4 b/pkg/parser/spl2/grammar/SPL2.g4 new file mode 100644 index 0000000..8bd42e0 --- /dev/null +++ b/pkg/parser/spl2/grammar/SPL2.g4 @@ -0,0 +1,341 @@ +// SPL2.g4 — the supported subset of Splunk's SPL2, parsed by ANTLR. +// +// The subset is `from` followed by any number of `where` and `stats` stages. +// A separate grammar from SPL1.g4 on purpose: SPL2 has typed expressions, one +// meaning for a bare word (a field reference, even on the right of a +// comparison), no implicit AND, and a pipeline that always starts at `from`. +// Sharing SPL1's rules would pull classic-SPL quirks into the newer language. +// +// The lexical rules are duplicated rather than imported from SPL1.g4 because +// the Go target's grammar imports cross package boundaries awkwardly. The +// lexer-parity test tokenizes one corpus with both generated lexers and +// asserts identical text and positions, so the duplication cannot drift +// silently. +// +// As in SPL1, three things stay outside the grammar: +// +// - Stage sequencing. `stageFrom`, `stageWhere`, and `stageStats` are entry +// rules the Go driver calls one stage at a time, so a first stage that is +// not `from` and a recognized-but-unimplemented command get their own +// positioned diagnostics before anything is parsed. +// - Dataset validation. The lowering refuses namespaced datasets, which the +// grammar cannot know are unusable as Elasticsearch indexes. +// - Index adjacency. `from logs-*` is one dataset name; the predicates below +// compare token spans, because adjacency is not expressible in a token +// rule. + +grammar SPL2; + +@parser::members { +// la returns the token type at lookahead k. +func (p *SPL2Parser) la(k int) int { return p.GetTokenStream().LA(k) } + +// tok returns the token at lookahead k; k may be negative. +func (p *SPL2Parser) tok(k int) antlr.Token { return p.GetTokenStream().LT(k) } + +// at reports whether the current token has type t. +func (p *SPL2Parser) at(t int) bool { return p.la(1) == t } + +// isIdentLike reports whether token type t is accepted by identLike. +func (p *SPL2Parser) isIdentLike(t int) bool { + switch t { + case SPL2ParserIDENT, SPL2ParserFROM, SPL2ParserWHERE, SPL2ParserSTATS, + SPL2ParserBY, SPL2ParserAS, SPL2ParserAND, SPL2ParserOR, SPL2ParserNOT: + return true + } + return false +} + +// touches reports whether the tokens at k and k+1 are adjacent in the source. +// Token offsets are rune indexes, so this is exact. +func (p *SPL2Parser) touches(k int) bool { + a, b := p.tok(k), p.tok(k+1) + if a == nil || b == nil { + return false + } + return a.GetStop()+1 == b.GetStart() +} + +// touchingPrev reports whether the current token starts exactly where the +// last consumed token ended. +func (p *SPL2Parser) touchingPrev() bool { + prev, cur := p.tok(-1), p.tok(1) + if prev == nil || cur == nil { + return false + } + return prev.GetStop()+1 == cur.GetStart() +} + +// hyphenRun reports whether a '-' continues a dataset name: it must touch the +// previous component and be followed, without a space, by a word, number, or +// wildcard. Whitespace therefore ends the name, and `from logs- *` is a +// syntax error at the '-'. +func (p *SPL2Parser) hyphenRun() bool { + return p.touchingPrev() && p.touches(1) && + (p.isIdentLike(p.la(2)) || p.la(2) == SPL2ParserNUMBER || p.la(2) == SPL2ParserSTAR) +} + +// callAhead reports whether an identifier is followed by '('. Adjacency is +// not required: `where lower (msg)="x"` is a call. +func (p *SPL2Parser) callAhead() bool { return p.la(2) == SPL2ParserLPAREN } + +// atNot, atCompare, atAdd, and atMul report whether the current token is an +// operator of that kind. The binary and unary rules gate on them so the parser +// commits to the operator and blames the missing operand after it. +func (p *SPL2Parser) atNot() bool { return p.at(SPL2ParserNOT) || p.at(SPL2ParserBANG) } + +func (p *SPL2Parser) atCompare() bool { + switch p.la(1) { + case SPL2ParserEQ2, SPL2ParserEQ, SPL2ParserNE, SPL2ParserLT, SPL2ParserLE, + SPL2ParserGT, SPL2ParserGE: + return true + } + return false +} + +func (p *SPL2Parser) atAdd() bool { return p.at(SPL2ParserPLUS) || p.at(SPL2ParserMINUS) } + +func (p *SPL2Parser) atMul() bool { + return p.at(SPL2ParserSTAR) || p.at(SPL2ParserSLASH) || p.at(SPL2ParserPERCENT) +} + +// parseAbort is the panic value for a grammar action that ends the parse at a +// token. The front-end recovers it structurally and maps the token through its +// SourceMap; generated code cannot import the front-end, so the methods below +// are the whole contract. +type parseAbort struct { + token antlr.Token + code string + message string +} + +func (a parseAbort) AbortToken() antlr.Token { return a.token } +func (a parseAbort) AbortCode() string { return a.code } +func (a parseAbort) AbortMessage() string { return a.message } + +// abortMissingOperand ends the parse at the token where an operand was +// required. +func (p *SPL2Parser) abortMissingOperand() { + t := p.tok(1) + message := "expected an expression, found end of query" + if t != nil && t.GetTokenType() != antlr.TokenEOF { + message = "expected an expression, found " + fmt.Sprintf("%q", t.GetText()) + } + panic(parseAbort{token: t, code: "syntax", message: message}) +} + +// abortSubsearch refuses a subsearch at its opening bracket, before the rest of +// the stage is parsed. +func (p *SPL2Parser) abortSubsearch() { + panic(parseAbort{ + token: p.tok(-1), + code: "unsupported-subsearch", + message: "subsearches are not supported", + }) +} +} + +// --- entry rules --------------------------------------------------------- +// +// The driver calls one of these per stage and inspects stageEnd to decide +// whether another stage follows. + +stageFrom : FROM indexName stageEnd ; +stageWhere : WHERE expr stageEnd ; +stageStats : STATS aggList byClause? stageEnd ; + +stageEnd : PIPE | EOF ; + +// --- datasets ------------------------------------------------------------ + +// A dataset is one unquoted name: words joined by adjacent hyphens, optionally +// ending in an adjacent wildcard. Every component must touch; whitespace ends +// the name. +indexName : identLike indexTail* ({p.touchingPrev()}? STAR)? ; + +indexTail + : {p.hyphenRun()}? MINUS (identLike | NUMBER | STAR) + ; + +// --- expressions --------------------------------------------------------- +// +// SPL2 is not context sensitive: a bare word is a field reference everywhere, +// including on the right of a comparison, and `AND` is required between +// conditions. There is no `*` primary, so `where status=*` and `stats count(*)` +// are syntax errors at the star rather than a guess about what a wildcard +// means in a typed expression. + +expr + : orExpr + ; + +orExpr + : andExpr orTail* + ; + +orTail + : {p.at(SPL2ParserOR)}? OR (andExpr | absentOperand) + ; + +andExpr + : notExpr andTail* + ; + +andTail + : {p.at(SPL2ParserAND)}? AND (notExpr | absentOperand) + ; + +notExpr + : (NOT | BANG) (notExpr | absentOperand) + | comparison + ; + +comparison + : additive comparisonTail* + ; + +comparisonTail + : {p.atCompare()}? compOp (additive | absentOperand) + ; + +additive + : multiplicative additiveTail* + ; + +additiveTail + : {p.atAdd()}? addOp (multiplicative | absentOperand) + ; + +multiplicative + : unary multiplicativeTail* + ; + +multiplicativeTail + : {p.atMul()}? mulOp (unary | absentOperand) + ; + +unary + : sign (unary | absentOperand) + | primary + ; + +primary + : LPAREN expr RPAREN + | {p.callAhead()}? identLike LPAREN (expr (COMMA expr)*)? RPAREN + | identLike + | STRING + | NUMBER + | DURATION + | subsearch + ; + +// A subsearch consumes the rest of its stage so the lowering layer can refuse +// it at the bracket instead of reporting a grammar error further in. +subsearch + : LBRACKET {p.abortSubsearch()} (~(PIPE | EOF))* + ; + +// absentOperand keeps every expression rule total: at a token that cannot +// begin a primary it ends the parse immediately, at the token where an operand +// was required. Totality is what lets prediction commit to an operator whose +// operand is missing, so the first diagnostic stays at the operand position +// instead of moving back to the operator. +absentOperand + : {p.abortMissingOperand()} (EQ2 | EQ | NE | LT | LE | GT | GE | COMMA | RPAREN | RBRACKET | PIPE | EOF) + ; + +// --- aggregates ---------------------------------------------------------- + +aggList + : agg (COMMA agg)* + ; + +// SPL2 requires the parentheses: `count()` aggregates the whole result set and +// `count(host)` aggregates a field. `stats count` is a syntax error. +agg + : identLike LPAREN expr? RPAREN aliasClause? + ; + +aliasClause + : AS identLike + ; + +byClause + : BY fieldList + ; + +fieldList + : field (COMMA field)* + ; + +field + : identLike + ; + +compOp : EQ2 | EQ | NE | LT | LE | GT | GE ; +addOp : PLUS | MINUS ; +mulOp : STAR | SLASH | PERCENT ; +sign : MINUS | PLUS ; + +identLike + : IDENT | FROM | WHERE | STATS | BY | AS | AND | OR | NOT + ; + +// --- lexer --------------------------------------------------------------- +// +// The lexical rules below are identical to SPL1.g4's; see the header. Keywords +// are ASCII fragments rather than the caseInsensitive option so the generated +// automaton is stable across ANTLR versions and targets. + +FROM : [fF][rR][oO][mM] ; +WHERE : [wW][hH][eE][rR][eE] ; +STATS : [sS][tT][aA][tT][sS] ; +BY : [bB][yY] ; +AS : [aA][sS] ; +AND : [aA][nN][dD] ; +OR : [oO][rR] ; +NOT : [nN][oO][tT] ; + +// Durations are declared before numbers; maximal munch keeps `1mon` whole. +DURATION : DIGITS ('.' DIGITS)? EXPONENT? UNIT ; +NUMBER : DIGITS ('.' DIGITS)? EXPONENT? ; + +STRING : '"' DQ_BODY '"' | '\'' SQ_BODY '\'' ; + +// A backslash escapes only the matching quote. Any other backslash stays a +// literal, including a run of them: `"a\\"` is unterminated because the last +// backslash escapes the closing quote. +fragment DQ_BODY : ('\\'+ '"' | '\\'+ ~["\\] | ~["\\])* ; +fragment SQ_BODY : ('\\'+ '\'' | '\\'+ ~['\\] | ~['\\])* ; + +IDENT : [_@A-Za-z] [_@A-Za-z0-9.:]* ; + +EQ2 : '==' ; +NE : '!=' ; +LE : '<=' ; +GE : '>=' ; +EQ : '=' ; +LT : '<' ; +GT : '>' ; +BANG : '!' ; +PIPE : '|' ; +COMMA : ',' ; +LPAREN : '(' ; +RPAREN : ')' ; +LBRACKET : '[' ; +RBRACKET : ']' ; +PLUS : '+' ; +MINUS : '-' ; +STAR : '*' ; +SLASH : '/' ; +PERCENT : '%' ; + +WS : [ \t\r\n]+ -> skip ; + +// The lexer never reports errors itself; the invalid-token pass in Go reports +// the first UNKNOWN token in source order with an exact position. +UNKNOWN : . ; + +fragment DIGITS : [0-9]+ ; +fragment EXPONENT : [eE] [+-]? [0-9]+ ; +fragment UNIT : 'mon' | 'ms' | [smhdwy] ; diff --git a/pkg/parser/spl2/lexer.go b/pkg/parser/spl2/lexer.go new file mode 100644 index 0000000..6450969 --- /dev/null +++ b/pkg/parser/spl2/lexer.go @@ -0,0 +1,139 @@ +package spl2 + +import ( + "fmt" + "strconv" + "unicode/utf8" + + "github.com/antlr4-go/antlr/v4" + + "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" + "github.com/be-thomas/openspl/pkg/parser/spl2/gen" +) + +// newTokenStream runs the generated lexer over src, fills the stream so every +// token is available up front, and applies the invalid-token pass. Lexing the +// whole input before parsing keeps the front-end's priority: a lexical error +// in a later stage beats a syntax error in an earlier one. +func newTokenStream(m *antlrpos.SourceMap, src string) (*antlr.CommonTokenStream, []antlr.Token, error) { + lexer := spl2gen.NewSPL2Lexer(antlr.NewInputStream(src)) + lexer.RemoveErrorListeners() + stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) + stream.Fill() + toks := stream.GetAllTokens() + if err := checkTokens(m, toks, src); err != nil { + return nil, nil, err + } + return stream, toks, nil +} + +// checkTokens reports the first lexically invalid token in source order. +// +// ANTLR's lexer never fails: a character no rule accepts becomes UNKNOWN, a +// numeric literal immediately followed by a letter lexes as a valid number +// plus an identifier, and a number too large for a float64 still lexes as +// NUMBER. All three are lexical errors, reported at the start of the offending +// token before any parsing begins. +func checkTokens(m *antlrpos.SourceMap, toks []antlr.Token, src string) error { + for i, t := range toks { + switch t.GetTokenType() { + case spl2gen.SPL2ParserUNKNOWN: + return invalidCharacter(m, t, src) + case spl2gen.SPL2ParserNUMBER, spl2gen.SPL2ParserDURATION: + // A number outside float64 is invalid, like any other lexical + // error, and is reported before parsing begins. + if t.GetTokenType() == spl2gen.SPL2ParserNUMBER { + if _, err := strconv.ParseFloat(t.GetText(), 64); err != nil { + return diag.NewError(m.Pos(t), "syntax", + "invalid number %q", t.GetText()) + } + } + next := nextToken(toks, i) + if next == nil || next.GetTokenType() == antlr.TokenEOF { + continue + } + if t.GetStop()+1 != next.GetStart() { + continue + } + at := m.ByteOffset(next.GetStart()) + if at >= len(src) || !isLetter(src[at]) { + continue + } + start := m.ByteOffset(t.GetStart()) + // The literal is malformed because a letter-run continues it, so + // quote the whole run rather than the numeric token alone. + end := m.ByteOffset(next.GetStop() + 1) + if end > len(src) { + end = len(src) + } + return diag.NewError(m.Pos(t), "syntax", + "invalid numeric literal %q", src[start:end]) + } + } + return nil +} + +func nextToken(toks []antlr.Token, i int) antlr.Token { + if i+1 < len(toks) { + return toks[i+1] + } + return nil +} + +func invalidCharacter(m *antlrpos.SourceMap, t antlr.Token, src string) error { + at := m.ByteOffset(t.GetStart()) + if at >= len(src) { + return diag.NewError(m.Pos(t), "syntax", "unexpected end of query") + } + r, size := utf8.DecodeRuneInString(src[at:]) + if r == utf8.RuneError && size == 1 { + return diag.NewError(m.Pos(t), "syntax", "unexpected byte 0x%02X", src[at]) + } + return diag.NewError(m.Pos(t), "syntax", "unexpected character %q", string(r)) +} + +func isLetter(b byte) bool { + return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') +} + +// describe names a token the way a diagnostic should, using SPL2 vocabulary. +func describe(t antlr.Token) string { + if t == nil || t.GetTokenType() == antlr.TokenEOF { + return "end of query" + } + switch t.GetTokenType() { + case spl2gen.SPL2ParserIDENT, spl2gen.SPL2ParserFROM, spl2gen.SPL2ParserWHERE, + spl2gen.SPL2ParserSTATS, spl2gen.SPL2ParserBY, spl2gen.SPL2ParserAS, + spl2gen.SPL2ParserAND, spl2gen.SPL2ParserOR, spl2gen.SPL2ParserNOT: + return fmt.Sprintf("identifier %q", t.GetText()) + case spl2gen.SPL2ParserSTRING: + return fmt.Sprintf("string %q", decodeString(t.GetText())) + case spl2gen.SPL2ParserNUMBER: + return fmt.Sprintf("number %q", t.GetText()) + case spl2gen.SPL2ParserDURATION: + return fmt.Sprintf("duration %q", t.GetText()) + } + return fmt.Sprintf("%q", t.GetText()) +} + +// decodeString returns the value of a string literal token: the delimiters are +// dropped and only an escaped delimiter is unescaped. Every other backslash is +// kept so regular expressions survive intact. +func decodeString(raw string) string { + if len(raw) < 2 { + return "" + } + quote := raw[0] + body := raw[1 : len(raw)-1] + out := make([]byte, 0, len(body)) + for i := 0; i < len(body); i++ { + if body[i] == '\\' && i+1 < len(body) && body[i+1] == quote { + out = append(out, quote) + i++ + continue + } + out = append(out, body[i]) + } + return string(out) +} diff --git a/pkg/parser/spl2/spl2.go b/pkg/parser/spl2/spl2.go index d376958..6b883bf 100644 --- a/pkg/parser/spl2/spl2.go +++ b/pkg/parser/spl2/spl2.go @@ -1,22 +1,164 @@ -// Package spl2 is the reserved front-end for Splunk's SPL2 dialect. +// Package spl2 is the front-end for the supported subset of Splunk's SPL2. // -// SPL2 differs from classic SPL in both surface syntax (`from ... | where ...` -// pipelines, typed expressions, `eval` without pipes in some contexts) and -// semantics. Keeping it a separate package prevents classic-SPL quirks from -// leaking into the newer grammar while both lower into pkg/ast. +// The subset is `from` followed by any number of `where` and `stats` stages: // -// The front-end is intentionally not implemented in v0.1.0. Returning a -// positioned, explicit error is better than silently accepting SPL2 with the -// classic grammar and translating it incorrectly. +// from main | where status=500 | stats count() AS count BY host +// +// SPL2 differs from classic SPL in both surface syntax and semantics: a +// pipeline always starts at `from`, a bare word is a field reference even on +// the right of a comparison, and conditions need an explicit `AND`. The +// dialect therefore has its own grammar (grammar/SPL2.g4), generated parser, +// and lowering; it shares only the source map and the error listener with the +// classic front-end, and neither front-end imports the other. +// +// Everything outside the subset is refused with a positioned diagnostic rather +// than approximated: namespaced datasets (a `datamodel:` or any other +// colon-qualified name) cannot become an Elasticsearch index, commands other +// than `from`, `where`, and `stats` are recognized and refused, and a `*` +// inside an expression is a syntax error because the subset has no meaning for +// a wildcard there. package spl2 import ( + "strings" + + "github.com/antlr4-go/antlr/v4" + "github.com/be-thomas/openspl/pkg/ast" "github.com/be-thomas/openspl/pkg/diag" + "github.com/be-thomas/openspl/pkg/parser/commands" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrpos" + "github.com/be-thomas/openspl/pkg/parser/internal/antlrsupport" + "github.com/be-thomas/openspl/pkg/parser/spl2/gen" ) // Parse parses an SPL2 query into the unified IR. -func Parse(src string) (*ast.Pipeline, error) { - return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "spl2-not-implemented", - "the SPL2 front-end is not implemented yet; see docs/ROADMAP.md") +func Parse(src string) (pl *ast.Pipeline, err error) { + if strings.TrimSpace(src) == "" { + return nil, diag.NewError(ast.Pos{Line: 1, Col: 1}, "empty-query", "query is empty") + } + + m := antlrpos.New(src) + stream, toks, err := newTokenStream(m, src) + if err != nil { + return nil, err + } + + parser := spl2gen.NewSPL2Parser(stream) + parser.RemoveErrorListeners() + parser.AddErrorListener(antlrsupport.New(m)) + + b := &builder{m: m, toks: toks, parser: parser} + + // The listener aborts the parse by panicking on the first syntax error; + // any other panic is a bug and is re-raised by Recover. + defer func() { + if r := recover(); r != nil { + if e, ok := antlrsupport.Recover(r, m); ok { + pl, err = nil, e + } + } + }() + return b.pipeline() +} + +// pipeline drives the entry rules one stage at a time. The grammar owns +// dataset names, expressions, and aggregates; the driver owns pipeline shape +// and command classification, because the first stage must be `from` and a +// recognized command has to be refused before it is parsed as something else. +func (b *builder) pipeline() (*ast.Pipeline, error) { + ts := b.parser.GetTokenStream() + cur := ts.LT(1) + + // Unlike classic SPL, a leading pipe is not accepted: the pipeline starts + // at `from`, so any other first token is an error at that token. + if cur.GetTokenType() != spl2gen.SPL2ParserFROM { + return nil, diag.NewError(b.pos(cur), "syntax", + "an SPL2 pipeline must start with 'from'") + } + + pl := &ast.Pipeline{} + for first := true; ; first = false { + stage, end, err := b.stage(first) + if err != nil { + return nil, err + } + pl.Stages = append(pl.Stages, stage) + + // stageEnd is part of every entry rule and was just consumed. The + // stream does not advance past EOF, so the rule context, not LT(-1), + // says whether the stage ended at a pipe. + if end.EOF() != nil { + return pl, nil + } + if ts.LA(1) == antlr.TokenEOF { + return nil, diag.NewError(b.pos(end.PIPE().GetSymbol()), "syntax", + "expected a command after '|'") + } + } +} + +// stage classifies the stage start and parses exactly one stage. +func (b *builder) stage(first bool) (ast.Stage, spl2gen.IStageEndContext, error) { + ts := b.parser.GetTokenStream() + cur := ts.LT(1) + + if isIdentLikeToken(cur.GetTokenType()) { + name := strings.ToLower(cur.GetText()) + if commands.SPL2Implemented(name) { + return b.stageCommand(name, first) + } + if commands.SPL2Known(name) { + return nil, nil, diag.NewError(b.pos(cur), "unsupported-command", + "command %q is recognized but not implemented for SPL2 yet; see docs/COMPATIBILITY.md", name) + } + return nil, nil, diag.NewError(b.pos(cur), "unknown-command", "unknown command %q", name) + } + + // Not a word: let the grammar blame the token. `stageWhere` requires a + // command keyword, so the error lands on this token. + ctx := b.parser.StageWhere() + st, err := b.where(ctx) + return st, ctx.StageEnd(), err +} + +// stageCommand parses one implemented stage. The name comes from the command +// table, so a command added there without a case here is a programming error, +// not a user-visible condition. +func (b *builder) stageCommand(name string, first bool) (ast.Stage, spl2gen.IStageEndContext, error) { + switch name { + case "from": + cur := b.parser.GetTokenStream().LT(1) + if !first { + return nil, nil, diag.NewError(b.pos(cur), "syntax", + "'from' must be the first stage") + } + ctx := b.parser.StageFrom() + st, err := b.from(ctx) + return st, ctx.StageEnd(), err + + case "where": + ctx := b.parser.StageWhere() + st, err := b.where(ctx) + return st, ctx.StageEnd(), err + + case "stats": + ctx := b.parser.StageStats() + st, err := b.stats(ctx) + return st, ctx.StageEnd(), err + } + + pos := b.pos(b.parser.GetTokenStream().LT(1)) + return nil, nil, diag.NewError(pos, "internal", "command %q has no SPL2 grammar rule", name) +} + +// isIdentLikeToken mirrors the grammar's identLike rule for stage dispatch. +func isIdentLikeToken(t int) bool { + switch t { + case spl2gen.SPL2ParserIDENT, spl2gen.SPL2ParserFROM, spl2gen.SPL2ParserWHERE, + spl2gen.SPL2ParserSTATS, spl2gen.SPL2ParserBY, spl2gen.SPL2ParserAS, + spl2gen.SPL2ParserAND, spl2gen.SPL2ParserOR, spl2gen.SPL2ParserNOT: + return true + } + return false } diff --git a/pkg/parser/spl2/spl2_test.go b/pkg/parser/spl2/spl2_test.go index 0d65653..7325080 100644 --- a/pkg/parser/spl2/spl2_test.go +++ b/pkg/parser/spl2/spl2_test.go @@ -3,22 +3,304 @@ package spl2 import ( "testing" + "github.com/be-thomas/openspl/pkg/ast" "github.com/be-thomas/openspl/pkg/diag" ) -func TestParseIsExplicitlyUnsupported(t *testing.T) { - _, err := Parse(`from idx | where status = 500`) - if err == nil { - t.Fatal("expected an error") +func mustParse(t *testing.T, src string) *ast.Pipeline { + t.Helper() + p, err := Parse(src) + if err != nil { + t.Fatalf("Parse(%q) failed: %v", src, err) } - ds, ok := diag.FromError(err) - if !ok || len(ds) == 0 { - t.Fatalf("error is not a diag.Error: %v", err) + return p +} + +func TestParseStages(t *testing.T) { + tests := []struct { + name string + src string + want []string + }{ + {"from only", `from main`, []string{"search"}}, + {"where", `from main | where status=500`, []string{"search", "search"}}, + {"stats", `from main | stats count() AS count BY host`, []string{"search", "stats"}}, + {"full subset", `from main | where status=500 | stats count() AS count BY host`, + []string{"search", "search", "stats"}}, + {"no spaces around pipe", `from main|where status=500|stats count()`, []string{"search", "search", "stats"}}, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + p := mustParse(t, tc.src) + if len(p.Stages) != len(tc.want) { + t.Fatalf("got %d stages, want %d", len(p.Stages), len(tc.want)) + } + for i, want := range tc.want { + if got := p.Stages[i].StageName(); got != want { + t.Errorf("stage %d: got %q, want %q", i, got, want) + } + } + }) + } +} + +// TestFromShape pins the lowering: `from ` becomes the same IR shape +// classic SPL produces for `index=`, so the emitters resolve the +// index through one path. +func TestFromShape(t *testing.T) { + tests := []struct { + name string + src string + dataset string + }{ + {"plain", `from main`, "main"}, + {"hyphenated", `from logs-2024-01`, "logs-2024-01"}, + {"trailing wildcard", `from logs*`, "logs*"}, + {"hyphen and wildcard", `from logs-*`, "logs-*"}, + {"keyword word", `from stats`, "stats"}, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + p := mustParse(t, tc.src) + stage := p.Stages[0].(*ast.SearchStage) + if stage.Pos != (ast.Pos{Line: 1, Col: 1}) { + t.Errorf("stage position = %#v, want 1:1", stage.Pos) + } + b := stage.Expr.(*ast.BinaryExpr) + if b.Op != "=" { + t.Fatalf("operator = %q, want", b.Op) + } + f, ok := b.Left.(*ast.FieldRef) + if !ok || f.Name != "index" || f.Pos != (ast.Pos{Line: 1, Col: 1}) { + t.Fatalf("left side = %#v, want FieldRef index at 1:1", b.Left) + } + s, ok := b.Right.(*ast.StringLit) + if !ok || s.Value != tc.dataset { + t.Fatalf("right side = %#v, want StringLit %q", b.Right, tc.dataset) + } + if s.Pos != (ast.Pos{Line: 1, Col: 6, Offset: 5}) { + t.Errorf("dataset position = %#v, want 1:6", s.Pos) + } + }) } - if ds[0].Code != "spl2-not-implemented" { - t.Fatalf("code = %q", ds[0].Code) +} + +// TestWhereSemantics pins the SPL2 rule that a bare word is a field reference +// everywhere, including on the right of a comparison, and that conditions need +// an explicit AND. +func TestWhereSemantics(t *testing.T) { + t.Run("word on the right is a field reference", func(t *testing.T) { + p := mustParse(t, `from main | where host=web`) + b := p.Stages[1].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + f, ok := b.Right.(*ast.FieldRef) + if !ok || f.Name != "web" { + t.Fatalf("right side = %#v, want FieldRef web", b.Right) + } + }) + + t.Run("number stays a number", func(t *testing.T) { + p := mustParse(t, `from main | where status=500`) + b := p.Stages[1].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + n, ok := b.Right.(*ast.NumberLit) + if !ok || n.Value != 500 { + t.Fatalf("right side = %#v, want NumberLit 500", b.Right) + } + }) + + t.Run("quoted string stays a string", func(t *testing.T) { + p := mustParse(t, `from main | where host="web"`) + b := p.Stages[1].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + if _, ok := b.Right.(*ast.StringLit); !ok { + t.Fatalf("right side = %#v, want StringLit", b.Right) + } + }) + + t.Run("function call", func(t *testing.T) { + p := mustParse(t, `from main | where lower(host)="web"`) + b := p.Stages[1].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + c, ok := b.Left.(*ast.CallExpr) + if !ok || c.Name != "lower" || len(c.Args) != 1 { + t.Fatalf("left side = %#v, want lower(host)", b.Left) + } + if f, ok := c.Args[0].(*ast.FieldRef); !ok || f.Name != "host" { + t.Fatalf("call argument = %#v, want FieldRef host", c.Args[0]) + } + }) + + t.Run("boolean and arithmetic", func(t *testing.T) { + p := mustParse(t, `from main | where (a=1 OR b=2) AND NOT c>-1`) + top := p.Stages[1].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + if top.Op != "and" { + t.Fatalf("top operator = %q, want and", top.Op) + } + if or, ok := top.Left.(*ast.BinaryExpr); !ok || or.Op != "or" { + t.Fatalf("left side = %#v, want or", top.Left) + } + not, ok := top.Right.(*ast.UnaryExpr) + if !ok || not.Op != "not" { + t.Fatalf("right side = %#v, want not", top.Right) + } + cmp, ok := not.Operand.(*ast.BinaryExpr) + if !ok || cmp.Op != ">" { + t.Fatalf("negated operand = %#v, want >", not.Operand) + } + if u, ok := cmp.Right.(*ast.UnaryExpr); !ok || u.Op != "-" { + t.Fatalf("right side = %#v, want unary minus", cmp.Right) + } + }) + + t.Run("bang is not", func(t *testing.T) { + p := mustParse(t, `from main | where !a=1`) + u, ok := p.Stages[1].(*ast.SearchStage).Expr.(*ast.UnaryExpr) + if !ok || u.Op != "not" { + t.Fatalf("expression = %#v, want not", p.Stages[1].(*ast.SearchStage).Expr) + } + }) +} + +func TestStatsAggregates(t *testing.T) { + t.Run("count without an argument", func(t *testing.T) { + p := mustParse(t, `from main | stats count()`) + s := p.Stages[1].(*ast.StatsStage) + if len(s.Aggs) != 1 || s.Aggs[0].Func != "count" || s.Aggs[0].Arg != nil { + t.Fatalf("aggs = %#v, want count with no argument", s.Aggs) + } + }) + + t.Run("argument, alias, and by fields", func(t *testing.T) { + p := mustParse(t, `from main | stats sum(bytes) AS total, dc(host) BY host, user`) + s := p.Stages[1].(*ast.StatsStage) + if len(s.Aggs) != 2 { + t.Fatalf("got %d aggregates, want 2", len(s.Aggs)) + } + if s.Aggs[0].Func != "sum" || s.Aggs[0].Alias != "total" { + t.Errorf("first aggregate = %#v", s.Aggs[0]) + } + if f, ok := s.Aggs[0].Arg.(*ast.FieldRef); !ok || f.Name != "bytes" { + t.Errorf("first argument = %#v, want FieldRef bytes", s.Aggs[0].Arg) + } + if s.Aggs[1].Func != "dc" { + t.Errorf("second aggregate = %#v, want dc", s.Aggs[1]) + } + if len(s.By) != 2 { + t.Fatalf("got %d by fields, want 2", len(s.By)) + } + for i, want := range []string{"host", "user"} { + f, ok := s.By[i].(*ast.FieldRef) + if !ok || f.Name != want { + t.Errorf("by field %d = %#v, want %q", i, s.By[i], want) + } + } + }) + + t.Run("distinct_count normalizes to dc", func(t *testing.T) { + p := mustParse(t, `from main | stats distinct_count(user)`) + s := p.Stages[1].(*ast.StatsStage) + if s.Aggs[0].Func != "dc" { + t.Fatalf("func = %q, want dc", s.Aggs[0].Func) + } + }) +} + +func TestRefusals(t *testing.T) { + tests := []struct { + src string + code string + line int + col int + }{ + {"", "empty-query", 1, 1}, + {" ", "empty-query", 1, 1}, + + // Pipeline shape. + {"| from a", "syntax", 1, 1}, + {"where a=1", "syntax", 1, 1}, + {"main | stats count()", "syntax", 1, 1}, + {"from", "syntax", 1, 5}, + {"from *", "syntax", 1, 6}, + {"from logs *", "syntax", 1, 11}, + {"from a b", "syntax", 1, 8}, + {"from a | from b", "syntax", 1, 10}, + {"from a |", "syntax", 1, 8}, + {"from a || b", "syntax", 1, 9}, + + // Commands outside the subset. + {"from a | eval x=1", "unsupported-command", 1, 10}, + {"from a | sort -x", "unsupported-command", 1, 10}, + {"from a | frobnicate", "unknown-command", 1, 10}, + + // Datasets. + {"from datamodel:events", "unsupported-dataset", 1, 6}, + {"from lookup:foo", "unsupported-dataset", 1, 6}, + {"from DATA:foo", "unsupported-dataset", 1, 6}, + + // Expressions. + {"from a | where status=*", "syntax", 1, 23}, + {"from a | where [x]", "unsupported-subsearch", 1, 16}, + {"from a | where", "syntax", 1, 15}, + {"from a | where a AND", "syntax", 1, 21}, + {"from a | where a b", "syntax", 1, 18}, + {"from a | where =", "syntax", 1, 16}, + {"from a | where (a=1", "syntax", 1, 20}, + {"from a | where status IN (200,500)", "syntax", 1, 23}, + + // Aggregates need the parentheses and a complete list. + {"from a | stats count(*)", "syntax", 1, 22}, + {"from a | stats count", "syntax", 1, 21}, + {"from a | stats count() by", "syntax", 1, 26}, + {"from a | stats count() by host,", "syntax", 1, 32}, + + // Lexical errors win over syntax, wherever they are. + {"from a $ b", "syntax", 1, 8}, + {"from 1x", "syntax", 1, 6}, + {"from a | eval x=$", "syntax", 1, 17}, } - if ds[0].Pos.Line != 1 || ds[0].Pos.Col != 1 { - t.Fatalf("position = %#v", ds[0].Pos) + + for _, tc := range tests { + t.Run(tc.src, func(t *testing.T) { + _, err := Parse(tc.src) + if err == nil { + t.Fatalf("Parse(%q) succeeded, want %s at %d:%d", tc.src, tc.code, tc.line, tc.col) + } + ds, ok := diag.FromError(err) + if !ok || len(ds) == 0 { + t.Fatalf("error is not a *diag.Error: %v", err) + } + d := ds[0] + if d.Code != tc.code || d.Pos.Line != tc.line || d.Pos.Col != tc.col { + t.Fatalf("got %s at %d:%d, want %s at %d:%d (%s)", + d.Code, d.Pos.Line, d.Pos.Col, tc.code, tc.line, tc.col, d.Message) + } + }) } } + +// TestPositions pins byte-based columns after multibyte text and across CRLF. +func TestPositions(t *testing.T) { + t.Run("multibyte string", func(t *testing.T) { + p := mustParse(t, `from m | where host="東京" AND status=500`) + top := p.Stages[1].(*ast.SearchStage).Expr.(*ast.BinaryExpr) + if top.Op != "and" { + t.Fatalf("operator = %q, want and", top.Op) + } + if want := (ast.Pos{Line: 1, Col: 30, Offset: 29}); top.Pos != want { + t.Errorf("AND position = %#v, want %#v", top.Pos, want) + } + right := top.Right.(*ast.BinaryExpr) + if want := (ast.Pos{Line: 1, Col: 34, Offset: 33}); right.Left.Position() != want { + t.Errorf("status position = %#v, want %#v", right.Left.Position(), want) + } + }) + + t.Run("CRLF", func(t *testing.T) { + p := mustParse(t, "from m\r\n| where host=\"東京\" | stats count()") + if want := (ast.Pos{Line: 2, Col: 3, Offset: 10}); p.Stages[1].Position() != want { + t.Errorf("where position = %#v, want %#v", p.Stages[1].Position(), want) + } + if want := (ast.Pos{Line: 2, Col: 25, Offset: 32}); p.Stages[2].Position() != want { + t.Errorf("stats position = %#v, want %#v", p.Stages[2].Position(), want) + } + }) +} diff --git a/scripts/antlr-4.13.2.sha256 b/scripts/antlr-4.13.2.sha256 new file mode 100644 index 0000000..cec1fc1 --- /dev/null +++ b/scripts/antlr-4.13.2.sha256 @@ -0,0 +1 @@ +eae2dfa119a64327444672aff63e9ec35a20180dc5b8090b7a6ab85125df4d76 antlr4-4.13.2-complete.jar diff --git a/scripts/generate-parsers.sh b/scripts/generate-parsers.sh new file mode 100755 index 0000000..6cb6164 --- /dev/null +++ b/scripts/generate-parsers.sh @@ -0,0 +1,93 @@ +#!/bin/sh +# Regenerate the ANTLR Go parsers under pkg/parser/*/gen. +# +# The generated code is committed, so building OpenSPL never needs Java. This +# script is only for changing a grammar. The tool version is pinned by name and +# by SHA-256; a mismatch fails instead of generating from an unknown jar. +set -eu + +cd "$(dirname "$0")/.." + +version=4.13.2 +jar_name="antlr4-${version}-complete.jar" +checksum_file="scripts/antlr-${version}.sha256" + +sha256() { + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "$1" | awk '{print $1}' + else + shasum -a 256 "$1" | awk '{print $1}' + fi +} + +# 1. Locate the pinned jar, downloading it once into the user cache. +if [ -n "${ANTLR_JAR:-}" ]; then + jar="$ANTLR_JAR" +else + cache="${XDG_CACHE_HOME:-$HOME/.cache}/openspl" + jar="$cache/$jar_name" + if [ ! -f "$jar" ]; then + mkdir -p "$cache" + url="https://repo1.maven.org/maven2/org/antlr/antlr4/${version}/${jar_name}" + echo "downloading $url" + if ! curl -fsSL -o "$jar.tmp" "$url"; then + rm -f "$jar.tmp" + echo "error: could not download the ANTLR jar" >&2 + exit 1 + fi + mv "$jar.tmp" "$jar" + fi +fi + +# 2. Verify it. A mismatch deletes a cached download so the next run retries. +expected=$(awk 'NR == 1 {print $1}' "$checksum_file") +actual=$(sha256 "$jar") +if [ "$expected" != "$actual" ]; then + echo "error: $jar has sha256 $actual, want $expected" >&2 + if [ -z "${ANTLR_JAR:-}" ]; then + rm -f "$jar" + fi + exit 1 +fi + +# 3. Java 17 or newer is required by ANTLR 4.13.2. +if ! command -v java >/dev/null 2>&1; then + echo "error: java not found; ANTLR 4.13.2 needs Java 17 or newer" >&2 + exit 1 +fi +major=$(java -version 2>&1 | sed -n '1s/.*version "\([0-9][0-9]*\).*/\1/p') +if [ -z "$major" ] || [ "$major" -lt 17 ]; then + echo "error: java $major found; ANTLR 4.13.2 needs Java 17 or newer" >&2 + exit 1 +fi + +# 4. Generate each grammar into its own package. +generate() { + dir=$1 + name=$2 + pkg=$3 + grammar="pkg/parser/$dir/grammar/$name.g4" + out="pkg/parser/$dir/gen" + + if [ ! -f "$grammar" ]; then + echo "skipping missing $grammar" + return 0 + fi + + echo "generating $grammar -> $out" + mkdir -p "$out" + java -jar "$jar" \ + -Dlanguage=Go -visitor -no-listener \ + -package "$pkg" -Xexact-output-dir \ + -o "$out" "$grammar" + + # The runtime reads the serialized ATN embedded in the Go files; the + # token and interpreter dumps are generation byproducts. + rm -f "$out"/*.interp "$out"/*.tokens + gofmt -w "$out" +} + +generate spl1 SPL1 spl1gen +generate spl2 SPL2 spl2gen + +echo "generated parsers; run make generate-check to confirm no drift"