Skip to content

Commit f313c9b

Browse files
akoclaude
andcommitted
fix: allow reserved keywords as business event message/attribute names (issue #476)
businessEventMessageDef and businessEventAttrDef both used IDENTIFIER, which rejects any token that is also a reserved keyword (Date, Amount, Timestamp, etc.) — common attribute names in real domain models. Changed both rules to identifierOrKeyword and updated the visitor to read the name via identifierOrKeywordText(). Regenerated ANTLR parser. Added regression test TestBusinessEvent_KeywordAttributeNames to prevent recurrence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ea6cc64 commit f313c9b

5 files changed

Lines changed: 65 additions & 30 deletions

File tree

mdl/executor/bugfix_regression_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,3 +870,22 @@ func TestValidateMicroflowReferencesReportsIncludedMissingMicroflow(t *testing.T
870870
t.Fatalf("unexpected validation error: %v", err)
871871
}
872872
}
873+
874+
// =============================================================================
875+
// Issue #476: Business event MESSAGE attribute names reject reserved keywords
876+
// =============================================================================
877+
878+
// TestBusinessEvent_KeywordAttributeNames verifies that reserved keywords (Date,
879+
// Amount, etc.) are accepted as MESSAGE attribute names and message names.
880+
func TestBusinessEvent_KeywordAttributeNames(t *testing.T) {
881+
input := `CREATE BUSINESS EVENT SERVICE MyModule.Events
882+
(ServiceName: 'Svc', EventNamePrefix: 'com.test')
883+
{
884+
MESSAGE OrderCreated (Date: DateTime, Amount: Decimal) PUBLISH ENTITY MyModule.Order;
885+
};`
886+
887+
_, errs := visitor.Build(input)
888+
if len(errs) > 0 {
889+
t.Fatalf("issue #476: keyword attribute names rejected: %v", errs[0])
890+
}
891+
}

mdl/grammar/MDLParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,7 +2874,7 @@ createBusinessEventServiceStatement
28742874
;
28752875

28762876
businessEventMessageDef
2877-
: MESSAGE IDENTIFIER
2877+
: MESSAGE identifierOrKeyword
28782878
LPAREN businessEventAttrDef (COMMA businessEventAttrDef)* RPAREN
28792879
(PUBLISH | SUBSCRIBE)
28802880
(ENTITY qualifiedName)?
@@ -2883,7 +2883,7 @@ businessEventMessageDef
28832883
;
28842884

28852885
businessEventAttrDef
2886-
: IDENTIFIER COLON dataType
2886+
: identifierOrKeyword COLON dataType
28872887
;
28882888

28892889
// =============================================================================

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: 39 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdl/visitor/visitor_businessevents.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func (b *Builder) ExitCreateBusinessEventServiceStatement(ctx *parser.CreateBusi
3939
}
4040

4141
msg := &ast.BusinessEventMessageDef{}
42-
if id := msgDef.IDENTIFIER(); id != nil {
43-
msg.MessageName = id.GetText()
42+
if iok := msgDef.IdentifierOrKeyword(); iok != nil {
43+
msg.MessageName = identifierOrKeywordText(iok)
4444
}
4545

4646
// Parse operation (PUBLISH or SUBSCRIBE)
@@ -71,8 +71,8 @@ func (b *Builder) ExitCreateBusinessEventServiceStatement(ctx *parser.CreateBusi
7171
attr := &ast.BusinessEventAttributeDef{
7272
TypeName: dataTypeSimpleName(attrDef.DataType()),
7373
}
74-
if id := attrDef.IDENTIFIER(); id != nil {
75-
attr.Name = id.GetText()
74+
if iok := attrDef.IdentifierOrKeyword(); iok != nil {
75+
attr.Name = identifierOrKeywordText(iok)
7676
}
7777
msg.Attributes = append(msg.Attributes, attr)
7878
}

0 commit comments

Comments
 (0)