[antlr-interest] Antlr NetBeans support!

Krishna Praveen M. R. krsnapraveen4 at gmail.com
Thu Jul 23 00:03:03 PDT 2009


Hello Everyone:

I am an Electrical Engineer but I need to ANTLR for my project, developing
an algorithm, I have discovered that it a wonderful tool!
I need ANTLR support in NetBeans to materialize this algorithm.

I followed the instructions given on this page (to the T) :

http://www.antlr.org/wiki/display/ANTLR3/Integration+with+Development+Environments#IntegrationwithDevelopmentEnvironments-InstallandAddSupporttoProject

by I am getting errors in the build.xml :

My build.xml looks like this:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script.
-->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="MyAntlrProject" default="default" basedir=".">
    <description>Builds, tests, and runs the project
MyAntlrProject.</description>
    <import file="nbproject/build-impl.xml"/>
    <!--

    There exist several targets which are by default empty and which can be
    used for execution of your tasks. These targets are usually executed
    before and after some main targets. They are:

      -pre-init:                 called before initialization of project
properties
      -post-init:                called after initialization of project
properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single
file
      -post-compile-single:      called after javac compilation of single
file
      -pre-compile-test:         called before javac compilation of JUnit
tests
      -post-compile-test:        called after javac compilation of JUnit
tests
      -pre-compile-test-single:  called before javac compilation of single
JUnit test
      -post-compile-test-single: called after javac compilation of single
JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like
this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported
    nbproject/build-impl.xml file.


    Another way to customize the build is by overriding existing main
targets.
    The targets of interest are:

      -init-macrodef-javac:     defines macro for javac compilation
      -init-macrodef-junit:     defines macro for junit execution
      -init-macrodef-debug:     defines macro for class debugging
      -init-macrodef-java:      defines macro for class execution
      -do-jar-with-manifest:    JAR building (if you are using a manifest)
      -do-jar-without-manifest: JAR building (if you are not using a
manifest)
      run:                      execution of project
      -javadoc-build:           Javadoc generation
      test-report:              JUnit report generation

    An example of overriding the target for project execution could look
like this:

        <target name="run" depends="MyAntlrProject-impl.jar">
            <exec dir="bin" executable="launcher.exe">
                <arg file="${dist.jar}"/>
            </exec>
        </target>

    Notice that the overridden target depends on the jar target and not only
on
    the compile target as the regular run target does. Again, for a list of
available
    properties which you can use, check the target you are overriding in the
    nbproject/build-impl.xml file.

    -->
    <property name="antlr.libdir" location="D:\antlr-3.1.2\antlr-3.1.2\lib"
/>
    <property name="antlr.tooldir" location="D:\antlr-3.1.2\antlr-3.1.2\lib"
/>
    <property name="antlr.runtimedir"
location="D:\antlr-3.1.2\antlr-3.1.2\lib" />


    <patternset id="antlr.libs">
        <include name="stringtemplate-3.1.jar" />
        <include name="antlr277.jar" />
    </patternset>

    <patternset id="antlr.tool">
        <include name="antlr-3.1.2.jar" />
    </patternset>

    <patternset id="antlr.runtime">
        <include name="antlr-runtime-3.1.2.jar" />
    </patternset>

    <path id="antlr.path">
        <fileset dir="${antlr.tooldir}" casesensitive="yes">
            <patternset refid="antlr.tool" />
        </fileset>

        <fileset dir="${antlr.runtimedir}" casesensitive="yes">
            <patternset refid="antlr.runtime" />
        </fileset>

        <fileset dir="${antlr.libdir}" casesensitive="yes">
            <patternset refid="antlr.libs" />
        </fileset>
    </path>


    <target name="-pre-init">
        <taskdef resource="net/sf/antcontrib/antlib.xml"/>
    </target>


    <target name="-post-clean">
        <fileset id="antlr.grammars" dir="${src.dir}" includes="**/*.g"/>

        <pathconvert property="antlr.clean.files" pathsep=','
refid="antlr.grammars">
            <compositemapper>
                <globmapper
from="${basedir}${file.separator}${src.dir}${file.separator}*.g"
                    to="*.tokens"/>
                <globmapper
from="${basedir}${file.separator}${src.dir}${file.separator}*.g"
                    to="*Parser.java"/>
                <globmapper
from="${basedir}${file.separator}${src.dir}${file.separator}*.g"
                    to="*Lexer.java"/>
                <chainedmapper>
                    <globmapper
from="${basedir}${file.separator}${src.dir}${file.separator}*.g"
                        to="*.g"/>
                    <compositemapper>
                        <regexpmapper from="(([^/]*/)*).*\.g"
                            to="\1__Test__.java" handledirsep="true"/>
                        <regexpmapper from="(([^/]*/)*).*\.g"
                            to="\1__Test___input.txt" handledirsep="true"/>
                    </compositemapper>
                </chainedmapper>
            </compositemapper>
        </pathconvert>
        <pathconvert property="antlr.clean.dirs" pathsep=','
refid="antlr.grammars">
            <chainedmapper>
                <globmapper
from="${basedir}${file.separator}${src.dir}${file.separator}*.g"
                    to="*.g"/>
                <compositemapper>
                    <regexpmapper from="(([^/]*/)*).*\.g"
                        to="\1classes/**/*" handledirsep="true"/>
                    <regexpmapper from="(([^/]*/)*).*\.g"
                        to="\1classes" handledirsep="true"/>
                </compositemapper>
            </chainedmapper>
        </pathconvert>

        <if>
            <not>
                <equals arg1="${antlr.clean.files}" arg2=""/>
            </not>
            <then>
                <echo level="info">Cleaning ANTLR- and ANTLRWorks-generated
files (if any exist):${line.separator}</echo>
                <delete quiet="true" verbose="true">
                    <FileSet dir="${src.dir}"
includes="${antlr.clean.files}" excludes="${src.dir}"/>
                </delete>
            </then>
        </if>
        <if>
            <not>
                <equals arg1="${antlr.clean.dirs}" arg2=""/>
            </not>
            <then>
                <echo level="info">Cleaning ANTLRWorks-generated directories
(if any exist):${line.separator}</echo>
                <delete quiet="true" verbose="true" includeemptydirs="true">
                    <FileSet dir="${src.dir}" includes="${antlr.clean.dirs}"
excludes="${src.dir}"/>
                </delete>
            </then>
        </if>
    </target>


    <target name="-pre-compile-single">
        <basename property="javac.includes.base" file="${javac.includes}"/>
        <if>
            <equals arg1="${javac.includes.base}" arg2="*"/>
            <then>
                <for param="antlr.target">
                    <path>
                        <fileset dir="${src.dir}"
includes="${javac.includes}.g"/>
                    </path>
                    <sequential>
                        <antlr:antlr3
xmlns:antlr="antlib:org/apache/tools/ant/antlr"
                            target="@{antlr.target}">
                            <classpath>
                                <path refid="antlr.path" />
                            </classpath>
                        </antlr:antlr3>
                    </sequential>
                </for>
            </then>
        </if>
    </target>


    <target name="-pre-compile">
        <for param="antlr.target">
            <path>
                <fileset dir="${src.dir}" includes="**/*.g"/>
            </path>
            <sequential>
                <antlr:antlr3
xmlns:antlr="antlib:org/apache/tools/ant/antlr"
                    target="@{antlr.target}">
                    <classpath>
                        <path refid="antlr.path" />
                    </classpath>
                </antlr:antlr3>
            </sequential>
        </for>
    </target>


</project>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The errors that I am getting are:

Could not load definitions from resource net/sf/antcontrib/antlib.xml. It
could not be found.
init:
deps-clean:
C:\Users\Krishna
Praveen\Documents\NetBeansProjects\MyAntlrProject\build.xml:148: Problem:
failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
BUILD FAILED (total time: 0 seconds)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I also tried following what was given here:

http://wiki.netbeans.org/AntlrInNetBeansJavaApplication

I don't get any errors but the .java files not are created, it simply makes
a JAR file.

I really appreciate any help!!

Thank You.
Krishna!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090723/e2c677e0/attachment.html 


More information about the antlr-interest mailing list