tags:

views:

91

answers:

2

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

A: 

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.

Mauricio Scheffer
I think it is not possible at all. compiler steps operates on AST. but which AST will be produced for such a code class = 'Hello'
Sergey Mirvoda
good point, then it has to be at the parser level.
Mauricio Scheffer
Added my finding as an answer.
Andrey Shchekin
so it *was* possible with a compiler step after all
Mauricio Scheffer
yes, and I am ok with compiler steps, but I was hoping that there is something that works out of the box.
Andrey Shchekin
A: 

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
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
also you should check thata = "Hello"@a = "Hello"after your step you can get non uniq names
Sergey Mirvoda
_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
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