A5 - Remove PRECONDITION_ELEMENT token and collapse into varRef#58
Merged
Conversation
javihern98
approved these changes
May 25, 2026
Contributor
javihern98
left a comment
There was a problem hiding this comment.
Looks good, thanks! 😊
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52
Summary
PRECONDITION_ELEMENTwas an undocumented lexer token forv_xxxforms that duplicated the shape ofvarRef. The fix removes it and extendsVAR_REFERENCEto cover both forms, routing everything through the existingvarRefrule.PRECONDITION_PREFIXfragment andPRECONDITION_ELEMENTtoken fromdpm_xlLexer.g4VAR_REFERENCEto match bothvVAR_CODEandv_TABLE_CODEforms:VAR_REF_PREFIX (VAR_CODE | '_' TABLE_CODE)preconditionElemalternative fromselectOperandindpm_xlParser.g4and deleted thepreconditionElemrulevisitVarRefinconstructor.pyto detect thev_prefix and return aPreconditionItemnode (same node as before); removed the now-redundantvisitPreconditionElemmethodgrammar/generated/using ANTLR 4.9.2 (antlr4 -Dlanguage=Python3 -visitor)The AST output is unchanged:
{v_Z101}still producesPreconditionItem(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 theTABLE_CODEvsVAR_CODEdifference); verifies all are accepted by the parsertest_precondition_elem_produces_precondition_item— same inputs; verifies each produces aPreconditionItemwith the correctvariable_idandvariable_codetest_regular_var_ref—{vMyVar}continues to produce aVarRefnode, confirming no regression in the normal variable reference pathtest_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 awith-clause (not a valid cell ref), and{v_Z101} <- 1(precondition element cannot be the LHS of a persistent assignment)Checklist
ruff format,ruff check,mypy)pytest) with 100% branch coverage (coverage report --fail-under=100)Impact / Risk
Notes