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
2009-12-21 02:15:59
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
2009-12-21 10:02:01
good point, then it has to be at the parser level.
Mauricio Scheffer
2009-12-21 15:48:43
Added my finding as an answer.
Andrey Shchekin
2009-12-21 15:52:35
so it *was* possible with a compiler step after all
Mauricio Scheffer
2009-12-21 16:08:00
yes, and I am ok with compiler steps, but I was hoping that there is something that works out of the box.
Andrey Shchekin
2009-12-21 16:33:44
A:
That's what I found (and this is probably the final answer):
- It is possible to use
@
as a prefix in identifier names. However, by default it creates a different identifier (@a != a
). - Since
@
is allowed, it is possible to add a new compiler step to the pipeline that will doTrimStart('@')
on all identifiers. It works ok, you will just have to remember all types of things that have names. - 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
2009-12-21 15:52:06
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
2009-12-21 17:31:00
also you should check thata = "Hello"@a = "Hello"after your step you can get non uniq names
Sergey Mirvoda
2009-12-21 17:33:09
_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
2009-12-21 17:43:42
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
2009-12-21 17:44:39