How to allow ( ) in func parameters ?

All questions regarding lexer highlighting schemes are discussed here...
Locked
runsun
Posts: 15
Joined: 16.12.2015 01:43

How to allow ( ) in func parameters ?

Post 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 ?
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

this cannot be done with skip. () inside (). so u need grammar. one grammar rule is Par and one Func which uses "(" Par ")"
runsun
Posts: 15
Joined: 16.12.2015 01:43

Post 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
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

yes, grammer is not ok, i also did code and it gave err (so I rewritten code).
Locked