Skip to content

Commit

Permalink
support notes for Table Group
Browse files Browse the repository at this point in the history
  • Loading branch information
nilswende committed Oct 24, 2024
1 parent acf265e commit af3702c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/com/wn/dbml/compiler/parser/ParserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,15 @@ private void parseTableGroup() {
} else {
next(LBRACE);
while (true) {
var tableName = parseTableName();
var table = findTable(tableName);
if (!tableGroup.addTable(table)) {
error("Table '%s' is already defined", table);
if (lookaheadTypeIs(NOTE)) {
next(NOTE);
tableGroup.setNote(parseNote());
} else {
var tableName = parseTableName();
var table = findTable(tableName);
if (!tableGroup.addTable(table)) {
error("Table '%s' is already defined", table);
}
}
if (lookaheadTypeIs(RBRACE)) {
next(RBRACE);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/wn/dbml/model/TableGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class TableGroup {
private final Schema schema;
private final String name;
private final Set<Table> tables = new LinkedHashSet<>();
private Note note;

TableGroup(final Schema schema, final String name) {
this.schema = Objects.requireNonNull(schema);
Expand All @@ -31,6 +32,14 @@ public Set<Table> getTables() {
return Collections.unmodifiableSet(tables);
}

public Note getNote() {
return note;
}

public void setNote(Note note) {
this.note = note;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/wn/dbml/compiler/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ void testParseTableGroup() {
table1
table2
C
note: 'group note'
}""";
var database = parse(dbml);

Expand All @@ -384,6 +385,9 @@ void testParseTableGroup() {
assertTrue(schema.containsTableGroup(tableGroupName));
var tables = tableGroup.getTables();
assertEquals(3, tables.size());
var note = tableGroup.getNote();
assertNotNull(note);
assertEquals("group note", note.getValue());
}

@Test
Expand Down

0 comments on commit af3702c

Please sign in to comment.