You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2024/04/16 00:46:10 UTC
(netbeans) branch master updated: HCL added Scoped Function name support (Terraform 1.8)
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 8c75f2df42 HCL added Scoped Function name support (Terraform 1.8)
8c75f2df42 is described below
commit 8c75f2df4215223866aceb88fe9981c5c2ac8e81
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sun Apr 14 19:50:16 2024 -0700
HCL added Scoped Function name support (Terraform 1.8)
---
.../netbeans/modules/languages/hcl/HCLTokenId.java | 1 +
.../modules/languages/hcl/ast/HCLElementFactory.java | 8 ++++++++
.../languages/hcl/ast/HCLExpressionFactory.java | 19 +++++++++++++------
.../modules/languages/hcl/ast/HCLIdentifier.java | 2 ++
.../languages/hcl/grammar/g4/HCLExpressionParser.g4 | 10 ++++++++--
.../modules/languages/hcl/grammar/g4/HCLLexer.g4 | 9 +++++++--
6 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/HCLTokenId.java b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/HCLTokenId.java
index f214a20c06..afd23ae588 100644
--- a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/HCLTokenId.java
+++ b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/HCLTokenId.java
@@ -56,6 +56,7 @@ public enum HCLTokenId implements TokenId {
INTERPOLATION_START("${", "separator"),
INTERPOLATION_END("}", "separator"),
RARROW("=>", "separator"),
+ SCOPE("::", "separator"),
TEMPLATE_START("%{", "separator"),
TEMPLATE_END("}", "separator"),
diff --git a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLElementFactory.java b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLElementFactory.java
index 3b84857a1f..03058ff880 100644
--- a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLElementFactory.java
+++ b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLElementFactory.java
@@ -23,6 +23,7 @@ import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.netbeans.modules.languages.hcl.grammar.HCLLexer;
+import org.netbeans.modules.languages.hcl.grammar.HCLParser;
/**
*
@@ -41,6 +42,13 @@ public sealed abstract class HCLElementFactory permits HCLBlockFactory, HCLExpre
return tn != null ? id(tn.getSymbol()) : null;
}
+ protected final HCLIdentifier id(HCLParser.ScopedIdContext ctx) {
+ HCLIdentifier parent = ctx.target != null
+ ? id(ctx.target)
+ : id(ctx.scopedId());
+ return created(new HCLIdentifier.ScopedId(parent, ctx.ref.getText()), ctx);
+ }
+
protected final HCLIdentifier id(Token t) {
return (t != null) && (t.getType() == HCLLexer.IDENTIFIER) ? created(new HCLIdentifier.SimpleId(t.getText()), t) : null;
}
diff --git a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLExpressionFactory.java b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLExpressionFactory.java
index 455ae4806b..cca7c87026 100644
--- a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLExpressionFactory.java
+++ b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLExpressionFactory.java
@@ -27,6 +27,7 @@ import java.util.function.Consumer;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.TerminalNode;
import org.netbeans.modules.languages.hcl.grammar.HCLLexer;
import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.*;
import org.netbeans.modules.languages.hcl.grammar.HCLParser;
@@ -175,16 +176,22 @@ public final class HCLExpressionFactory extends HCLElementFactory {
if (ctx == null) {
return null;
}
- List<HCLExpression> args = Collections.emptyList();
+ if (ctx.exception != null) {
+ return null;
+ }
+ List<HCLExpression> args = List.of();
boolean expand = false;
if (ctx.arguments() != null) {
- args = new ArrayList<>(ctx.arguments().expression().size());
- for (HCLParser.ExpressionContext ectx : ctx.arguments().expression()) {
- args.add(expr(ectx));
- }
+ args = ctx.arguments().expression().stream()
+ .map(this::expr)
+ .toList();
expand = ctx.arguments().ELLIPSIS() != null;
}
- return created(new HCLFunction(id(ctx.IDENTIFIER()), args, expand), ctx);
+ HCLIdentifier name = ctx.IDENTIFIER() != null
+ ? id(ctx.IDENTIFIER())
+ : id(ctx.scopedId());
+
+ return created(new HCLFunction(name, args, expand), ctx);
}
private static HCLArithmeticOperation.Operator binOp(int tokenType) {
diff --git a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLIdentifier.java b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLIdentifier.java
index 1dd48e8ad5..ad25ab30e0 100644
--- a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLIdentifier.java
+++ b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLIdentifier.java
@@ -36,4 +36,6 @@ public sealed interface HCLIdentifier extends HCLElement {
public record SimpleId(String id) implements HCLIdentifier {}
public record StringId(String id) implements HCLIdentifier {}
+
+ public record ScopedId(HCLIdentifier parent, String id) implements HCLIdentifier {}
}
diff --git a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLExpressionParser.g4 b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLExpressionParser.g4
index aa5bd8e6f1..4297ffd4c0 100644
--- a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLExpressionParser.g4
+++ b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLExpressionParser.g4
@@ -128,13 +128,19 @@ heredoc
: HEREDOC_START heredocTemplate HEREDOC_END
;
+// This is not part of the HCL spec, though used in Terraform 1.8 for function calls
+scopedId
+ : target=IDENTIFIER SCOPE ref=IDENTIFIER
+ | scopedId SCOPE ref=IDENTIFIER
+ ;
+
variableExpr
: IDENTIFIER
;
functionCall
- : IDENTIFIER LPAREN arguments RPAREN
- | IDENTIFIER LPAREN RPAREN
+ : (IDENTIFIER|scopedId) LPAREN arguments RPAREN
+ | (IDENTIFIER|scopedId) LPAREN RPAREN
;
arguments
diff --git a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLLexer.g4 b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLLexer.g4
index dad41f9550..b5a70f0f65 100644
--- a/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLLexer.g4
+++ b/ide/languages.hcl/src/org/netbeans/modules/languages/hcl/grammar/g4/HCLLexer.g4
@@ -86,6 +86,11 @@ QUESTION
: Question
;
+// Used from Terraform 1.8 in provider exported function names
+SCOPE
+ : Colon Colon
+ ;
+
COLON
: Colon
;
@@ -123,8 +128,8 @@ ELLIPSIS
;
LEGACY_INDEX
- : Dot DecDigit+
- ;
+ : Dot DecDigit+
+ ;
DOT
: Dot
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists