Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

mid-rule actions feature request #122

Closed
garyhodgson opened this Issue · 4 comments

3 participants

@garyhodgson

Hi,

I don't know how active this project is now but I was wondering if there are any plans to implement mid-rule actions? I'm in the middle of porting a yacc based app (openscad) and have come across one which has thrown a spanner in the works.

If it's not being implemented then do you have any advice to a parser newbie on how to get around having to use mid-rule actions? I can't see how I could change the lex or grammar to work around it.

The pertinent yacc looks like this if it helps any...

statement:
    TOK_MODULE TOK_ID '(' arguments_decl optional_commas ')' {
        Module *p = currmodule;
        module_stack.push_back(currmodule);
        currmodule = new Module();
        p->modules[$2] = currmodule;
        currmodule->argnames = $4->argnames;
        currmodule->argexpr = $4->argexpr;
        free($2);
        delete $4;
    } statement {
        currmodule = module_stack.back();
        module_stack.pop_back();
    } | etc....

which would parse something like...

module hole(size) {
    cylinder(r = size, h = 100, center = true);
}

hole(10);

It's temporarily pushing the current module onto a stack so it can process a child module definition, and i'm not sure how I would isolate the child module from the rest of the script.

Any advice would be appreciated.

Thanks,
Gary

@zaach
Owner

There are no current plans, but there is a feature request here #69.

An alternative would be to break the rule into two separate rules:

statement: statement_begin statement_end
  | ...

statement_begin:
    TOK_MODULE TOK_ID '(' arguments_decl optional_commas ')' {
        Module *p = currmodule;
        module_stack.push_back(currmodule);
        currmodule = new Module();
        p->modules[$2] = currmodule;
        currmodule->argnames = $4->argnames;
        currmodule->argexpr = $4->argexpr;
        free($2);
        delete $4;
    } 

statement_end: statement {
        currmodule = module_stack.back();
        module_stack.pop_back();
    }

That example might not work, but you get the idea.

@zaach zaach closed this
@garyhodgson

Thanks for the advice Zaach - i'll give it a go. And thanks for Jison! Great project!

@CatTail

I think jison should add feature to support mid-rule action. Any ideas?

@zaach
Owner

@CatTail I'll look into it since it does seem to come up often enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.