-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add back custom operators #517
Comments
How to define unary operators with this syntax? |
@disnet are you thinking of hard-coding this into the enforester/macro-context or implementing it as a macro? It seems like operators and infix macros require some of the same features (access to a prefix of tokens). |
This is a very important feature in my opinion. It would be good to have it |
@disnet That sounds like very useful feature. Are there any reference to the old version supporting it or other projects? |
@dmitriz Sure, the old documentation is available at http://sweetjs.org/doc/main/sweet.html |
@disnet I just got another question about this on Gitter. Do you want to have a design discussion about it? |
@gabejohnson absolutely, do you have some design ideas kicking around? I haven't had the chance to think about it deeply in a while. |
Looks like this has been hanging out for about a year now. Anything I can do to help it land? |
@mooreniemi if you'd like to dive in that would be awesome! Nothing has been blocking it, just not on top of my stack. There should be two pieces to getting this landed. One is the syntax design and the other is wiring it up. For wiring it up you need to:
For the syntax design it sounded like @gabejohnson had some ideas? |
@mooreniemi Any help would be welcome! As far as design goes, I want to make sure we don't introduce new primitive forms unnecessarily. And I can't shake the feeling that this has to tie in to infix operators. I know operators are some of the more complex forms to parse, but if we exposed operator foo (left, right, associativity='left', precedence=13) {
// left is already enforested at this point as it will be with infix macros
return #`${op}(${left}, ${right.expand('Expression')})`;
} The operator context stack juggling could be done in the definition of the There would be a lot of duplicate code b/w the macro and the enforester unless we were able to leverage the enforester or have all operators dispatch to macros. See the bottom of this #516 (comment). Though that might slow things down too much. As to defining something like: operator |> (...) {
...
} It would be my preference starting out just defining the new punctuator w/ readtables. The only other reasonable way to do it, to my mind, would be to have the whole pipeline be lazy and extend the readtable on the fly. Whatever happens @disnet, I think getting infix macros done first makes the most sense as I think they're a superset of all other syntactic extensions. |
@gabejohnson so I started writing a long post saying why I thought that wouldn't work but then realized it actually kinda would and that it's super easy to add infix macros. So #643. I'm still not entirely sure I'm comfortable with exposing But we can totally experiment. |
@disnet I don't want to beat a dead horse here but I'd still want like to avoid creating a single purpose special form (if possible). Consider this: syntax m: { precedence: 13, associativity: 'left' } = ctx => {
...
} This syntax would put additional information on the I realized that in my example above... operator foo (left, right, associativity='left', precedence=13) {
// left is already enforested at this point as it will be with infix macros
return #`${op}(${left}, ${right.expand('Expression')})`;
} ...that conflating local, runtime binding syntax w/ what were essentially compile-time bindings was misguided. But there is already precedent in JS for compile-time bindings using this syntax (i.e. Flow, TypeScript). A side benefit is that this syntax could be adapted in the future for type hints if we so desire (in this case a parameterized one, It might make sense to do this work at the same time that we implement your proposal in #620 (if we go forward with that). |
I'll have to stew on it for a while but I think I like your proposed syntax. We could also throw in a syntax m: #{ precedence: 13, associativity: 'left' } = ctx => {
...
} |
I don't think it adds any information that isn't already provided by |
* Implement custom operators; fixes #517 * Add support for postfix custom operators
Pre 1.0 had the ability to define custom operators with precedence and associativity. It would be nice to have that back. Some syntax ideas:
Most of the plumbing for this features is already done. Just need to decide on the right syntax.
The text was updated successfully, but these errors were encountered: