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

Operator syntax not working for "^^", "->" and others #707

Open
jayrbolton opened this issue May 17, 2017 · 4 comments
Open

Operator syntax not working for "^^", "->" and others #707

jayrbolton opened this issue May 17, 2017 · 4 comments

Comments

@jayrbolton
Copy link

for example:

 operator ^^ left 1 = (l, r) => #``

Throws:

Error: expecting an identifier
__^__ left 1 = ( l , r ) => #` `

The same happens with -> as well, but it works for me with the tutorial example >>=

@gabejohnson
Copy link
Member

gabejohnson commented May 17, 2017

^^ and -> aren't valid JavaScript identifiers. If it's not already an operator or keyword and you can't do

var ^^ = 5;

Then you can't use it to define an operator.

That will change with #687.

@disnet should we make this explicit in the docs?

Edit: Added note about pre-existing operators and keywords

@jayrbolton
Copy link
Author

Thanks for the reply, I think a note about that in the docs would be good. Also note the example with >>= right here: http://www.sweetjs.org/doc/tutorial#sweet-operators. As far I know you can't do var >>= = 5; either.

@gabejohnson
Copy link
Member

You got me 😄 .

It works with pre-existing operators and keywords too. I'll update the comment.

@disnet
Copy link
Member

disnet commented May 18, 2017

Syntax bindings (both syntax ... and operator ...) allow identifiers, keywords, and punctuators to be the binding, while runtime declarations can only be identifiers and keywords (depending on the context). The reason ^^ doesn't work is that it is actually two ^ tokens. Some of the existing operators "look" like two tokens but are lexed as one (e.g. >>=, =>, etc.). Readtables will essentially allow you to change the lexer and make ^^ into a single token.

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

3 participants