Skip to content

Commit

Permalink
flexibilities where config, apis, imports and global_javadoc
Browse files Browse the repository at this point in the history
…may appear on the document, allowing zdl file concatenation.
  • Loading branch information
ivangsa committed Dec 12, 2024
1 parent 0a7ada0 commit c71ed0b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/antlr4/io.github.zenwave360.zdl.antlr/Zdl.g4
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ PATTERN_REGEX: '/' .*? '/' ; // TODO: improve regex
ERRCHAR: . -> channel(HIDDEN);
// Rules
zdl: imports global_javadoc? legacy_constants config? apis? (policies | aggregate | entity | enum | input | output | event | relationships | service | service_legacy)* EOF;
zdl: legacy_constants (import_ | config | apis | policies | aggregate | entity | enum | input | output | event | relationships | service | service_legacy)* EOF;
imports: ('@import' LPAREN import_value RPAREN)*;
import_: '@import' LPAREN import_value RPAREN;
import_value: string;
global_javadoc: JAVADOC;
javadoc: JAVADOC;
Expand All @@ -139,7 +139,7 @@ pair: keyword COLON value;
object: LBRACE pair (COMMA pair)* RBRACE;
array: LBRACK? value (COMMA value)* RBRACK?;
config: CONFIG config_body;
config: global_javadoc? CONFIG config_body;
config_body: LBRACE config_option* plugins? RBRACE;
config_option: field_name complex_value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ public void enterLegacy_constants(io.github.zenwave360.zdl.antlr.ZdlParser.Legac
}

@Override
public void enterImports(io.github.zenwave360.zdl.antlr.ZdlParser.ImportsContext ctx) {
for (io.github.zenwave360.zdl.antlr.ZdlParser.Import_valueContext importValue : ctx.import_value()) {
model.appendToList("imports", getValueText(importValue.string()));
}
public void enterImport_(io.github.zenwave360.zdl.antlr.ZdlParser.Import_Context ctx) {
model.appendToList("imports", getValueText(ctx.import_value().string()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ public class ZdlListenerTest {

@Test
public void parseZdl_SuffixJavadoc() throws Exception {

ZdlModel model = parseZdl("src/test/resources/suffix_javadoc.zdl");
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model));
}

@Test
public void parseZdl_Composed() throws Exception {
ZdlModel model = parseZdl("src/test/resources/composed.zdl");
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(model));
}


@Test
public void parseZdl_CompleteZdl() throws Exception {

Expand Down
23 changes: 23 additions & 0 deletions src/test/resources/composed.zdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* First Global Javadoc
*/
config {
title "First Title"
}

entity OneEntity {
oneField String
secondField String
}

/**
* Seccond Global Javadoc
*/
config {
title "Second Title"
}

entity OneEntity {
oneField Long
thirdField String
}

0 comments on commit c71ed0b

Please sign in to comment.