sweet-js/sweet-core

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

jayrbolton opened this issue · 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 >>=

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

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.

You got me 😄 .

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

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.