assert documentation.

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

assert documentation.

nophead
The wiki documentation for assert only shows the statement form. I found that it also works as a function in an expression. In fact it is like the echo function in that is can be followed by an expression as well to give a value.

I tried to update the wiki but it doesn't like my IP address.

I used it in a function by putting it in a let. I now realise I could just put it anywhere, but why does let allow an expression on its own without an assignment?

E.g. this gives no error or warning:
let(42);

let(1,2,3); gives:

WARNING: Ignoring duplicate variable assignment = 2

WARNING: Ignoring duplicate variable assignment = 3


which is puzzling. It behaves as if it assigns to an anonymous variable.









_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

MichaelPFrey
On 22.01.19 23:40, nop head wrote:
The wiki documentation for assert only shows the statement form. I found that it also works as a function in an expression. In fact it is like the echo function in that is can be followed by an expression as well to give a value.
Assert is a parser passed. The parser it self is GNU/Bison based. This sometimes leads to very interesting - but also very consistent - consequences.
E.g. this gives no error or warning:
let(42);

We can always add a warning, which seams like a sensible thing to do in that case.

I will dwell a bit on that and then get to work.

let(1,2,3); gives:

WARNING: Ignoring duplicate variable assignment = 2

WARNING: Ignoring duplicate variable assignment = 3

which is puzzling. It behaves as if it assigns to an anonymous variable.

I would not call it anonymous variable, it is really "" as in empty string as the variable name.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

nophead
Isn't the let thing a syntax error? I.e. the arguments to let should be assignment statements with name = expression, not just an expression. let(a 42), let(a =)  and let(=42) are all syntax errors as expected.

On Wed, 23 Jan 2019 at 12:15, Michael Frey <[hidden email]> wrote:
On 22.01.19 23:40, nop head wrote:
The wiki documentation for assert only shows the statement form. I found that it also works as a function in an expression. In fact it is like the echo function in that is can be followed by an expression as well to give a value.
Assert is a parser passed. The parser it self is GNU/Bison based. This sometimes leads to very interesting - but also very consistent - consequences.
E.g. this gives no error or warning:
let(42);

We can always add a warning, which seams like a sensible thing to do in that case.

I will dwell a bit on that and then get to work.

let(1,2,3); gives:

WARNING: Ignoring duplicate variable assignment = 2

WARNING: Ignoring duplicate variable assignment = 3

which is puzzling. It behaves as if it assigns to an anonymous variable.

I would not call it anonymous variable, it is really "" as in empty string as the variable name.
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

MichaelPFrey
In reply to this post by nophead
On 23.01.19 13:30, nop head wrote:
> Isn't the let thing a syntax error? I.e. the arguments to let should
> be assignment statements with name = expression, not just an
> expression. let(a 42), let(a =)  and let(=42) are all syntax errors as
> expected.
>
You can see it that way. Either we catch that during parsing or during
runtime.
Catching it in the parser requires more work, then catching it during
runtime.

Hm - I think you right, I'll give modifying the parser a try.

With kind regards,

Michael Frey


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

nophead
Yes it looks like a parser bug to me because there is no equals sign. I don't
know how it gets an empty variable name and carries on. If you actually give
it an equals sign without a variable name it does give a syntax error.

The grammer here http://files.openscad.org/grammar.xhtml says it should be
ID = expr. How does the parser not give an error for just expr?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

MichaelPFrey
On 23.01.19 19:16, nophead wrote:
> Yes it looks like a parser bug to me because there is no equals sign. I don't
> know how it gets an empty variable name and carries on. If you actually give
> it an equals sign without a variable name it does give a syntax error.
>
> The grammer here http://files.openscad.org/grammar.xhtml says it should be
> ID = expr. How does the parser not give an error for just expr?
>

Modules and Functions accept named and unnamed variables.

TOK_LET beeing a valid module identifier:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L341-L345

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L351-L351

That is why I can not easily change the parser.

Any way: Let has has two more forms:

Expression:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L490

and list_comprehension_element:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L521

Eitherway, let takes arguments_call:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L628

which consists of many argument_call

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L647

and there is cause:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L648-L651

Note that we need this for unnamed parameters for functions and modules
calls.

To resolve the issue with let, we would need to duplicate/modify those
data structures.

I do not like the idea of increasing the parser complexity by
duplicating part of it.


I know that it is kind of hard to follow this links and my description,
but that is the nature of GNU/Bison parsers.

It takes time getting used to reading them.


With kind regards,

Michael Frey


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

Ronaldo
In reply to this post by nophead
"Let" is not the only strange case. The following expressions are syntactically acceptable too:

for( 0!=1 );
for( i=[0:10], i!=2);

but do not expect any reasonable semantics they might induce.

Em qua, 23 de jan de 2019 às 18:17, nophead <[hidden email]> escreveu:
Yes it looks like a parser bug to me because there is no equals sign. I don't
know how it gets an empty variable name and carries on. If you actually give
it an equals sign without a variable name it does give a syntax error.

The grammer here http://files.openscad.org/grammar.xhtml says it should be
ID = expr. How does the parser not give an error for just expr?

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

nophead
In reply to this post by MichaelPFrey
So the grammar documentation I found has nothing to do with the parser? That grammar says let takes statements not arguments_call. That is the bug.

On Wed, 23 Jan 2019 at 20:41, Michael Frey <[hidden email]> wrote:
On 23.01.19 19:16, nophead wrote:
> Yes it looks like a parser bug to me because there is no equals sign. I don't
> know how it gets an empty variable name and carries on. If you actually give
> it an equals sign without a variable name it does give a syntax error.
>
> The grammer here http://files.openscad.org/grammar.xhtml says it should be
> ID = expr. How does the parser not give an error for just expr?
>

Modules and Functions accept named and unnamed variables.

TOK_LET beeing a valid module identifier:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L341-L345

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L351-L351

That is why I can not easily change the parser.

Any way: Let has has two more forms:

Expression:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L490

and list_comprehension_element:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L521

Eitherway, let takes arguments_call:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L628

which consists of many argument_call

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L647

and there is cause:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L648-L651

Note that we need this for unnamed parameters for functions and modules
calls.

To resolve the issue with let, we would need to duplicate/modify those
data structures.

I do not like the idea of increasing the parser complexity by
duplicating part of it.


I know that it is kind of hard to follow this links and my description,
but that is the nature of GNU/Bison parsers.

It takes time getting used to reading them.


With kind regards,

Michael Frey


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

nophead
Sorry, I meant assignments, not arguments_call.

On Wed, 23 Jan 2019 at 20:50, nop head <[hidden email]> wrote:
So the grammar documentation I found has nothing to do with the parser? That grammar says let takes statements not arguments_call. That is the bug.

On Wed, 23 Jan 2019 at 20:41, Michael Frey <[hidden email]> wrote:
On 23.01.19 19:16, nophead wrote:
> Yes it looks like a parser bug to me because there is no equals sign. I don't
> know how it gets an empty variable name and carries on. If you actually give
> it an equals sign without a variable name it does give a syntax error.
>
> The grammer here http://files.openscad.org/grammar.xhtml says it should be
> ID = expr. How does the parser not give an error for just expr?
>

Modules and Functions accept named and unnamed variables.

TOK_LET beeing a valid module identifier:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L341-L345

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L351-L351

That is why I can not easily change the parser.

Any way: Let has has two more forms:

Expression:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L490

and list_comprehension_element:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L521

Eitherway, let takes arguments_call:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L628

which consists of many argument_call

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L647

and there is cause:

https://github.com/openscad/openscad/blob/9f861b119fa61c0027e657c452ce02549affc500/src/parser.y#L648-L651

Note that we need this for unnamed parameters for functions and modules
calls.

To resolve the issue with let, we would need to duplicate/modify those
data structures.

I do not like the idea of increasing the parser complexity by
duplicating part of it.


I know that it is kind of hard to follow this links and my description,
but that is the nature of GNU/Bison parsers.

It takes time getting used to reading them.


With kind regards,

Michael Frey


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

kintel
Administrator
In reply to this post by nophead
> On Jan 23, 2019, at 15:50, nop head <[hidden email]> wrote:
>
> So the grammar documentation I found has nothing to do with the parser? That grammar says let takes statements not arguments_call. That is the bug.
>
I cannot remember how I generated that diagram. It probably was an experiment where I tried to describe the grammar using EBNF or smth., but didn't fully encode the OpenSCAD grammar..

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

nophead
Is it easy to change the parser to match the grammar? I can't see why let should use the arguments_call rule.

On Sat, 26 Jan 2019 at 18:02, Marius Kintel <[hidden email]> wrote:
> On Jan 23, 2019, at 15:50, nop head <[hidden email]> wrote:
>
> So the grammar documentation I found has nothing to do with the parser? That grammar says let takes statements not arguments_call. That is the bug.
>
I cannot remember how I generated that diagram. It probably was an experiment where I tried to describe the grammar using EBNF or smth., but didn't fully encode the OpenSCAD grammar..

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

kintel
Administrator
> On Jan 26, 2019, at 13:07, nop head <[hidden email]> wrote:
>
> Is it easy to change the parser to match the grammar? I can't see why let should use the arguments_call rule.
>
The let() function yes, but the let() module isn't part of the grammar it's just a built-in module.

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

nophead
Oh I see, that is why it has grammar of a module call, which is similar to assignments but not quite correct.

On Sat, 26 Jan 2019 at 18:13, Marius Kintel <[hidden email]> wrote:
> On Jan 26, 2019, at 13:07, nop head <[hidden email]> wrote:
>
> Is it easy to change the parser to match the grammar? I can't see why let should use the arguments_call rule.
>
The let() function yes, but the let() module isn't part of the grammar it's just a built-in module.

 -Marius


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

doug.moen
In reply to this post by MichaelPFrey
Michael Frey wrote:
> I do not like the idea of increasing the parser complexity by
> duplicating part of it.

Do you actually need to change the parser in order to issue the error messages that nop head has asked for? Why not issue the error messages at run time? These would be actual syntax error messages that terminate the program, instead of warnings.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: assert documentation.

MichaelPFrey
On 26.01.19 19:58, Doug Moen wrote:
> Michael Frey wrote:
>> I do not like the idea of increasing the parser complexity by
>> duplicating part of it.
> Do you actually need to change the parser in order to issue the error messages that nop head has asked for? Why not issue the error messages at run time? These would be actual syntax error messages that terminate the program, instead of warnings.

There is no need to touch the parser and I implemented it in runtime:

https://github.com/openscad/openscad/pull/2720

Having that runtime check might also catch other weird things in the
future, so that  is the right thing in some regards "anyway".


If it would have been easy, implementing it in the parser would cause
the warning to appear earlier.

Warning earlier is usually a good idea, as "at the earliest detectable
point in time" we tend to have access to most relevant information.
Catching issues later can force us to weird error messages, where we can
only explain the symptom, not the cause.

Also the parser is able to mark the line that has the error. (not just
output the line number)


With Kind Regards,

Michael Frey


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org