Skip to content

Commit

Permalink
Added ANTLR based Go Parser module
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed Jan 15, 2023
1 parent 595660f commit 3deb9cd
Show file tree
Hide file tree
Showing 17 changed files with 14,033 additions and 0 deletions.
104 changes: 104 additions & 0 deletions ide/go.lang/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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="ide/go.lang" default="build" basedir=".">
<description>Builds, tests, and runs the project org.netbeans.modules.languages.golang</description>
<import file="../../nbbuild/templates/projectized.xml"/>

<target name="download-golang-grammar" depends="init">
<property name="apache.license.header">
/*
* 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.
*/

// DO NOT EDIT THIS FILE MANUALLY!
// SEE build.xml FOR INSTRUCTIONS

</property>
<property name="golang.additionalheader">

@header{
${apache.license.header}
package org.antlr.parser.golang;

}

</property>

<property name="golang.outdir" location="${src.dir}/org/antlr/parser/golang"/>
<mkdir dir="${golang.outdir}"/>

<get src="https://raw.githubusercontent.com/antlr/grammars-v4/${golang.grammar.version}/golang/GoLexer.g4" dest="${golang.outdir}"/>
<get src="https://raw.githubusercontent.com/antlr/grammars-v4/${golang.grammar.version}/golang/GoParser.g4" dest="${golang.outdir}"/>
<get src="https://raw.githubusercontent.com/antlr/grammars-v4/${golang.grammar.version}/golang/Java/GoParserBase.java" dest="${golang.outdir}"/>

<replace file="${golang.outdir}/GoParserBase.java">
<replacetoken><![CDATA[import java.util.List;]]></replacetoken>
<replacevalue><![CDATA[package org.antlr.parser.golang;
import java.util.List;]]></replacevalue>
</replace>

<replaceregexp match="(parser|lexer) grammar ([^;]+);([\n\r]*)"
replace="\1 grammar \2;${golang.additionalheader}"
flags="g"
>
<fileset dir="${golang.outdir}" includes="GoParser.g4 GoLexer.g4" />
</replaceregexp>
</target>

<target name="generate-golang-parser" description="Regenerate the Go parser" depends="init">
<property name="golang.outdir" location="${src.dir}/org/antlr/parser/golang"/>
<path id="antlr4.tool">
<fileset dir="../../ide/libs.antlr4.runtime/external" includes="*.jar"/>
<fileset dir="../../ide/libs.antlr3.runtime/external" includes="antlr-runtime-*.jar"/>
</path>

<java classname="org.antlr.v4.Tool" classpathref="antlr4.tool" fork="true" dir="${golang.outdir}">
<arg value="-o"/>
<arg value="${golang.outdir}"/>
<arg value="-visitor"/>
<arg value="GoLexer.g4"/>
<arg value="GoParser.g4"/>
</java>

<delete dir="${golang.outdir}" includes="*.tokens"/>
<delete dir="${golang.outdir}" includes="*.interp"/>

</target>
</project>
29 changes: 29 additions & 0 deletions ide/go.lang/licenseinfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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.
-->
<licenseinfo>
<fileset>
<file>src/org/antlr/parser/golang/GoLexer.g4</file>
<file>src/org/antlr/parser/golang/GoParser.g4</file>
<file>src/org/antlr/parser/golang/GoParserBase.java</file>
<license ref="BSD-antlr-go-grammar" />
</fileset>
</licenseinfo>
5 changes: 5 additions & 0 deletions ide/go.lang/manifest.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.go.lang
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/go/lang/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0
AutoUpdate-Show-In-Client: true
22 changes: 22 additions & 0 deletions ide/go.lang/nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.
javac.source=1.8

# As of 2nd Jan 2023, we use the Grammar from:
# https://github.com/antlr/grammars-v4/tree/4794c0c5371ce6b0711a306256f8f7706394ec6d/golang
#
golang.grammar.version=4794c0c5371ce6b0711a306256f8f7706394ec6d
43 changes: 43 additions & 0 deletions ide/go.lang/nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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.
-->
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>org.netbeans.modules.go.lang</code-name-base>
<module-dependencies>
<dependency>
<code-name-base>org.netbeans.libs.antlr4.runtime</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>1.20</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages>
<package>org.antlr.parser.golang</package>
</public-packages>
</data>
</configuration>
</project>
Loading

0 comments on commit 3deb9cd

Please sign in to comment.