sweet-core icon indicating copy to clipboard operation
sweet-core copied to clipboard

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

Open jayrbolton opened this issue 8 years ago • 4 comments

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 >>=

jayrbolton avatar May 17 '17 17:05 jayrbolton

^^ 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

gabejohnson avatar May 17 '17 17:05 gabejohnson

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.

jayrbolton avatar May 17 '17 17:05 jayrbolton

You got me 😄 .

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

gabejohnson avatar May 17 '17 17:05 gabejohnson

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.

disnet avatar May 18 '17 05:05 disnet