Skip to content

fix: support @Module.Const syntax in expressions#179

Open
engalar wants to merge 3 commits intomendixlabs:mainfrom
engalar:fix/issue-178-constant-ref-roundtrip
Open

fix: support @Module.Const syntax in expressions#179
engalar wants to merge 3 commits intomendixlabs:mainfrom
engalar:fix/issue-178-constant-ref-roundtrip

Conversation

@engalar
Copy link
Copy Markdown
Contributor

@engalar engalar commented Apr 10, 2026

Fixes #178

Summary

  • Added @QualifiedName as a valid atomicExpression in the MDL grammar for constant references
  • New ConstantRefExpr AST node type for clean representation
  • Visitor converts @ Module.Const parse tree to ConstantRefExpr
  • expressionToString() outputs @Module.Const for BSON serialization
  • Backward compatible: getConstantValue('Module.Const') still works

Round-trip restored

-- DESCRIBE outputs:
DECLARE $val String = @MyModule.MyConstant;

-- Can now be fed back into CREATE without modification ✓

Test plan

  • mxcli check accepts @Module.Const syntax
  • mxcli check still accepts getConstantValue('Module.Const') syntax
  • Full test suite passes
  • Build succeeds

This was referenced Apr 10, 2026
Copy link
Copy Markdown
Collaborator

@ako ako left a comment

Choose a reason for hiding this comment

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

Surgical, minimal fix that restores DESCRIBE roundtrip for microflows referencing constants.

What's good

  • Full-stack change in 5 files: 1 grammar line, 1 AST type, 1 visitor case, 2 formatter cases
  • Backward compatible — getConstantValue('Mod.Const') still works
  • Reuses existing AT token (no lexer changes)

Concerns

Potential parser ambiguity with @annotation. The grammar already uses AT IDENTIFIER for annotations like @Documentation. Adding AT qualifiedName to atomicExpression should be fine since contexts don't overlap (annotations are statement-level, expressions are body-level), but a test confirming this would close the gap.

No regression tests. The PR's main value is DESCRIBE roundtrip but there's no test verifying parse → describe → re-parse for a microflow with @Module.Const. A doctype-test entry would prevent regression.

Two expressionToString functions in different files both got the new case. This kind of duplication is a maintenance hazard but outside the scope of this PR.

QualifiedNameExpr change in cmd_diff_mdl.go is unrelated to the constant reference fix — looks like a separate bug being piggybacked. Should be its own commit ideally.

LGTM.

@engalar engalar force-pushed the fix/issue-178-constant-ref-roundtrip branch from ef1cdde to 2410f33 Compare April 13, 2026 05:07
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

  1. Incomplete LSP/W Code extension wiring: The PR adds new expression syntax (@Module.Const) but doesn't show changes to:

    • cmd/mxcli/lsp.go for LSP support (hover, go-to-definition, diagnostics)
    • vscode-mdl/package.json if new LSP capabilities were added
      Expression syntax typically requires LSP support for proper IDE integration.
  2. Truncated diff obscures verification: The diff appears cut off, preventing verification of:

    • Visitor implementation changes (mentioned in PR description but not visible)
    • Whether doctest examples were added/updated for the new syntax
    • Any other related implementation details

Minor Issues

  1. Generated parser file commit: The diff shows changes to MDLParser.interp (generated file). While this indicates make grammar was run, generated parser files should typically not be committed directly - either regenerate in CI or explicitly note the regeneration.

What Looks Good

  • Clean, focused implementation following existing patterns
  • Proper backward compatibility maintained with getConstantValue('Module.Const')
  • Clear DESCRIBE round-trip capability demonstrated (DECLARE $val String = @MyModule.MyConstant;)
  • Follows MDL syntax design guidelines:
    • Uses qualified names (Module.Element)
    • Reads as English (citizen developer friendly)
    • Uses @ specifically for constant references (no keyword overloading)
    • Minimal, focused changes
  • Test plan items verified:
    • mxcli check accepts new syntax
    • Backward compatibility maintained
    • Full test suite passes
    • Build succeeds

Recommendation

Request changes to verify full-stack consistency:

  1. Please provide the missing visitor implementation changes (likely in truncated diff)
  2. Confirm LSP support was added for the new syntax in cmd/mxcli/lsp.go
  3. Confirm VS Code extension was updated if LSP capabilities changed
  4. Verify doctest examples were added to 09-constant-examples.mdl
  5. Consider whether generated parser files should be committed (prefer regenerating in CI)

Once these are verified, the PR is ready for approval as it correctly implements the feature following all architectural guidelines.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

engalar and others added 3 commits April 13, 2026 14:32
Parser now accepts @QualifiedName as a constant reference in any
expression context (DECLARE, SET, CHANGE, etc.), matching the output
of DESCRIBE MICROFLOW. This restores the round-trip guarantee:
DESCRIBE output can be fed back into CREATE without modification.
…oString

The Executor.expressionToString method in cmd_diff_mdl.go was missing
cases for ConstantRefExpr and QualifiedNameExpr, causing mxcli diff to
output Go struct formatting instead of valid MDL syntax.
Adds regression coverage for the parse→check roundtrip of constant
references using @Module.Const syntax in microflow DECLARE statements
and compound expressions. Addresses review feedback on PR mendixlabs#179.
@engalar engalar force-pushed the fix/issue-178-constant-ref-roundtrip branch from 2410f33 to 4f92da2 Compare April 13, 2026 06:40
@github-actions
Copy link
Copy Markdown

AI Code Review

What Looks Good

  • The PR correctly implements the full MDL pipeline: grammar → AST → visitor → executor → DESCRIBE roundtrip
  • Backward compatibility is maintained with existing getConstantValue('Module.Const') syntax
  • Test cases are properly added to 09-constant-examples.mdl showing usage in microflow expressions
  • The roundtrip functionality works as demonstrated (DESCRIBE outputs @Module.Const which can be re-parsed)
  • Code changes are minimal and focused on the specific feature
  • ExpressionToString handling is consistent across both microflows helpers and diff command

Recommendation

Approve - The PR properly implements the requested @Module.Const syntax following all required patterns and guidelines. The feature is complete, tested, and maintains backward compatibility.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

@engalar engalar requested a review from ako April 13, 2026 06:42
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.

Constant reference round-trip broken: DESCRIBE outputs @Module.Const but parser rejects @ syntax

2 participants