2

If I have an identifier with a same name as existing keyword, how do I escape it?

Andrey Shchekin
  • 21,101
  • 19
  • 94
  • 162

2 Answers2

1

That's what I found (and this is probably the final answer):

  1. It is possible to use @ as a prefix in identifier names. However, by default it creates a different identifier (@a != a).
  2. Since @ is allowed, it is possible to add a new compiler step to the pipeline that will do TrimStart('@') on all identifiers. It works ok, you will just have to remember all types of things that have names.
  3. If you are using Rhino.DSL, it has a UseSymbols step that converts @a into 'a', which had confused me a lot (I was working with project that included this step by default).
Andrey Shchekin
  • 21,101
  • 19
  • 94
  • 162
  • and how that work?? how code like that can be produced to AST? ''class = "Hello I'm keyword"'' yes you can wrote @class, but it is _not_ a keyword. Also you should be able do than in different levels of a type i.e. fields, parameters, properties, methods etc. It's not an easy task )) – Sergey Mirvoda Dec 21 '09 at 17:31
  • also you should check that a = "Hello" @a = "Hello" after your step you can get non uniq names – Sergey Mirvoda Dec 21 '09 at 17:33
  • 1
    _yes you can wrote @class, but it is not a keyword_ -- well, the difference is not obvious when you stay inside Boo, but consider a calling application in some other language where, for example, 'def' is not a keyword. In this case, difference between 'def _def()' and 'def @def()' is that it would be callable as 'x._def()' in the first case , and 'x.def()' in the second. – Andrey Shchekin Dec 21 '09 at 17:43
  • 1
    as for the unique names, I know it, but it is the same as C# does it, so I (and other users) am quite accustomed to this. – Andrey Shchekin Dec 21 '09 at 17:44
0

I don't think anything like the C# @ prefix is implemented in Boo... but I'm pretty sure it could be achieved by inserting a custom compiler step to the beginning of the compiler pipeline.

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275