You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/08/29 20:31:02 UTC

[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #4549: Initial ANTL v4 Grammar Support (Syntax Highlighting)

matthiasblaesing commented on code in PR #4549:
URL: https://github.com/apache/netbeans/pull/4549#discussion_r957764830


##########
java/languages.antlr/external/binaries-list:
##########
@@ -0,0 +1,20 @@
+# 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.
+59D7B72E12E4348CBB355929696B3531FA2E54EF https://raw.githubusercontent.com/antlr/grammars-v4/293c9b2a3fef07c1b549a9ac42adfd98cf9bda4a/antlr/antlr4/ANTLRv4Lexer.g4 ANTLRv4Lexer.g4
+B64F65F798215059626B0C5551576AFB2AB250C5 https://raw.githubusercontent.com/antlr/grammars-v4/293c9b2a3fef07c1b549a9ac42adfd98cf9bda4a/antlr/antlr4/ANTLRv4Parser.g4 ANTLRv4Parser.g4
+02F57464E7D6AEE602FB9F1C07A2B51231D0F462 https://raw.githubusercontent.com/antlr/grammars-v4/293c9b2a3fef07c1b549a9ac42adfd98cf9bda4a/antlr/antlr4/LexBasic.g4 LexBasic.g4
+C69EDA58DC59224F15898669B6AE84058B2D5928 https://raw.githubusercontent.com/antlr/grammars-v4/293c9b2a3fef07c1b549a9ac42adfd98cf9bda4a/antlr/antlr4/Java/LexerAdaptor.java LexerAdaptor.java

Review Comment:
   As written above I don't think we should download these files.



##########
ide/libs.antlr4.runtime/external/binaries-list:
##########
@@ -15,3 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 E27D8AB4F984F9D186F54DA984A6AB1CCCAC755E org.antlr:antlr4-runtime:4.7.2
+93058C41A6CBB7F5CA63EDAC837F42C002DBC556 org.antlr:antlr4:4.7.2
+CD9CD41361C155F3AF0F653009DCECB08D8B4AFD org.antlr:antlr-runtime:3.5.2

Review Comment:
   Why? This is about antlr4 - so why to 3 runtime?



##########
java/java.kit/nbproject/project.xml:
##########
@@ -237,6 +237,12 @@
                         <specification-version>2.23</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.languages.antlr</code-name-base>
+                    <run-dependency>
+                        <specification-version>1.0</specification-version>
+                    </run-dependency>
+                </dependency>

Review Comment:
   Why is language support for antlr4 in the java cluster? antlr grammars can be used to generate lexers/parsers for various languages, java only one of them.



##########
.gitignore:
##########
@@ -108,3 +108,9 @@ derby.log
 /extide/gradle/netbeans-gradle-tooling/gradle/wrapper/gradle-wrapper.jar
 /extide/gradle/release/modules/gradle/daemon-loader/.gradle/
 /nbbuild/misc/prepare-bundles/target/
+
+# ANTLR v4 Grammar
+##################################
+/java/languages.antlr/external/*.g4
+/java/languages.antlr/external/LexerAdaptor.java

Review Comment:
   Why are these files downloaded at runtime? If I'm not mistaken (3-Clause BSD), we can hold them in the repository and thus don't need a build-time download (external repositories will go away)



##########
java/languages.antlr/manifest.mf:
##########
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+OpenIDE-Module: org.netbeans.modules.languages.antlr

Review Comment:
   antlr is its fourth iteration - so unless this is really support for all antlr version, I suggest to name this `org.netbeans.modules.languages.antlr4`



##########
java/languages.antlr/build.xml:
##########
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
+<!-- for some information on what you could do (e.g. targets to override). -->
+<!-- If you delete this file and reopen the project it will be recreated. -->
+<project name="java/languages.antlr" default="build" basedir=".">
+    <description>Builds, tests, and runs the project org.netbeans.modules.languages.antlr</description>
+    <import file="../../nbbuild/templates/projectized.xml"/>
+
+    <target name="antlr-generate" depends="init">
+        <path id="antlr4.tool">
+            <fileset dir="../../ide/libs.antlr4.runtime/external" includes="*.jar"/>
+        </path>
+        <property name="antlr.outdir" location="${build.dir}/parser-src/org/antlr/parser/antlr4"/>
+        <mkdir dir="${antlr.outdir}"/>
+        <copy todir="${antlr.outdir}">
+            <fileset dir="external" includes="*.g4"/>
+            <fileset dir="external" includes="*.java"/>
+        </copy>
+        <replace file="${antlr.outdir}/LexerAdaptor.java" token="//package" value="package"/>
+        <java classname="org.antlr.v4.Tool" classpathref="antlr4.tool">
+            <arg value="-o"/><arg value="${antlr.outdir}"/>
+            <arg value="-package"/><arg value="org.antlr.parser.antlr4"/>
+            <arg value="${antlr.outdir}/ANTLRv4Lexer.g4"/>
+            <!--arg value="${antlr.outdir}/ANTLRv4Parser.g4"/-->
+        </java>
+    </target>
+
+    <target name="antlr-compile" depends="antlr-generate" extensionOf="-pre-compile">
+        <property name="javac.fork" value="false"/>
+        <mkdir dir="${build.dir}/parser-classes"/>
+        <nb-javac srcdir="${build.dir}/parser-src" destdir="${build.dir}/parser-classes" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8"
+                  deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${javac.target}" includeantruntime="false"
+                  fork="${javac.fork}"
+        >
+            <classpath refid="cp"/>
+            <compilerarg line="${javac.compilerargs}"/>
+            <processorpath refid="processor.cp"/>
+        </nb-javac>
+        <mkdir dir="${build.dir}/parser"/>
+        <jar jarfile="${build.dir}/parser/antlr4-parser.jar">
+            <fileset dir="${build.dir}/parser-classes"/>
+        </jar>
+    </target>

Review Comment:
   I don't understand why the parser is not build as part of the general build of the module. Creating a secondary artifact only makes it harder to reason over it.



##########
java/languages.antlr/src/org/netbeans/modules/languages/antlr/AntlrDataObject.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.antlr;
+
+import org.netbeans.core.spi.multiview.MultiViewElement;
+import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.awt.ActionReferences;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.MIMEResolver;
+import org.openide.loaders.DataNode;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectExistsException;
+import org.openide.loaders.MultiDataObject;
+import org.openide.loaders.MultiFileLoader;
+import org.openide.nodes.Children;
+import org.openide.nodes.Node;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.windows.TopComponent;
+
+/**
+ *
+ * @author lkishalmi
+ */
+@NbBundle.Messages(
+        "ANTLRResolver=ANTLR4 Grammar"
+)
+@MIMEResolver.ExtensionRegistration(displayName = "#ANTLRResolver",
+    extension = "g4",
+    mimeType = AntlrTokenId.MIME_TYPE,
+    position = 285
+)
+
+@ActionReferences({
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
+            position = 100,
+            separatorAfter = 300
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
+            position = 400
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
+            position = 500,
+            separatorAfter = 600
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
+            position = 700
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
+            position = 800,
+            separatorAfter = 900
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
+            position = 1000,
+            separatorAfter = 1100
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
+            position = 1200,
+            separatorAfter = 1300
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
+            position = 1400
+    ),
+    @ActionReference(
+            path = "Loaders/text/x-antlr4/Actions",
+            id = @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
+            position = 1500
+    )
+})
+
+@DataObject.Registration(
+        mimeType = AntlrTokenId.MIME_TYPE,
+        displayName = "#ANTLRResolver",
+        position = 304
+)
+public class AntlrDataObject extends MultiDataObject {

Review Comment:
   I think the data object is unnecessary (see discussion around Yaml/Docker support)



-- 
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