Skip to content

Commit f96a037

Browse files
akoclaude
andcommitted
refactor: split MDLParser.g4 into domain-specific files (#515)
Reduces merge conflicts: PRs that add syntax to different domains now touch separate domain files instead of the same monolithic grammar. MDLParser.g4 shrinks from 4082 → 400 lines (master dispatch rules only). Nine domain files created in mdl/grammar/domains/: MDLDomainModel.g4 — entities, associations, enums, constants, mappings MDLMicroflow.g4 — microflows, nanoflows, Java actions, REST calls, list ops MDLPage.g4 — pages, snippets, xpath, page V3 widgets, notebooks MDLSecurity.g4 — roles, grants, revokes, project security, demo users MDLAgent.g4 — agent editor: models, knowledge bases, MCP services, agents MDLWorkflow.g4 — CREATE/ALTER WORKFLOW MDLService.g4 — database connections, REST/OData clients+services, BES MDLCatalog.g4 — SHOW/DESCRIBE statements, SELECT CATALOG, OQL query MDLSettings.g4 — ALTER SETTINGS, utility statements, expressions, common rules ANTLR4 merges all rules at generation time — the generated Go parser is unchanged and all listener/visitor code continues to work without modification. Updated mdl/grammar/Makefile and generate.sh to pass -lib domains so ANTLR4 can resolve imported grammars. Updated keyword_coverage_test.go to search all domain files since the keyword rule moved to MDLSettings.g4. Applied main's grammar changes to domain files: - addToListStatement: ADD expression TO VARIABLE (MDLMicroflow.g4) - sessionSetStatement already present from original grammar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0d6ddd5 commit f96a037

18 files changed

Lines changed: 54901 additions & 55397 deletions

mdl/grammar/MDLParser.g4

Lines changed: 22 additions & 3704 deletions
Large diffs are not rendered by default.

mdl/grammar/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ PARSER = MDLParser.g4
1515
OUTPUT_DIR = parser
1616
PACKAGE = parser
1717

18+
# Domain grammar files (imported by MDLParser.g4 via the `import` directive)
19+
DOMAIN_FILES = \
20+
domains/MDLDomainModel.g4 \
21+
domains/MDLMicroflow.g4 \
22+
domains/MDLPage.g4 \
23+
domains/MDLSecurity.g4 \
24+
domains/MDLAgent.g4 \
25+
domains/MDLWorkflow.g4 \
26+
domains/MDLService.g4 \
27+
domains/MDLCatalog.g4 \
28+
domains/MDLSettings.g4
29+
1830
# Find antlr4 command (try common locations)
1931
ANTLR4 := $(shell which antlr4 2>/dev/null || which antlr 2>/dev/null)
2032

@@ -25,9 +37,9 @@ ifndef ANTLR4
2537
$(error ANTLR4 not found. Install with: brew install antlr4 (macOS) or pip install antlr4-tools)
2638
endif
2739

28-
generate: check-antlr $(LEXER) $(PARSER)
40+
generate: check-antlr $(LEXER) $(PARSER) $(DOMAIN_FILES)
2941
@mkdir -p $(OUTPUT_DIR)
30-
$(ANTLR4) -Dlanguage=Go -no-visitor -package $(PACKAGE) -o $(OUTPUT_DIR) $(LEXER) $(PARSER)
42+
$(ANTLR4) -Dlanguage=Go -no-visitor -package $(PACKAGE) -lib domains -o $(OUTPUT_DIR) $(LEXER) $(PARSER)
3143
@echo "Generated Go parser in $(OUTPUT_DIR)/"
3244

3345
clean:

mdl/grammar/domains/MDLAgent.g4

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* MDL Agent Grammar — agent editor: models, knowledge bases,
3+
* consumed MCP services, agents.
4+
*/
5+
parser grammar MDLAgent;
6+
7+
options { tokenVocab = MDLLexer; }
8+
9+
// =============================================================================
10+
// AGENT-EDITOR MODEL CREATION
11+
// =============================================================================
12+
// CREATE MODEL Module.Name (
13+
// Provider: MxCloudGenAI,
14+
// Key: Module.SomeConstant
15+
// [, DisplayName: '...', KeyName: '...', etc. — Portal-populated metadata]
16+
// );
17+
createModelStatement
18+
: MODEL qualifiedName
19+
LPAREN modelProperty (COMMA modelProperty)* RPAREN
20+
;
21+
22+
modelProperty
23+
: identifierOrKeyword COLON identifierOrKeyword // Provider: MxCloudGenAI
24+
| identifierOrKeyword COLON qualifiedName // Key: Module.Constant
25+
| identifierOrKeyword COLON STRING_LITERAL // DisplayName: 'GPT-4 Turbo' etc.
26+
| identifierOrKeyword COLON NUMBER_LITERAL // ConnectionTimeoutSeconds: 30
27+
| identifierOrKeyword COLON booleanLiteral // Enabled: true
28+
| identifierOrKeyword COLON DOLLAR_STRING // SystemPrompt: $$multi-line...$$
29+
| identifierOrKeyword COLON LPAREN variableDefList RPAREN // Variables: ("Key": EntityAttribute, ...)
30+
;
31+
32+
variableDefList
33+
: variableDef (COMMA variableDef)*
34+
;
35+
36+
variableDef
37+
: (STRING_LITERAL | QUOTED_IDENTIFIER) COLON identifierOrKeyword // "Key": EntityAttribute
38+
;
39+
40+
// =============================================================================
41+
// AGENT-EDITOR CONSUMED MCP SERVICE CREATION
42+
// =============================================================================
43+
// CREATE CONSUMED MCP SERVICE Module.Name (
44+
// ProtocolVersion: v2025_03_26,
45+
// Version: '0.0.1',
46+
// ConnectionTimeoutSeconds: 30,
47+
// Documentation: '...'
48+
// );
49+
createConsumedMCPServiceStatement
50+
: CONSUMED MCP SERVICE qualifiedName
51+
LPAREN modelProperty (COMMA modelProperty)* RPAREN
52+
;
53+
54+
// =============================================================================
55+
// AGENT-EDITOR KNOWLEDGE BASE CREATION
56+
// =============================================================================
57+
// CREATE KNOWLEDGE BASE Module.Name (
58+
// Provider: MxCloudGenAI,
59+
// Key: Module.SomeConstant
60+
// );
61+
createKnowledgeBaseStatement
62+
: KNOWLEDGE BASE qualifiedName
63+
LPAREN modelProperty (COMMA modelProperty)* RPAREN
64+
;
65+
66+
// =============================================================================
67+
// AGENT-EDITOR AGENT CREATION
68+
// =============================================================================
69+
// CREATE AGENT Module.Name (
70+
// UsageType: Task,
71+
// Model: Module.MyModel,
72+
// SystemPrompt: '...',
73+
// ...
74+
// )
75+
// [ { TOOL ... | MCP SERVICE ... | KNOWLEDGE BASE ... } ]
76+
// ;
77+
createAgentStatement
78+
: AGENT qualifiedName
79+
LPAREN modelProperty (COMMA modelProperty)* RPAREN
80+
agentBody?
81+
;
82+
83+
agentBody
84+
: LBRACE agentBodyBlock* RBRACE
85+
;
86+
87+
agentBodyBlock
88+
: MCP SERVICE qualifiedName LBRACE modelProperty (COMMA modelProperty)* RBRACE // MCP SERVICE Mod.Name { ... }
89+
| KNOWLEDGE BASE identifierOrKeyword LBRACE modelProperty (COMMA modelProperty)* RBRACE // KNOWLEDGE BASE MyKB { ... }
90+
| TOOL identifierOrKeyword LBRACE modelProperty (COMMA modelProperty)* RBRACE // TOOL ToolName { ... }
91+
;

0 commit comments

Comments
 (0)