Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labeled element not being passed to action handler as property of element #28

Closed
mesozoic-technology opened this issue Feb 22, 2018 · 4 comments

Comments

@mesozoic-technology
Copy link

I have this rule that I would expect to provide 'Expression' as the property 'expression' on the appropriate element passed to the action handler, however it isn't showing up. Plenty of other rules have property labels on them and they show up just fine -- is there something I've missed here?

  ExpressionStatement    <- !("{" / FunctionToken) expression:Expression EOS %makeExpressionStatement 
@jcoglan
Copy link
Owner

jcoglan commented Feb 22, 2018

Labelled elements only exist on nodes built by Canopy's default tree-building code. If you supply your own action, that means you're overriding that built-in behaviour, and you are given the elements of the match as an array.

If you're writing in JS, you could use destructuring to improve the code:

makeExpressionStatement(text, start, end, [_, expression]) {
  // ...
}

@mesozoic-technology
Copy link
Author

mesozoic-technology commented Feb 22, 2018

That would only be a minor cosmetic benefit - what I wanted it to do was return me the element nested at nth element deep, which would prevent me from having to make a nasty function that checks manually each vertebrae of the resulting tree to see if that is where the actually parsed element is found.

@mesozoic-technology
Copy link
Author

I've inherited this grammar from PegJS, where it works just as described - instead of returning a whole tree of expressions that hand off the parsing until it meets the matching expression in question, it will simply return a literal, assignment expression or what have you all by itself as a single object

@mesozoic-technology
Copy link
Author

Aha - there was actually a decent amount of javascript I was overlooking that accomplishes that for PegJS. I'll have to figure out how to make this work in Canopy minus labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants