discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

unexpected error from command line -D $fn=8

TA
Todd Allen
Fri, Mar 7, 2025 12:14 AM

I made a file x.scad with a single line:
cylinder();

On the command line I executed:
openscad x.scad -o x.stl -D $fn=8

which generates:
ERROR: Parser error: syntax error in file x.scad, line 4
Can't parse file 'x.scad'!

Despite the unhelpful error message I thought to try a '' in front of the
'$' (I'm using linux) which fixes the problem and I got my expected result.

I believe what openscad saw without the '' was -D =8 for which I'd expect
an error message about a bad parameter rather than the error I got.

I made a file x.scad with a single line: cylinder(); On the command line I executed: openscad x.scad -o x.stl -D $fn=8 which generates: ERROR: Parser error: syntax error in file x.scad, line 4 Can't parse file 'x.scad'! Despite the unhelpful error message I thought to try a '\' in front of the '$' (I'm using linux) which fixes the problem and I got my expected result. I believe what openscad saw without the '\' was -D =8 for which I'd expect an error message about a bad parameter rather than the error I got.
JB
Jordan Brown
Fri, Mar 7, 2025 1:18 AM

On 3/6/2025 4:14 PM, Todd Allen via Discuss wrote:

I made a file x.scad with a single line:
cylinder();

On the command line I executed:
openscad x.scad -o x.stl -D $fn=8

which generates:
ERROR: Parser error: syntax error in file x.scad, line 4
Can't parse file 'x.scad'!

Despite the unhelpful error message I thought to try a '' in front of
the '$' (I'm using linux) which fixes the problem and I got my
expected result.

I believe what openscad saw without the '' was -D =8 for which I'd
expect an error message about a bad parameter rather than the error I got.

I trust that you know that the need for a backslash or wrapping the
value in single quotes derives entirely from the shell's handling of the
dollar sign, and is totally unrelated to the program you're running. 
You'll see the same if you say "echo x.scad -o x.stl -D $fn=8".

-D options don't exactly set values.  They are simply appended to the
program, with some magic that allows them to override settings in the
program without triggering an error.

They can contain any statement, not just assignments.

Maybe they should be restricted to assignments, so that they can give
better error messages.  But I'm sure somebody out there is using this
feature, e.g. to externally control which module gets invoked by saying

-D 'foo()'

versus

-D 'bar()'

Note that, again, the shell requires the quotes because of the parentheses.

On 3/6/2025 4:14 PM, Todd Allen via Discuss wrote: > I made a file x.scad with a single line: > cylinder(); > > On the command line I executed: > openscad x.scad -o x.stl -D $fn=8 > > which generates: > ERROR: Parser error: syntax error in file x.scad, line 4 > Can't parse file 'x.scad'! > > Despite the unhelpful error message I thought to try a '\' in front of > the '$' (I'm using linux) which fixes the problem and I got my > expected result. > > I believe what openscad saw without the '\' was -D =8 for which I'd > expect an error message about a bad parameter rather than the error I got. I trust that you know that the need for a backslash or wrapping the value in single quotes derives entirely from the shell's handling of the dollar sign, and is totally unrelated to the program you're running.  You'll see the same if you say "echo x.scad -o x.stl -D $fn=8". -D options don't exactly set values.  They are simply appended to the program, with some magic that allows them to override settings in the program without triggering an error. They can contain any statement, not just assignments. Maybe they *should* be restricted to assignments, so that they can give better error messages.  But I'm sure somebody out there is using this feature, e.g. to externally control which module gets invoked by saying -D 'foo()' versus -D 'bar()' Note that, again, the shell requires the quotes because of the parentheses.
TA
Todd Allen
Fri, Mar 7, 2025 2:54 AM

Thanks for the explanation. Now the error message makes more sense. But I
expect others will also get confused by this.  I originally encountered it
in a more complex situation and had to boil it down to the example I posted
before it dawned on me the shell was changing the parameter as the error
message had me thinking it was something else.

On Thu, Mar 6, 2025, 7:18 PM Jordan Brown openscad@jordan.maileater.net
wrote:

On 3/6/2025 4:14 PM, Todd Allen via Discuss wrote:

I made a file x.scad with a single line:
cylinder();

On the command line I executed:
openscad x.scad -o x.stl -D $fn=8

which generates:
ERROR: Parser error: syntax error in file x.scad, line 4
Can't parse file 'x.scad'!

Despite the unhelpful error message I thought to try a '' in front of the
'$' (I'm using linux) which fixes the problem and I got my expected result.

I believe what openscad saw without the '' was -D =8 for which I'd expect
an error message about a bad parameter rather than the error I got.

I trust that you know that the need for a backslash or wrapping the value
in single quotes derives entirely from the shell's handling of the dollar
sign, and is totally unrelated to the program you're running.  You'll see
the same if you say "echo x.scad -o x.stl -D $fn=8".

-D options don't exactly set values.  They are simply appended to the
program, with some magic that allows them to override settings in the
program without triggering an error.

They can contain any statement, not just assignments.

Maybe they should be restricted to assignments, so that they can give
better error messages.  But I'm sure somebody out there is using this
feature, e.g. to externally control which module gets invoked by saying

-D 'foo()'

versus

-D 'bar()'

Note that, again, the shell requires the quotes because of the parentheses.

Thanks for the explanation. Now the error message makes more sense. But I expect others will also get confused by this. I originally encountered it in a more complex situation and had to boil it down to the example I posted before it dawned on me the shell was changing the parameter as the error message had me thinking it was something else. On Thu, Mar 6, 2025, 7:18 PM Jordan Brown <openscad@jordan.maileater.net> wrote: > On 3/6/2025 4:14 PM, Todd Allen via Discuss wrote: > > I made a file x.scad with a single line: > cylinder(); > > On the command line I executed: > openscad x.scad -o x.stl -D $fn=8 > > which generates: > ERROR: Parser error: syntax error in file x.scad, line 4 > Can't parse file 'x.scad'! > > Despite the unhelpful error message I thought to try a '\' in front of the > '$' (I'm using linux) which fixes the problem and I got my expected result. > > I believe what openscad saw without the '\' was -D =8 for which I'd expect > an error message about a bad parameter rather than the error I got. > > > I trust that you know that the need for a backslash or wrapping the value > in single quotes derives entirely from the shell's handling of the dollar > sign, and is totally unrelated to the program you're running. You'll see > the same if you say "echo x.scad -o x.stl -D $fn=8". > > > -D options don't exactly set values. They are simply appended to the > program, with some magic that allows them to override settings in the > program without triggering an error. > > They can contain any statement, not just assignments. > > Maybe they *should* be restricted to assignments, so that they can give > better error messages. But I'm sure somebody out there is using this > feature, e.g. to externally control which module gets invoked by saying > > -D 'foo()' > > versus > > -D 'bar()' > > Note that, again, the shell requires the quotes because of the parentheses. > >
JB
Jordan Brown
Fri, Mar 7, 2025 5:44 AM

On 3/6/2025 6:54 PM, Todd Allen wrote:

Thanks for the explanation. Now the error message makes more sense.
But I expect others will also get confused by this.  I originally
encountered it in a more complex situation and had to boil it down to
the example I posted before it dawned on me the shell was changing the
parameter as the error message had me thinking it was something else.

One thing it probably could do (he says without looking at all at the
difficulty involved) would be to have the location of the error be
more explicit.  It seems like it could know that those statements were
coming from -D options rather than from the file.

Maybe it could say, for instance:

ERROR: Parser error: syntax error in -D command line options, line 4

(Though dropping out the word "file" might be tough.)

Maybe the CLI error report could include the actual problematic line. 
You don't really need that in the GUI, but it might be helpful in the CLI.

On 3/6/2025 6:54 PM, Todd Allen wrote: > Thanks for the explanation. Now the error message makes more sense. > But I expect others will also get confused by this.  I originally > encountered it in a more complex situation and had to boil it down to > the example I posted before it dawned on me the shell was changing the > parameter as the error message had me thinking it was something else. One thing it probably could do (he says without looking at all at the difficulty involved) would be to have the *location* of the error be more explicit.  It seems like it could know that those statements were coming from -D options rather than from the file. Maybe it could say, for instance: ERROR: Parser error: syntax error in -D command line options, line 4 (Though dropping out the word "file" might be tough.) Maybe the CLI error report could include the actual problematic line.  You don't really need that in the GUI, but it might be helpful in the CLI.