Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mdl-examples/doctype-tests/09-constant-examples.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,34 @@ DEFAULT true;
DROP CONSTANT CoTest.LaunchDate;
/

-- MARK: - Constants in Microflow Expressions (regression: issue #178)

/**
* Level 5.1: Use @Module.Const in a microflow DECLARE
* Tests that `@Module.Const` syntax parses and round-trips correctly.
* Regression test for: DESCRIBE → re-parse roundtrip with @-style constant refs.
*/
CREATE OR REPLACE MICROFLOW CoTest.UseConstantRef ()
RETURNS Nothing
BEGIN
DECLARE $Endpoint String = @CoTest.ServiceEndpoint;
DECLARE $Retries Integer = @CoTest.MaxRetries;
DECLARE $IsTaxable Boolean = @CoTest.EnableDebugLogging;
END;
/

/**
* Level 5.2: Mix @Module.Const with other expressions
* Confirms constant references work in compound expressions alongside literals.
*/
CREATE OR REPLACE MICROFLOW CoTest.MixedConstantExpressions ()
RETURNS Nothing
BEGIN
DECLARE $Limit Decimal = @CoTest.TaxRate + 0.05;
DECLARE $Msg String = 'Endpoint: ' + @CoTest.ServiceEndpoint;
END;
/

-- ############################################################################
-- END OF CONSTANT EXAMPLES
-- ############################################################################
7 changes: 7 additions & 0 deletions mdl/ast/ast_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ type QualifiedNameExpr struct {

func (e *QualifiedNameExpr) isExpression() {}

// ConstantRefExpr represents a constant reference: @Module.ConstantName
type ConstantRefExpr struct {
QualifiedName QualifiedName // The constant qualified name
}

func (e *ConstantRefExpr) isExpression() {}

// IfThenElseExpr represents an inline if-then-else expression:
// if condition then trueExpr else falseExpr
type IfThenElseExpr struct {
Expand Down
4 changes: 4 additions & 0 deletions mdl/executor/cmd_diff_mdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ func (e *Executor) expressionToString(expr ast.Expression) string {
return fmt.Sprintf("[%%%s%%]", ex.Token)
case *ast.ParenExpr:
return fmt.Sprintf("(%s)", e.expressionToString(ex.Inner))
case *ast.QualifiedNameExpr:
return ex.QualifiedName.String()
case *ast.ConstantRefExpr:
return "@" + ex.QualifiedName.String()
default:
return fmt.Sprintf("%v", expr)
}
Expand Down
2 changes: 2 additions & 0 deletions mdl/executor/cmd_microflows_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func expressionToString(expr ast.Expression) string {
case *ast.QualifiedNameExpr:
// Qualified name (association name, entity reference) - unquoted
return e.QualifiedName.String()
case *ast.ConstantRefExpr:
return "@" + e.QualifiedName.String()
case *ast.IfThenElseExpr:
cond := expressionToString(e.Condition)
thenStr := expressionToString(e.ThenExpr)
Expand Down
1 change: 1 addition & 0 deletions mdl/grammar/MDLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -3495,6 +3495,7 @@ argumentList
atomicExpression
: literal
| VARIABLE (DOT attributeName)* // $Var or $Widget.Attribute (data source ref)
| AT qualifiedName // @Module.ConstantName (constant reference)
| qualifiedName
| IDENTIFIER
| MENDIX_TOKEN
Expand Down
2 changes: 1 addition & 1 deletion mdl/grammar/parser/MDLParser.interp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mdl/grammar/parser/mdl_lexer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,113 changes: 567 additions & 546 deletions mdl/grammar/parser/mdl_parser.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mdl/grammar/parser/mdlparser_base_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mdl/grammar/parser/mdlparser_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions mdl/visitor/visitor_microflow_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,15 @@ func buildAtomicExpression(ctx parser.IAtomicExpressionContext) ast.Expression {
}
}

// Constant reference: @Module.ConstantName
if atomCtx.AT() != nil {
if qn := atomCtx.QualifiedName(); qn != nil {
return &ast.ConstantRefExpr{
QualifiedName: buildQualifiedName(qn),
}
}
}

// Mendix token [%TokenName%]
if token := atomCtx.MENDIX_TOKEN(); token != nil {
tokenText := token.GetText()
Expand Down
Loading