Skip to content

Commit

Permalink
fix: parsing fields annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Jan 6, 2023
1 parent b35d106 commit a6e34aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void enterField(io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext ctx
var isEntity = false; // TODO
var isArray = ctx.field_type().ARRAY() != null;
var validations = processFieldValidations(ctx.field_validations());
currentStack.peek().appendTo("fields", name, new FluentMap()
var field = new FluentMap()
.with("name", name)
.with("type", type)
.with("javadoc", javadoc)
Expand All @@ -176,14 +176,17 @@ public void enterField(io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext ctx
.with("isEntity", isEntity)
.with("isArray", isArray)
.with("options", new FluentMap())
.with("validations", validations));
.with("validations", validations);
currentStack.peek().appendTo("fields", name, field);

var entityName = currentStack.peek().get("name");
var entityLocation = currentCollection + "." + entityName + ".fields." + name;
model.setLocation(entityLocation, getLocations(ctx));
model.setLocation(entityLocation + ".name", getLocations(ctx.field_name()));
model.setLocation(entityLocation + ".type", getLocations(ctx.field_type()));
model.setLocation(entityLocation + ".javadoc", getLocations(first(ctx.javadoc(), ctx.suffix_javadoc())));

currentStack.push(field);
}

private Map<String, Object> processFieldValidations(List<io.github.zenwave360.zdl.antlr.ZdlParser.Field_validationsContext> field_validations) {
Expand All @@ -203,13 +206,14 @@ private Map<String, Object> processFieldValidations(List<io.github.zenwave360.zd

@Override
public void exitField(io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext ctx) {
currentStack.pop();
super.exitField(ctx);
}

@Override
public void enterNested_field(io.github.zenwave360.zdl.antlr.ZdlParser.Nested_fieldContext ctx) {
io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext parent = (io.github.zenwave360.zdl.antlr.ZdlParser.FieldContext) ctx.getParent();
var parentEntity = currentStack.peek();
var parentEntity = currentStack.get(currentStack.size() - 2); // currentStack.peek();
var parentEntityFields = ((FluentMap) parentEntity.get("fields"));
var parentField = new ArrayList<>(parentEntityFields.values()).get(parentEntityFields.size() - 1);
String entityName = parent.field_type().ID().getText();
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/simple.zdl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ apis {
@array([1, 2, 3])
@array2(1, 2, 3)
entity Customer {
username String required unique min(5)
@dbref username String required unique min(5)
tags String[]
email String required unique max(MAX_LENGTH) pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)
}
Expand Down

0 comments on commit a6e34aa

Please sign in to comment.