Skip to content

A5 - Remove PRECONDITION_ELEMENT token and collapse into varRef#58

Merged
ruizmaa merged 3 commits into
cr-48/grammar-docs-consistencyfrom
a5
May 25, 2026
Merged

A5 - Remove PRECONDITION_ELEMENT token and collapse into varRef#58
ruizmaa merged 3 commits into
cr-48/grammar-docs-consistencyfrom
a5

Conversation

@ruizmaa
Copy link
Copy Markdown
Contributor

@ruizmaa ruizmaa commented May 15, 2026

Closes #52

Summary

PRECONDITION_ELEMENT was an undocumented lexer token for v_xxx forms that duplicated the shape of varRef. The fix removes it and extends VAR_REFERENCE to cover both forms, routing everything through the existing varRef rule.

  • Removed PRECONDITION_PREFIX fragment and PRECONDITION_ELEMENT token from dpm_xlLexer.g4
  • Extended VAR_REFERENCE to match both vVAR_CODE and v_TABLE_CODE forms: VAR_REF_PREFIX (VAR_CODE | '_' TABLE_CODE)
  • Removed the preconditionElem alternative from selectOperand in dpm_xlParser.g4 and deleted the preconditionElem rule
  • Updated visitVarRef in constructor.py to detect the v_ prefix and return a PreconditionItem node (same node as before); removed the now-redundant visitPreconditionElem method
  • Regenerated all files under grammar/generated/ using ANTLR 4.9.2 (antlr4 -Dlanguage=Python3 -visitor)

The AST output is unchanged: {v_Z101} still produces PreconditionItem(variable_id='Z101', variable_code='Z101'), so all downstream code (semantic analyser, ML generation, operands) requires no modifications.

Tests

Unit tests were added in tests/unit/ast/test_precondition_elem.py:

  • test_valid_precondition_elem — parametrized over {v_Z101}, {v_SomeTable}, {v_A} (single-letter code), and {v_Some-Table} (hyphen in code, exercising the TABLE_CODE vs VAR_CODE difference); verifies all are accepted by the parser
  • test_precondition_elem_produces_precondition_item — same inputs; verifies each produces a PreconditionItem with the correct variable_id and variable_code
  • test_regular_var_ref{vMyVar} continues to produce a VarRef node, confirming no regression in the normal variable reference path
  • test_invalid_precondition_forms_are_rejected — parametrized over four invalid forms: bare {v_} (no code), {v_123} (digit-initial code), {v_Z101} as the head of a with-clause (not a valid cell ref), and {v_Z101} <- 1 (precondition element cannot be the LHS of a persistent assignment)

Checklist

  • Code quality checks pass (ruff format, ruff check, mypy)
  • Tests pass (pytest) with 100% branch coverage (coverage report --fail-under=100)
  • Documentation updated (if applicable)

Impact / Risk

  • Breaking changes? (public API / CLI / REST endpoints / Django models)
  • Database schema or migration concerns?
  • Notes for release/changelog?

Notes

@ruizmaa ruizmaa self-assigned this May 15, 2026
@ruizmaa ruizmaa linked an issue May 15, 2026 that may be closed by this pull request
@ruizmaa ruizmaa marked this pull request as ready for review May 15, 2026 11:13
@ruizmaa ruizmaa requested a review from a team May 15, 2026 11:14
Copy link
Copy Markdown
Contributor

@javihern98 javihern98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! 😊

@ruizmaa ruizmaa merged commit c35fc93 into cr-48/grammar-docs-consistency May 25, 2026
@ruizmaa ruizmaa deleted the a5 branch May 25, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A5 - Remove PRECONDITION_ELEMENT token and collapse into varRef

2 participants