Skip to content

Commit 7664f23

Browse files
authored
Merge pull request #179 from engalar/fix/issue-178-constant-ref-roundtrip
fix: support @Module.Const syntax in expressions
2 parents af10890 + 849d249 commit 7664f23

File tree

8 files changed

+579
-507
lines changed

8 files changed

+579
-507
lines changed

mdl-examples/doctype-tests/09-constant-examples.mdl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,34 @@ DEFAULT true;
150150
DROP CONSTANT CoTest.LaunchDate;
151151
/
152152

153+
-- MARK: - Constants in Microflow Expressions (regression: issue #178)
154+
155+
/**
156+
* Level 5.1: Use @Module.Const in a microflow DECLARE
157+
* Tests that `@Module.Const` syntax parses and round-trips correctly.
158+
* Regression test for: DESCRIBE → re-parse roundtrip with @-style constant refs.
159+
*/
160+
CREATE OR REPLACE MICROFLOW CoTest.UseConstantRef ()
161+
RETURNS Nothing
162+
BEGIN
163+
DECLARE $Endpoint String = @CoTest.ServiceEndpoint;
164+
DECLARE $Retries Integer = @CoTest.MaxRetries;
165+
DECLARE $IsTaxable Boolean = @CoTest.EnableDebugLogging;
166+
END;
167+
/
168+
169+
/**
170+
* Level 5.2: Mix @Module.Const with other expressions
171+
* Confirms constant references work in compound expressions alongside literals.
172+
*/
173+
CREATE OR REPLACE MICROFLOW CoTest.MixedConstantExpressions ()
174+
RETURNS Nothing
175+
BEGIN
176+
DECLARE $Limit Decimal = @CoTest.TaxRate + 0.05;
177+
DECLARE $Msg String = 'Endpoint: ' + @CoTest.ServiceEndpoint;
178+
END;
179+
/
180+
153181
-- ############################################################################
154182
-- END OF CONSTANT EXAMPLES
155183
-- ############################################################################

mdl/ast/ast_expression.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ type QualifiedNameExpr struct {
108108

109109
func (e *QualifiedNameExpr) isExpression() {}
110110

111+
// ConstantRefExpr represents a constant reference: @Module.ConstantName
112+
type ConstantRefExpr struct {
113+
QualifiedName QualifiedName // The constant qualified name
114+
}
115+
116+
func (e *ConstantRefExpr) isExpression() {}
117+
111118
// IfThenElseExpr represents an inline if-then-else expression:
112119
// if condition then trueExpr else falseExpr
113120
type IfThenElseExpr struct {

mdl/executor/cmd_diff_mdl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ func (e *Executor) expressionToString(expr ast.Expression) string {
701701
return fmt.Sprintf("[%%%s%%]", ex.Token)
702702
case *ast.ParenExpr:
703703
return fmt.Sprintf("(%s)", e.expressionToString(ex.Inner))
704+
case *ast.QualifiedNameExpr:
705+
return ex.QualifiedName.String()
706+
case *ast.ConstantRefExpr:
707+
return "@" + ex.QualifiedName.String()
704708
default:
705709
return fmt.Sprintf("%v", expr)
706710
}

mdl/executor/cmd_microflows_helpers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ func expressionToString(expr ast.Expression) string {
130130
case *ast.QualifiedNameExpr:
131131
// Qualified name (association name, entity reference) - unquoted
132132
return e.QualifiedName.String()
133+
case *ast.ConstantRefExpr:
134+
return "@" + e.QualifiedName.String()
133135
case *ast.IfThenElseExpr:
134136
cond := expressionToString(e.Condition)
135137
thenStr := expressionToString(e.ThenExpr)

mdl/grammar/MDLParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,6 +3517,7 @@ argumentList
35173517
atomicExpression
35183518
: literal
35193519
| VARIABLE (DOT attributeName)* // $Var or $Widget.Attribute (data source ref)
3520+
| AT qualifiedName // @Module.ConstantName (constant reference)
35203521
| qualifiedName
35213522
| IDENTIFIER
35223523
| MENDIX_TOKEN

mdl/grammar/parser/MDLParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

mdl/grammar/parser/mdl_parser.go

Lines changed: 527 additions & 506 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdl/visitor/visitor_microflow_expression.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,15 @@ func buildAtomicExpression(ctx parser.IAtomicExpressionContext) ast.Expression {
617617
}
618618
}
619619

620+
// Constant reference: @Module.ConstantName
621+
if atomCtx.AT() != nil {
622+
if qn := atomCtx.QualifiedName(); qn != nil {
623+
return &ast.ConstantRefExpr{
624+
QualifiedName: buildQualifiedName(qn),
625+
}
626+
}
627+
}
628+
620629
// Mendix token [%TokenName%]
621630
if token := atomCtx.MENDIX_TOKEN(); token != nil {
622631
tokenText := token.GetText()

0 commit comments

Comments
 (0)