You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "mbien (via GitHub)" <gi...@apache.org> on 2023/04/16 22:19:47 UTC

[GitHub] [netbeans] mbien commented on a diff in pull request #5612: Initial HCL Support

mbien commented on code in PR #5612:
URL: https://github.com/apache/netbeans/pull/5612#discussion_r1168035392


##########
ide/languages.hcl/src/org/netbeans/modules/languages/hcl/HCLHereDocAdaptor.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.hcl;
+
+import java.util.LinkedList;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.Lexer;
+
+/**
+ *
+ * @author Laszlo Kishalmi
+ */
+public abstract class HCLHereDocAdaptor extends Lexer {
+
+    LinkedList<String> hereDocStack = new LinkedList<>();
+    String currentHereDocVar;
+
+    public HCLHereDocAdaptor(CharStream input) {
+        super(input);
+    }
+
+    protected  void pushHereDocVar(String hereDocHead) {
+        String hereDocVar = hereDocHead.replaceAll("^<<-?", "");
+        hereDocVar = hereDocVar.substring(0, hereDocVar.length() - 1);
+        if (currentHereDocVar != null) {
+            hereDocStack.addFirst(currentHereDocVar);
+        }
+        currentHereDocVar = hereDocVar;
+    }
+
+    protected void popHereDocVar() {
+        currentHereDocVar = hereDocStack.isEmpty() ? null : hereDocStack.removeFirst();
+    }
+
+    protected boolean heredocEndAhead(String partialHeredoc) {
+        int n = 1;
+        int c = _input.LA(1);
+        while ( c == 9 || c == 32) { // Skip leading space and tabs

Review Comment:
   this is only for space and tab? not for other whitespace as in `Character.isWhitespace()`?
   
   btw you could also write this as: c == ' ' || c == '\t' which would make the comment redundant



##########
ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/HCLBlock.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.hcl.ast;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ *
+ * @author Laszlo Kishalmi
+ */
+public class HCLBlock extends HCLContainer {
+
+    final List<HCLIdentifier> declaration;
+    final String id;
+
+
+    public HCLBlock(List<HCLIdentifier> declaration) {
+        this.declaration = Collections.unmodifiableList(declaration);
+        StringBuilder idb = new StringBuilder(100);
+        String delim = "";
+        for (HCLIdentifier hi : this.declaration) {
+            idb.append(delim).append(hi.id());
+            delim = ".";
+        }
+        id = idb.toString();

Review Comment:
   potentially easier with `StringJoiner`?



##########
ide/languages.hcl/src/org/netbeans/modules/languages/hcl/AnstractHCLLexer.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.hcl;
+
+import java.text.Normalizer;
+import java.util.BitSet;
+import java.util.LinkedList;
+import java.util.function.Function;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.antlr.v4.runtime.ANTLRErrorListener;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.Parser;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
+import org.antlr.v4.runtime.atn.ATNConfigSet;
+import org.antlr.v4.runtime.dfa.DFA;
+import org.antlr.v4.runtime.misc.ParseCancellationException;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.modules.languages.hcl.grammar.HCLLexer;
+import org.netbeans.spi.lexer.LexerRestartInfo;
+import org.netbeans.spi.lexer.antlr4.AbstractAntlrLexerBridge;
+
+import static org.netbeans.modules.languages.hcl.HCLTokenId.*;
+import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.*;
+
+
+/**
+ *
+ * @author lkishalmi
+ */
+public abstract class AnstractHCLLexer extends AbstractAntlrLexerBridge<HCLHereDocAdaptor, HCLTokenId> {

Review Comment:
   typo. -> `Abstract`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists