Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing fields annotations #4

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading