Page 1 of 1

How to allow ( ) in func parameters ?

Posted: 27.12.2015 17:31
by runsun
I have the following OpenSCAD code:

Code: Select all

function f1( c,d=0,k=[] )=
    <statements>
;
I was able to make a foldable for it with a common symbol parser [\{\},\<\>;\#\(\)\[\]=\.\*\+\$-\?/&] and 2 rules:

Code: Select all

  rule_func<id>(..)=...

       0 Equal <symbol> =
       1 Equal <symbol> )
       2 Skip   < all tokens >
       3 Equal <symbol> (
       4 Equal <Identifier>
       5 Equal <Identifier> function

  rule_;

       0 Equal <symbol> ;
However, it fails when a (..) is given in the function parameter:

Code: Select all

function f1( c,d=0,k=[] 
            , a=get(3)      // <====== the ( ) causes it to fail
            )=
    <statements>
;
How could I make it to work ?

Posted: 27.12.2015 19:08
by Alexey
this cannot be done with skip. () inside (). so u need grammar. one grammar rule is Par and one Func which uses "(" Par ")"

Posted: 27.12.2015 23:45
by runsun
Alexey wrote:this cannot be done with skip. () inside (). so u need grammar. one grammar rule is Par and one Func which uses "(" Par ")"
Thx. I tried this:

Code: Select all

Params = <Identifier> | Params <Identifier> | Params (',' | '.' | ';' | ':' | '[' | ']' | '(' | ')' | '=' | '"');
func = 'function' <Identifier> '(' Params? ')' '=';
but keep getting "Circular stack" error

Posted: 28.12.2015 00:36
by Alexey
yes, grammer is not ok, i also did code and it gave err (so I rewritten code).