Pregunta

I was reading a tutorial with the following ant script in build.xml

<project name="calculator4" default="generate" basedir=".">
    <property name="src" location="src" />
    <property name="gen" location="gen" />
    <property name="src" location="src" />
    <property name="package" value="calculator4" />

    <target name="generate">
        <mkdir dir="${gen}/${package}" />
        <java classname="org.antlr.v4.Tool" classpathref="classpath" fork="true">
            <arg value="-o" />
            <arg path="${gen}/${package}" />
            <arg value="-lib" />
            <arg path="${src}/${package}" />
            <arg value="-listener" />
            <arg value="${src}/${package}/Calculator.g4" />
        </java>
    </target>

As I don't know much about ant and don't want to use it, I try to translate the command to bash like so

java org.antlr.v4.Tool -o gen/calculator4 -lib src/calculator4 -listener src/calculator4/Calculator.g4

But this is wrong as it generates files in gen/calculator4/src/calculator4 as supposed to the correct behavior of generating files in gen/calculator4

Is there something special going on with ${} other than direct substitution?

¿Fue útil?

Solución

The relative path for generated files matches the relative path for input files. Since you specified src/calculator4/Calculator.g4 as the input file, the output files will be src/calculator4/*.java.

  1. Change directories so the working directory is the same folder where Calculator.g4 is.
  2. Remove the -lib src/calculator4 argument.
  3. Change the -o argument to -o ../../gen/calculator4.
  4. Pass just Calculator.g4 as the final argument to the command.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top