Search code examples
macrosnemerle

Nemerle Custom Operator Problem


What would like to able to write in my code is the following.

c² = a² + b²

To begin with I tried creating a macro for ² first. I have tried the following.

  macro @² (x)
syntax (x,"²")
{
 <[ 
($x * $x)

  ]>
}

But I get expecting an identifier errors at the (x) So I tried

  macro @s (x)
syntax (x,"²")
{
 <[ 
($x * $x)

  ]>
}

Now I get Unsupported Syntax Token error at the "²".

So I ask 1. is possible to write the Operator ² ? 2. What are the supported Syntax Tokens?


Solution

  • Currently, any character with an ASCII code lower than 255 and the following characters are valid for an operator: '=', '<', '>', '@', '^', '&', '-', '+', '|', '*','/', '$', '%', '!', '?', '~', '.', ':', '#', '\', '`', '(' , ')' , ';' , '[' , ']'.

    We can add "²" too, but maybe a more generic approach would be better.