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 typo in the antlr grammar #840

Merged
merged 1 commit into from
Dec 19, 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 @@ -53,10 +53,10 @@ dtoBody

explicitProp
:
micro | aliasGroup | positiveProp | negativeProp | userProp
macro | aliasGroup | positiveProp | negativeProp | userProp
;

micro
macro
:
'#' name=Identifier
(
Expand All @@ -83,7 +83,7 @@ aliasPattern

aliasGroupProp
:
micro | positiveProp
macro | positiveProp
;

positiveProp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class DtoTypeBuilder<T extends BaseType, P extends BaseProp> {
}

for (DtoParser.ExplicitPropContext prop : body.explicitProps) {
if (prop.micro() != null) {
handleMicro(prop.micro());
if (prop.macro() != null) {
handleMacro(prop.macro());
} else if (prop.aliasGroup() != null) {
handleAliasGroup(prop.aliasGroup());
} else if (prop.positiveProp() != null) {
Expand Down Expand Up @@ -163,36 +163,36 @@ private DtoTypeBuilder(DtoTypeBuilder<T, P> base, Set<DtoPropBuilder<T, P>> remo
this.aliasPositivePropMap = aliasPositiveMap;
}

private void handleMicro(DtoParser.MicroContext micro) {
boolean isAllReferences = micro.name.getText().equals("allReferences");
if (!micro.name.getText().equals("allScalars") && !isAllReferences) {
private void handleMacro(DtoParser.MacroContext macro) {
boolean isAllReferences = macro.name.getText().equals("allReferences");
if (!macro.name.getText().equals("allScalars") && !isAllReferences) {
throw ctx.exception(
micro.name.getLine(),
micro.name.getCharPositionInLine(),
"Illegal micro name \"" +
micro.name.getText() +
macro.name.getLine(),
macro.name.getCharPositionInLine(),
"Illegal macro name \"" +
macro.name.getText() +
"\", it must be \"#allScalars\" or \"#allReferences\""
);
}

if (!positivePropMap.isEmpty() || !negativePropAliasMap.isEmpty()) {
throw ctx.exception(
micro.name.getLine(),
micro.name.getCharPositionInLine(),
macro.name.getLine(),
macro.name.getCharPositionInLine(),
"`#" +
micro.name +
macro.name +
"` must be defined at the beginning"
);
}

Mandatory mandatory;
if (micro.required != null) {
if (macro.required != null) {
mandatory = Mandatory.REQUIRED;
} else if (micro.optional != null) {
} else if (macro.optional != null) {
if (modifiers.contains(DtoModifier.SPECIFICATION)) {
throw ctx.exception(
micro.name.getLine(),
micro.name.getCharPositionInLine(),
macro.name.getLine(),
macro.name.getCharPositionInLine(),
"Unnecessary optional modifier '?', all properties of specification are automatically optional"
);
}
Expand All @@ -206,16 +206,16 @@ private void handleMicro(DtoParser.MicroContext micro) {
.findFirst()
.orElse(DtoModifier.STATIC);

if (micro.args.isEmpty()) {
if (macro.args.isEmpty()) {
for (P baseProp : ctx.getProps(baseType).values()) {
if (isAllReferences ? isAutoReference(baseProp) : isAutoScalar(baseProp)) {
DtoPropBuilder<T, P> propBuilder =
new DtoPropBuilder<>(
this,
currentAliasGroup,
baseProp,
micro.start.getLine(),
micro.start.getCharPositionInLine(),
macro.start.getLine(),
macro.start.getCharPositionInLine(),
isAllReferences ? "id" : null,
mandatory,
inputModifier,
Expand All @@ -229,7 +229,7 @@ private void handleMicro(DtoParser.MicroContext micro) {
Map<String, Set<T>> nameTypeMap = new HashMap<>();
collectSuperTypes(baseType, qualifiedNameTypeMap, nameTypeMap);
Set<T> handledBaseTypes = new LinkedHashSet<>();
for (DtoParser.QualifiedNameContext qnCtx : micro.args) {
for (DtoParser.QualifiedNameContext qnCtx : macro.args) {
String qualifiedName = qnCtx.parts.stream().map(Token::getText).collect(Collectors.joining("."));
T baseType = qualifiedName.equals("this") ? this.baseType : qualifiedNameTypeMap.get(qualifiedName);
if (baseType == null) {
Expand Down Expand Up @@ -377,8 +377,8 @@ private void handleAliasGroup(DtoParser.AliasGroupContext group) {
currentAliasGroup = new AliasPattern(ctx, group.pattern);
try {
for (DtoParser.AliasGroupPropContext prop : group.props) {
if (prop.micro() != null) {
handleMicro(prop.micro());
if (prop.macro() != null) {
handleMacro(prop.macro());
} else {
handlePositiveProp(prop.positiveProp());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
Expand Down Expand Up @@ -221,7 +220,7 @@ public void testAllReferencesWithOverride() {
}

@Test
public void testMixedMicro() {
public void testMixedMacro() {
List<DtoType<BaseType, BaseProp>> dtoTypes = MyDtoCompiler.book(
"input BookInput {\n" +
" #allScalars(this)" +
Expand Down