-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMDLParser.g4
More file actions
3734 lines (3265 loc) · 112 KB
/
MDLParser.g4
File metadata and controls
3734 lines (3265 loc) · 112 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* MDL (Mendix Definition Language) Parser Grammar
*
* ANTLR4 parser for MDL syntax used by the Mendix REPL.
* Converted from Chevrotain-based parser.
*/
parser grammar MDLParser;
options {
tokenVocab = MDLLexer;
}
// =============================================================================
// TOP-LEVEL RULES
// =============================================================================
/** Entry point: a program is a sequence of statements */
program
: statement* EOF
;
/** A statement can be DDL, DQL, or utility */
statement
: docComment? (ddlStatement | dqlStatement | utilityStatement) SEMICOLON? SLASH?
;
// =============================================================================
// DDL STATEMENTS (Data Definition Language)
// =============================================================================
ddlStatement
: createStatement
| alterStatement
| dropStatement
| renameStatement
| moveStatement
| updateWidgetsStatement
| securityStatement
;
/**
* Bulk update widget properties across pages/snippets.
*
* @example Preview changes (dry run)
* ```mdl
* UPDATE WIDGETS
* SET 'showLabel' = false
* WHERE WidgetType LIKE '%combobox%'
* DRY RUN;
* ```
*
* @example Apply changes to widgets in a module
* ```mdl
* UPDATE WIDGETS
* SET 'filterMode' = 'contains'
* WHERE WidgetType LIKE '%DataGrid%'
* IN MyModule;
* ```
*
* @example Multiple property assignments
* ```mdl
* UPDATE WIDGETS
* SET 'showLabel' = false, 'labelWidth' = 4
* WHERE WidgetType LIKE '%textbox%';
* ```
*/
updateWidgetsStatement
: UPDATE WIDGETS
SET widgetPropertyAssignment (COMMA widgetPropertyAssignment)*
WHERE widgetCondition (AND widgetCondition)*
(IN (qualifiedName | IDENTIFIER))?
(DRY RUN)?
;
createStatement
: docComment? annotation*
CREATE (OR (MODIFY | REPLACE))?
( createEntityStatement
| createAssociationStatement
| createModuleStatement
| createMicroflowStatement
| createJavaActionStatement
| createPageStatement
| createSnippetStatement
| createEnumerationStatement
| createValidationRuleStatement
| createNotebookStatement
| createDatabaseConnectionStatement
| createConstantStatement
| createRestClientStatement
| createIndexStatement
| createODataClientStatement
| createODataServiceStatement
| createExternalEntityStatement
| createExternalEntitiesStatement
| createNavigationStatement
| createBusinessEventServiceStatement
| createWorkflowStatement
| createUserRoleStatement
| createDemoUserStatement
| createImageCollectionStatement
| createJsonStructureStatement
| createImportMappingStatement
| createExportMappingStatement
| createConfigurationStatement
| createPublishedRestServiceStatement
)
;
alterStatement
: ALTER ENTITY qualifiedName alterEntityAction+
| ALTER ASSOCIATION qualifiedName alterAssociationAction+
| ALTER ENUMERATION qualifiedName alterEnumerationAction+
| ALTER NOTEBOOK qualifiedName alterNotebookAction+
| ALTER ODATA CLIENT qualifiedName SET odataAlterAssignment (COMMA odataAlterAssignment)*
| ALTER ODATA SERVICE qualifiedName SET odataAlterAssignment (COMMA odataAlterAssignment)*
| ALTER STYLING ON (PAGE | SNIPPET) qualifiedName WIDGET IDENTIFIER alterStylingAction+
| ALTER SETTINGS alterSettingsClause
| ALTER PAGE qualifiedName LBRACE alterPageOperation+ RBRACE
| ALTER SNIPPET qualifiedName LBRACE alterPageOperation+ RBRACE
| ALTER WORKFLOW qualifiedName alterWorkflowAction+ SEMICOLON?
| ALTER PUBLISHED REST SERVICE qualifiedName alterPublishedRestServiceAction (COMMA? alterPublishedRestServiceAction)*
;
alterPublishedRestServiceAction
: SET publishedRestAlterAssignment (COMMA publishedRestAlterAssignment)*
| ADD publishedRestResource
| DROP RESOURCE STRING_LITERAL
;
publishedRestAlterAssignment
: identifierOrKeyword EQUALS STRING_LITERAL
;
/**
* Styling modification actions for ALTER STYLING.
*
* @example Set Class and Style
* ```mdl
* ALTER STYLING ON PAGE MyModule.Page WIDGET btnSave
* SET Class = 'btn-lg', Style = 'margin-top: 8px;';
* ```
*
* @example Set design property
* ```mdl
* ALTER STYLING ON PAGE MyModule.Page WIDGET ctn1
* SET 'Spacing top' = 'Large', 'Full width' = ON;
* ```
*
* @example Clear all design properties
* ```mdl
* ALTER STYLING ON PAGE MyModule.Page WIDGET ctn1
* CLEAR DESIGN PROPERTIES;
* ```
*/
alterStylingAction
: SET alterStylingAssignment (COMMA alterStylingAssignment)*
| CLEAR DESIGN PROPERTIES
;
alterStylingAssignment
: CLASS EQUALS STRING_LITERAL // Class = 'my-class'
| STYLE EQUALS STRING_LITERAL // Style = 'color: red;'
| STRING_LITERAL EQUALS STRING_LITERAL // 'Spacing top' = 'Large'
| STRING_LITERAL EQUALS ON // 'Full width' = ON
| STRING_LITERAL EQUALS OFF // 'Full width' = OFF
;
/**
* ALTER PAGE operations for modifying widget trees in-place.
*
* @example Set property on widget
* ```mdl
* ALTER PAGE Module.Page {
* SET Caption = 'Save' ON btnSave
* }
* ```
*
* @example Insert widget after another
* ```mdl
* ALTER PAGE Module.Page {
* INSERT AFTER txtName { TEXTBOX txtNew (Label: 'New', Binds: Attr) }
* }
* ```
*
* @example Drop widgets
* ```mdl
* ALTER PAGE Module.Page {
* DROP WIDGET txtOld, txtUnused
* }
* ```
*
* @example Replace widget subtree
* ```mdl
* ALTER PAGE Module.Page {
* REPLACE footer1 WITH { FOOTER f1 { ACTIONBUTTON btn1 (Caption: 'OK', Action: SAVE_CHANGES) } }
* }
* ```
*/
alterPageOperation
: alterPageSet SEMICOLON?
| alterPageInsert SEMICOLON?
| alterPageDrop SEMICOLON?
| alterPageReplace SEMICOLON?
| alterPageAddVariable SEMICOLON?
| alterPageDropVariable SEMICOLON?
;
alterPageSet
: SET LAYOUT EQUALS qualifiedName (MAP LPAREN alterLayoutMapping (COMMA alterLayoutMapping)* RPAREN)? // SET Layout = Atlas_Core.TopBar MAP (Main -> Main)
| SET alterPageAssignment ON widgetRef // SET Caption = 'Save' ON btnSave | ON dgProducts.Name
| SET LPAREN alterPageAssignment (COMMA alterPageAssignment)* RPAREN ON widgetRef // SET (Caption = 'Save', ButtonStyle = Success) ON btnSave
| SET alterPageAssignment // SET Title = 'Edit' (page-level)
;
alterLayoutMapping
: identifierOrKeyword AS identifierOrKeyword // OldPlaceholder AS NewPlaceholder
;
alterPageAssignment
: DATASOURCE EQUALS dataSourceExprV3 // DataSource = SELECTION widgetName
| identifierOrKeyword EQUALS propertyValueV3 // Caption = 'Save'
| STRING_LITERAL EQUALS propertyValueV3 // 'showLabel' = false
;
alterPageInsert
: INSERT AFTER widgetRef LBRACE pageBodyV3 RBRACE
| INSERT BEFORE widgetRef LBRACE pageBodyV3 RBRACE
;
alterPageDrop
: DROP WIDGET widgetRef (COMMA widgetRef)*
;
alterPageReplace
: REPLACE widgetRef WITH LBRACE pageBodyV3 RBRACE
;
// Widget reference: plain name (btnSave) or dotted path (dgProducts.Name)
widgetRef
: identifierOrKeyword DOT identifierOrKeyword // dgProducts.Name (column ref)
| identifierOrKeyword // btnSave (widget ref)
;
alterPageAddVariable
: ADD VARIABLES_KW variableDeclaration // ADD Variables $show: Boolean = 'true'
;
alterPageDropVariable
: DROP VARIABLES_KW VARIABLE // DROP Variables $show
;
navigationClause
: HOME (PAGE | MICROFLOW) qualifiedName (FOR qualifiedName)?
| LOGIN PAGE qualifiedName
| NOT FOUND PAGE qualifiedName
| MENU_KW LPAREN navMenuItemDef* RPAREN
;
navMenuItemDef
: MENU_KW ITEM STRING_LITERAL ((PAGE qualifiedName) | (MICROFLOW qualifiedName))? SEMICOLON?
| MENU_KW STRING_LITERAL LPAREN navMenuItemDef* RPAREN SEMICOLON?
;
dropStatement
: DROP ENTITY qualifiedName
| DROP ASSOCIATION qualifiedName
| DROP ENUMERATION qualifiedName
| DROP CONSTANT qualifiedName
| DROP MICROFLOW qualifiedName
| DROP NANOFLOW qualifiedName
| DROP PAGE qualifiedName
| DROP SNIPPET qualifiedName
| DROP MODULE qualifiedName
| DROP NOTEBOOK qualifiedName
| DROP JAVA ACTION qualifiedName
| DROP INDEX qualifiedName ON qualifiedName
| DROP ODATA CLIENT qualifiedName
| DROP ODATA SERVICE qualifiedName
| DROP BUSINESS EVENT SERVICE qualifiedName
| DROP WORKFLOW qualifiedName
| DROP IMAGE COLLECTION qualifiedName
| DROP JSON STRUCTURE qualifiedName
| DROP IMPORT MAPPING qualifiedName
| DROP EXPORT MAPPING qualifiedName
| DROP REST CLIENT qualifiedName
| DROP PUBLISHED REST SERVICE qualifiedName
| DROP CONFIGURATION STRING_LITERAL
| DROP FOLDER STRING_LITERAL IN (qualifiedName | IDENTIFIER)
;
renameStatement
: RENAME renameTarget qualifiedName TO identifierOrKeyword (DRY RUN)?
| RENAME MODULE identifierOrKeyword TO identifierOrKeyword (DRY RUN)?
;
renameTarget
: ENTITY | MICROFLOW | NANOFLOW | PAGE | ENUMERATION | ASSOCIATION | CONSTANT
;
/**
* Moves a document to a different folder or module.
*
* @example Move page to folder in same module
* ```mdl
* MOVE PAGE MyModule.MyPage TO FOLDER 'Resources/Pages';
* ```
*
* @example Move microflow to folder in different module
* ```mdl
* MOVE MICROFLOW MyModule.MyMicroflow TO FOLDER 'Utils' IN OtherModule;
* ```
*
* @example Move snippet to module root (no folder)
* ```mdl
* MOVE SNIPPET MyModule.MySnippet TO OtherModule;
* ```
*
* @example Move entity to different module (no folder support)
* ```mdl
* MOVE ENTITY MyModule.Customer TO OtherModule;
* ```
*
* @example Move enumeration to different module
* ```mdl
* MOVE ENUMERATION MyModule.OrderStatus TO OtherModule;
* ```
*/
moveStatement
: MOVE (PAGE | MICROFLOW | SNIPPET | NANOFLOW | ENUMERATION | CONSTANT | DATABASE CONNECTION) qualifiedName TO FOLDER STRING_LITERAL (IN (qualifiedName | IDENTIFIER))?
| MOVE (PAGE | MICROFLOW | SNIPPET | NANOFLOW | ENUMERATION | CONSTANT | DATABASE CONNECTION) qualifiedName TO (qualifiedName | IDENTIFIER)
| MOVE ENTITY qualifiedName TO (qualifiedName | IDENTIFIER)
| MOVE FOLDER qualifiedName TO FOLDER STRING_LITERAL (IN (qualifiedName | IDENTIFIER))?
| MOVE FOLDER qualifiedName TO (qualifiedName | IDENTIFIER)
;
// =============================================================================
// SECURITY STATEMENTS
// =============================================================================
securityStatement
: createModuleRoleStatement
| dropModuleRoleStatement
| alterUserRoleStatement
| dropUserRoleStatement
| grantEntityAccessStatement
| revokeEntityAccessStatement
| grantMicroflowAccessStatement
| revokeMicroflowAccessStatement
| grantPageAccessStatement
| revokePageAccessStatement
| grantWorkflowAccessStatement
| revokeWorkflowAccessStatement
| grantODataServiceAccessStatement
| revokeODataServiceAccessStatement
| grantPublishedRestServiceAccessStatement
| revokePublishedRestServiceAccessStatement
| alterProjectSecurityStatement
| dropDemoUserStatement
| updateSecurityStatement
;
createModuleRoleStatement
: CREATE MODULE ROLE qualifiedName (DESCRIPTION STRING_LITERAL)?
;
dropModuleRoleStatement
: DROP MODULE ROLE qualifiedName
;
createUserRoleStatement
: USER ROLE identifierOrKeyword
LPAREN moduleRoleList RPAREN
(MANAGE ALL ROLES)?
;
alterUserRoleStatement
: ALTER USER ROLE identifierOrKeyword ADD MODULE ROLES LPAREN moduleRoleList RPAREN
| ALTER USER ROLE identifierOrKeyword REMOVE MODULE ROLES LPAREN moduleRoleList RPAREN
;
dropUserRoleStatement
: DROP USER ROLE identifierOrKeyword
;
grantEntityAccessStatement
: GRANT moduleRoleList ON qualifiedName
LPAREN entityAccessRightList RPAREN
(WHERE STRING_LITERAL)?
;
revokeEntityAccessStatement
: REVOKE moduleRoleList ON qualifiedName
(LPAREN entityAccessRightList RPAREN)?
;
grantMicroflowAccessStatement
: GRANT EXECUTE ON MICROFLOW qualifiedName TO moduleRoleList
;
revokeMicroflowAccessStatement
: REVOKE EXECUTE ON MICROFLOW qualifiedName FROM moduleRoleList
;
grantPageAccessStatement
: GRANT VIEW ON PAGE qualifiedName TO moduleRoleList
;
revokePageAccessStatement
: REVOKE VIEW ON PAGE qualifiedName FROM moduleRoleList
;
grantWorkflowAccessStatement
: GRANT EXECUTE ON WORKFLOW qualifiedName TO moduleRoleList
;
revokeWorkflowAccessStatement
: REVOKE EXECUTE ON WORKFLOW qualifiedName FROM moduleRoleList
;
grantODataServiceAccessStatement
: GRANT ACCESS ON ODATA SERVICE qualifiedName TO moduleRoleList
;
revokeODataServiceAccessStatement
: REVOKE ACCESS ON ODATA SERVICE qualifiedName FROM moduleRoleList
;
grantPublishedRestServiceAccessStatement
: GRANT ACCESS ON PUBLISHED REST SERVICE qualifiedName TO moduleRoleList
;
revokePublishedRestServiceAccessStatement
: REVOKE ACCESS ON PUBLISHED REST SERVICE qualifiedName FROM moduleRoleList
;
alterProjectSecurityStatement
: ALTER PROJECT SECURITY LEVEL (PRODUCTION | PROTOTYPE | OFF)
| ALTER PROJECT SECURITY DEMO USERS (ON | OFF)
;
createDemoUserStatement
: DEMO USER STRING_LITERAL PASSWORD STRING_LITERAL (ENTITY qualifiedName)?
LPAREN identifierOrKeyword (COMMA identifierOrKeyword)* RPAREN
;
dropDemoUserStatement
: DROP DEMO USER STRING_LITERAL
;
updateSecurityStatement
: UPDATE SECURITY (IN qualifiedName)?
;
moduleRoleList
: qualifiedName (COMMA qualifiedName)*
;
entityAccessRightList
: entityAccessRight (COMMA entityAccessRight)*
;
entityAccessRight
: CREATE
| DELETE
| READ STAR
| READ LPAREN IDENTIFIER (COMMA IDENTIFIER)* RPAREN
| WRITE STAR
| WRITE LPAREN IDENTIFIER (COMMA IDENTIFIER)* RPAREN
;
// =============================================================================
// ENTITY / ASSOCIATION CREATION
// =============================================================================
/**
* Creates a new entity in the domain model.
*
* Entities can be persistent (stored in database), non-persistent (in-memory only),
* view (based on OQL query), or external (from external data source).
*
* @example Persistent entity with attributes
* ```mdl
* CREATE PERSISTENT ENTITY MyModule.Customer (
* Name: String(100) NOT NULL,
* Email: String(200) UNIQUE,
* Age: Integer,
* Active: Boolean DEFAULT true
* );
* ```
*
* @example Non-persistent entity for search filters
* ```mdl
* CREATE NON-PERSISTENT ENTITY MyModule.SearchFilter (
* Query: String,
* MaxResults: Integer DEFAULT 100,
* IncludeArchived: Boolean DEFAULT false
* );
* ```
*
* @example View entity with OQL query
* ```mdl
* CREATE VIEW ENTITY MyModule.ActiveCustomers (
* CustomerId: Integer,
* CustomerName: String(100)
* ) AS
* SELECT c.Id AS CustomerId, c.Name AS CustomerName
* FROM MyModule.Customer AS c
* WHERE c.Active = true;
* ```
*
* @example Entity with index
* ```mdl
* CREATE PERSISTENT ENTITY MyModule.Order (
* OrderNumber: String(50) NOT NULL,
* CustomerRef: MyModule.Customer
* )
* INDEX (OrderNumber);
* ```
*
* @see attributeDefinition for attribute syntax
* @see dataType for supported data types
* @see oqlQuery for view entity queries
*/
createEntityStatement
: PERSISTENT ENTITY qualifiedName generalizationClause? entityBody?
| NON_PERSISTENT ENTITY qualifiedName generalizationClause? entityBody?
| VIEW ENTITY qualifiedName entityBody? AS LPAREN? oqlQuery RPAREN? // Parentheses optional
| EXTERNAL ENTITY qualifiedName entityBody?
| ENTITY qualifiedName generalizationClause? entityBody? // Default to persistent
;
generalizationClause
: EXTENDS qualifiedName
| GENERALIZATION qualifiedName
;
entityBody
: LPAREN attributeDefinitionList? RPAREN entityOptions?
| entityOptions
;
entityOptions
: entityOption (COMMA? entityOption)* // Allow optional commas between options
;
entityOption
: COMMENT STRING_LITERAL
| INDEX indexDefinition
| eventHandlerDefinition
;
// Entity event handler: ON BEFORE/AFTER CREATE/COMMIT/DELETE/ROLLBACK CALL Mod.Microflow($currentObject) [RAISE ERROR]
// Empty parens () = don't pass object, ($currentObject) = pass object, no parens = pass object (default)
eventHandlerDefinition
: ON eventMoment eventType CALL qualifiedName (LPAREN VARIABLE? RPAREN)? (RAISE ERROR)?
;
eventMoment
: BEFORE | AFTER
;
eventType
: CREATE | COMMIT | DELETE | ROLLBACK
;
attributeDefinitionList
: attributeDefinition (COMMA attributeDefinition)*
;
/**
* Defines an attribute within an entity.
*
* Attributes have a name, data type, and optional constraints like NOT NULL, UNIQUE, or DEFAULT.
* Documentation comments can be added above the attribute.
*
* @example Simple attributes
* ```mdl
* Name: String(100),
* Age: Integer,
* Active: Boolean
* ```
*
* @example Attributes with constraints
* ```mdl
* Code: String(50) NOT NULL,
* Email: String(200) UNIQUE,
* Status: Enum MyModule.Status DEFAULT MyModule.Status.Active
* ```
*
* @example Attribute with custom error messages
* ```mdl
* Name: String(100) NOT NULL ERROR 'Name is required',
* Code: String(50) UNIQUE ERROR 'Code must be unique'
* ```
*
* @example Documented attribute
* ```mdl
* -- The customer's primary email address
* Email: String(200) NOT NULL UNIQUE
* ```
*
* @see dataType for available types
* @see attributeConstraint for constraint options
*/
attributeDefinition
: docComment? annotation* attributeName COLON dataType attributeConstraint*
;
// Allow reserved keywords as attribute names
attributeName
: IDENTIFIER
| QUOTED_IDENTIFIER // Escape any reserved word ("Range", `Order`)
| keyword
;
attributeConstraint
: NOT_NULL (ERROR STRING_LITERAL)?
| NOT NULL (ERROR STRING_LITERAL)?
| UNIQUE (ERROR STRING_LITERAL)?
| DEFAULT (literal | expression)
| REQUIRED (ERROR STRING_LITERAL)?
| CALCULATED (BY? qualifiedName)?
;
/**
* Specifies the data type for an attribute.
*
* MDL supports all Mendix primitive types, enumerations, and entity references.
*
* @example Primitive types
* ```mdl
* Name: String(200), -- String with max length 200
* Age: Integer, -- 32-bit integer
* Total: Decimal, -- Fixed-point decimal
* Active: Boolean, -- true/false
* Created: DateTime, -- Date and time
* BirthDate: Date, -- Date only
* Counter: AutoNumber, -- Auto-incrementing number
* Data: Binary, -- Binary data (files)
* Password: HashedString -- Securely hashed string
* ```
*
* @example Enumeration types
* ```mdl
* Status: Enum MyModule.OrderStatus,
* Priority: Enumeration(MyModule.Priority)
* ```
*
* @example Entity references
* ```mdl
* Customer: MyModule.Customer, -- Single reference
* Items: List of MyModule.OrderItem -- List of references
* ```
*/
dataType
: STRING_TYPE (LPAREN (NUMBER_LITERAL | IDENTIFIER) RPAREN)?
| INTEGER_TYPE
| LONG_TYPE
| DECIMAL_TYPE
| BOOLEAN_TYPE
| DATETIME_TYPE
| DATE_TYPE
| AUTONUMBER_TYPE
| AUTOOWNER_TYPE
| AUTOCHANGEDBY_TYPE
| AUTOCREATEDDATE_TYPE
| AUTOCHANGEDDATE_TYPE
| BINARY_TYPE
| HASHEDSTRING_TYPE
| CURRENCY_TYPE
| FLOAT_TYPE
| STRINGTEMPLATE_TYPE LPAREN templateContext RPAREN // StringTemplate(Sql) etc.
| ENTITY LESS_THAN IDENTIFIER GREATER_THAN // ENTITY <pEntity> type parameter declaration
| ENUM_TYPE qualifiedName
| ENUMERATION LPAREN qualifiedName RPAREN // Enumeration(Module.Enum) syntax
| LIST_OF qualifiedName
| qualifiedName // Entity reference type
;
// Template context for StringTemplate types - only SQL or Text are valid
templateContext
: SQL
| TEXT
;
// Non-list data type - used for createObjectStatement to avoid matching "CREATE LIST OF"
nonListDataType
: STRING_TYPE (LPAREN (NUMBER_LITERAL | IDENTIFIER) RPAREN)?
| INTEGER_TYPE
| LONG_TYPE
| DECIMAL_TYPE
| BOOLEAN_TYPE
| DATETIME_TYPE
| DATE_TYPE
| AUTONUMBER_TYPE
| AUTOOWNER_TYPE
| AUTOCHANGEDBY_TYPE
| AUTOCREATEDDATE_TYPE
| AUTOCHANGEDDATE_TYPE
| BINARY_TYPE
| HASHEDSTRING_TYPE
| CURRENCY_TYPE
| FLOAT_TYPE
| ENUM_TYPE qualifiedName
| ENUMERATION LPAREN qualifiedName RPAREN
| qualifiedName // Entity reference type (NOT list)
;
indexDefinition
: IDENTIFIER? LPAREN indexAttributeList RPAREN
;
indexAttributeList
: indexAttribute (COMMA indexAttribute)*
;
indexAttribute
: indexColumnName (ASC | DESC)? // Column name with optional sort order
;
// Allow keywords as index column names (same as attributeName)
indexColumnName
: IDENTIFIER
| QUOTED_IDENTIFIER // Escape any reserved word
| keyword
;
createAssociationStatement
: ASSOCIATION qualifiedName
FROM qualifiedName
TO qualifiedName
associationOptions?
| ASSOCIATION qualifiedName LPAREN
FROM qualifiedName TO qualifiedName
(COMMA associationOption)*
RPAREN
;
associationOptions
: associationOption+
;
associationOption
: TYPE COLON? (REFERENCE | REFERENCE_SET)
| OWNER COLON? (DEFAULT | BOTH)
| STORAGE COLON? (COLUMN | TABLE)
| DELETE_BEHAVIOR deleteBehavior
| COMMENT STRING_LITERAL
;
deleteBehavior
: DELETE_AND_REFERENCES
| DELETE_BUT_KEEP_REFERENCES
| DELETE_IF_NO_REFERENCES
| CASCADE
| PREVENT
;
// =============================================================================
// ALTER ENTITY ACTIONS
// =============================================================================
alterEntityAction
: ADD ATTRIBUTE attributeDefinition
| ADD COLUMN attributeDefinition
| RENAME ATTRIBUTE attributeName TO attributeName
| RENAME COLUMN attributeName TO attributeName
| MODIFY ATTRIBUTE attributeName COLON? dataType attributeConstraint*
| MODIFY COLUMN attributeName COLON? dataType attributeConstraint*
| DROP ATTRIBUTE attributeName
| DROP COLUMN attributeName
| SET DOCUMENTATION STRING_LITERAL
| SET COMMENT STRING_LITERAL
| SET POSITION LPAREN NUMBER_LITERAL COMMA NUMBER_LITERAL RPAREN
| ADD INDEX indexDefinition
| DROP INDEX IDENTIFIER
| ADD EVENT HANDLER eventHandlerDefinition
| DROP EVENT HANDLER ON eventMoment eventType
;
alterAssociationAction
: SET DELETE_BEHAVIOR deleteBehavior
| SET OWNER (DEFAULT | BOTH)
| SET STORAGE (COLUMN | TABLE)
| SET COMMENT STRING_LITERAL
;
alterEnumerationAction
: ADD VALUE IDENTIFIER (CAPTION STRING_LITERAL)?
| RENAME VALUE IDENTIFIER TO IDENTIFIER
| DROP VALUE IDENTIFIER
| SET COMMENT STRING_LITERAL
;
alterNotebookAction
: ADD PAGE qualifiedName (POSITION NUMBER_LITERAL)?
| DROP PAGE qualifiedName
| SET COMMENT STRING_LITERAL
;
// =============================================================================
// MODULE CREATION
// =============================================================================
createModuleStatement
: MODULE IDENTIFIER moduleOptions?
;
moduleOptions
: moduleOption+
;
moduleOption
: COMMENT STRING_LITERAL
| FOLDER STRING_LITERAL
;
// =============================================================================
// ENUMERATION CREATION
// =============================================================================
createEnumerationStatement
: ENUMERATION qualifiedName
LPAREN enumerationValueList RPAREN
enumerationOptions?
;
enumerationValueList
: enumerationValue (COMMA enumerationValue)*
;
enumerationValue
: docComment? enumValueName (CAPTION? STRING_LITERAL)?
;
// Allow reserved keywords as enumeration value names.
// Uses the full `keyword` rule so any lexer token can appear as an enum value name.
enumValueName
: IDENTIFIER
| QUOTED_IDENTIFIER // Escape any reserved word
| keyword
;
enumerationOptions
: enumerationOption+
;
enumerationOption
: COMMENT STRING_LITERAL
;
// =============================================================================
// IMAGE COLLECTION CREATION
// =============================================================================
createImageCollectionStatement
: IMAGE COLLECTION qualifiedName imageCollectionOptions? imageCollectionBody?
;
imageCollectionOptions
: imageCollectionOption+
;
imageCollectionOption
: EXPORT LEVEL STRING_LITERAL // e.g. EXPORT LEVEL 'Public'
| COMMENT STRING_LITERAL
;
imageCollectionBody
: LPAREN imageCollectionItem (COMMA imageCollectionItem)* RPAREN
;
imageCollectionItem
: IMAGE imageName FROM FILE_KW path=STRING_LITERAL // IMAGE MyIcon FROM FILE '/path/to/file.png'
;
imageName
: IDENTIFIER
| QUOTED_IDENTIFIER
| keyword
;
// =============================================================================
// JSON STRUCTURE CREATION
// =============================================================================
createJsonStructureStatement
: JSON STRUCTURE qualifiedName (FOLDER STRING_LITERAL)? (COMMENT STRING_LITERAL)? SNIPPET (STRING_LITERAL | DOLLAR_STRING)
(CUSTOM_NAME_MAP LPAREN customNameMapping (COMMA customNameMapping)* RPAREN)?
;
customNameMapping
: STRING_LITERAL AS STRING_LITERAL // 'jsonKey' AS 'CustomName'
;
/**
* CREATE IMPORT MAPPING Module.Name
* WITH JSON STRUCTURE Module.JsonStructure
* {
* CREATE Module.Entity {
* PetId = id KEY,
* Name = name,
* CREATE Module.Assoc/Module.Child = jsonKey {
* Email = email
* }
* }
* };
*/
createImportMappingStatement
: IMPORT MAPPING qualifiedName
importMappingWithClause?
LBRACE importMappingRootElement RBRACE
;
importMappingWithClause
: WITH JSON STRUCTURE qualifiedName
| WITH XML SCHEMA qualifiedName
;
importMappingRootElement
: importMappingObjectHandling qualifiedName
LBRACE importMappingChild (COMMA importMappingChild)* RBRACE
;
importMappingChild
: importMappingObjectHandling qualifiedName SLASH qualifiedName EQUALS identifierOrKeyword
LBRACE importMappingChild (COMMA importMappingChild)* RBRACE // nested object with children
| importMappingObjectHandling qualifiedName SLASH qualifiedName EQUALS identifierOrKeyword // leaf object
| identifierOrKeyword EQUALS qualifiedName LPAREN identifierOrKeyword RPAREN // value transform: Attr = Module.MF(jsonField)
| identifierOrKeyword EQUALS identifierOrKeyword KEY? // value: Attr = jsonField [KEY]
;
importMappingObjectHandling
: CREATE
| FIND
| FIND OR CREATE
;
/**
* CREATE EXPORT MAPPING Module.Name
* WITH JSON STRUCTURE Module.JsonStructure
* [NULL VALUES LeaveOutElement]
* {
* Module.Entity {
* jsonField = Attr,
* Module.Assoc/Module.Child AS jsonKey {
* email = Email
* }
* }
* };
*/
createExportMappingStatement
: EXPORT MAPPING qualifiedName
exportMappingWithClause?
exportMappingNullValuesClause?
LBRACE exportMappingRootElement RBRACE
;
exportMappingWithClause
: WITH JSON STRUCTURE qualifiedName
| WITH XML SCHEMA qualifiedName
;
exportMappingNullValuesClause
: NULL VALUES identifierOrKeyword
;
exportMappingRootElement
: qualifiedName
LBRACE exportMappingChild (COMMA exportMappingChild)* RBRACE
;
exportMappingChild
: qualifiedName SLASH qualifiedName AS identifierOrKeyword
LBRACE exportMappingChild (COMMA exportMappingChild)* RBRACE // nested object with children
| qualifiedName SLASH qualifiedName AS identifierOrKeyword // leaf object
| identifierOrKeyword EQUALS identifierOrKeyword // value: jsonField = Attr
;
// =============================================================================
// VALIDATION RULE CREATION
// =============================================================================
createValidationRuleStatement
: VALIDATION RULE qualifiedName
FOR qualifiedName
validationRuleBody
;
validationRuleBody
: EXPRESSION expression FEEDBACK STRING_LITERAL
| REQUIRED attributeReference FEEDBACK STRING_LITERAL
| UNIQUE attributeReferenceList FEEDBACK STRING_LITERAL
| RANGE attributeReference rangeConstraint FEEDBACK STRING_LITERAL
| REGEX attributeReference STRING_LITERAL FEEDBACK STRING_LITERAL
;
rangeConstraint
: BETWEEN literal AND literal