Skip to content

feat(grammar): add ANTLR4 grammar for OSSIE_SQL_2026 expressions - #657

Open
j0hannesz wants to merge 3 commits into
apache:mainfrom
j0hannesz:feat/antlr4-expression-grammar
Open

j0hannesz wants to merge 3 commits into
apache:mainfrom
j0hannesz:feat/antlr4-expression-grammar

Conversation

@j0hannesz

Copy link
Copy Markdown

Summary

Adds an ANTLR 4 reference grammar for the OSSIE_SQL_2026 expression language.

  • core-spec/grammar/OssieExpression.g4 is the grammar.
  • compliance/expressions/valid.txt and invalid.txt are language-neutral conformance fixtures (one expression per line), so any parser can run them.
  • core-spec/grammar/tests/ has a pytest runner. It generates the Python parser, runs both fixture files, parses every ANSI_SQL / OSSIE_SQL_2026 expression in examples/*.yaml, and pins operator precedence on the parse tree.
  • .github/workflows/grammar-ci.yml runs the tests (Python 3.11 and 3.14).
  • core-spec/expression_language.md gets a short pointer to the grammar at the end. The spec stays normative; where the two differ, the spec wins.

Layout and approach follow JB's review.

Open points for the spec (not decided here)

  • || precedence: the grammar parses it at the level of + and -, so a || b + c is (a || b) + c. sqlglot and PostgreSQL parse it as a || (b + c).
  • Identifiers: the grammar is ASCII-only and allows $.
  • LIKE ... ESCAPE is not supported, as the spec does not mention it.
  • Comparisons do not chain (a = b = c needs parentheses).

The grammar follows whatever the spec decides on these.

Dependencies

No new runtime dependency. The tests use the ANTLR 4.13.2 tool (downloaded from Maven Central into the git-ignored dev/lib/, verified against a pinned SHA-256) and antlr4-python3-runtime 4.13.2, both BSD-3-Clause (ASF Category A), plus pytest and pyyaml.

Related Issues

https://lists.apache.org/thread/s5x6lo5gvxhyowb4pcohtplnly5rmgtm

Supported by Jean-Baptiste Onofré.

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure
  • Spec changes have been discussed on the mailing list or in a linked issue
  • Breaking changes to the spec are clearly called out in the summary

Ontology

  • Ontology changes in ontology/ are consistent with spec changes
  • New or modified terms are defined and documented

Converters

Validation

  • Validation rules in validation/ are updated if the spec changed
  • New validation cases are covered by tests

Documentation

  • docs/ is updated to reflect any user-facing changes
  • New features or behaviors are documented with examples where appropriate
  • CONTRIBUTING.md is updated if the contribution process changed

Examples

  • examples/ are added or updated for any new spec constructs

Tests

  • All existing tests pass (pytest / CI green)
  • New functionality is covered by tests

Compliance

  • ASF license headers are present on all new source files
  • No third-party dependencies are added without PMC/IPMC approval
  • If third-party source code is vendored/copied (not just declared as a dependency), NOTICE and/or LICENSE have been updated per ASF policy

Johannes Zemlin and others added 3 commits October 27, 2026 21:56
Add grammar/OssieExpression.g4, an ANTLR 4 grammar for the expression
language in core-spec/expression_language.md, with Python tests that
parse valid/invalid fixtures, the expressions in examples/, and check
operator precedence. Add a grammar CI workflow, a README, a label rule,
an .editorconfig rule for .g4 files, and a pointer from the spec.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Move the ANTLR grammar next to the spec (core-spec/grammar/) and the
valid/invalid expression fixtures to compliance/expressions/ so any parser
can run them. Require at least one argument after DISTINCT in function
calls, and add SUM(DISTINCT) and COUNT(DISTINCT) to the invalid fixtures.
Drop the stale NOT precedence note from the grammar header, update CI
paths, labels and links, and ignore generated ANTLR output.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thank you for your first contribution to Apache Ossie (incubating)!

A committer will review your PR. In the meantime, please ensure:

  • All CI checks pass
  • ASF license headers are present on new source files
  • Tests cover new functionality

No ICLA is required to contribute. If you are elected as a committer in the future, you will need an Individual Contributor License Agreement (ICLA) on file with the ASF.

Questions? Ask in the PR comments or join us on Slack.

We appreciate your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant