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?
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 besrc/calculator4/*.java
.Calculator.g4
is.-lib src/calculator4
argument.-o
argument to-o ../../gen/calculator4
.Calculator.g4
as the final argument to the command.