Skip to content
Closed
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
4 changes: 2 additions & 2 deletions rewrite-hcl/src/main/antlr/HCLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bodyContent
;

attribute
: (Identifier | NULL) ASSIGN expression
: (Identifier | NULL | IF | IN) ASSIGN expression
;

block
Expand Down Expand Up @@ -91,7 +91,7 @@ objectelem
;

qualifiedIdentifier
: Identifier (DOT Identifier)*
: (Identifier | IF | IN) (DOT (Identifier | IF | IN))*
;

// For Expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Hcl visitAttribute(HCLParser.AttributeContext ctx) {
randomId(),
Space.format(prefix),
Markers.EMPTY,
c.Identifier() != null ? visitIdentifier(c.Identifier()) : visitIdentifier(c.NULL()),
visitIdentifier(attributeNameToken(c)),
new HclLeftPadded<>(
sourceBefore("="),
Hcl.Attribute.Type.Assignment,
Expand All @@ -82,6 +82,33 @@ public Hcl visitAttribute(HCLParser.AttributeContext ctx) {
));
}

private static TerminalNode attributeNameToken(HCLParser.AttributeContext ctx) {
if (ctx.Identifier() != null) {
return ctx.Identifier();
} else if (ctx.NULL() != null) {
return ctx.NULL();
} else if (ctx.IF() != null) {
return ctx.IF();
} else if (ctx.IN() != null) {
return ctx.IN();
}
throw new IllegalStateException("Unexpected attribute name token in: " + ctx.getText());
}

private static List<TerminalNode> qualifiedIdentifierNames(HCLParser.QualifiedIdentifierContext ctx) {
List<TerminalNode> names = new ArrayList<>();
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof TerminalNode) {
int type = ((TerminalNode) child).getSymbol().getType();
if (type != HCLParser.DOT) {
names.add((TerminalNode) child);
}
}
}
return names;
}

@Override
public Hcl visitAttributeAccessExpression(HCLParser.AttributeAccessExpressionContext ctx) {
return convert(ctx, (c, prefix) -> new Hcl.AttributeAccess(
Expand Down Expand Up @@ -744,7 +771,7 @@ public Hcl visitVariableExpr(HCLParser.VariableExprContext ctx) {
if (ctx == null) {
return null;
}
List<TerminalNode> identifiers = ctx.Identifier();
List<TerminalNode> identifiers = qualifiedIdentifierNames(ctx);
if (identifiers.size() == 1) {
return visitIdentifier(identifiers.get(0));
}
Expand Down

Large diffs are not rendered by default.

Loading