-
Notifications
You must be signed in to change notification settings - Fork 21
Reinstate @ decorator for unary ops. #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Chris, I have 2 comments on this PR. I see you updated Ruby18Parser.java to contain setValueNode instead of setValue. You should revert that set of changes since setValueNode was replaced by setValue (although the .y file was not updated). The second name is more about what should be returned by getName() and getDecoratedName(). In how they have been used I would say getName() should return '-@' and getDecoratedName() should return '-'. Even this recommendation worries me since I think in netbeans we use getName() for length/name of identifier for things like instant renaming. I loathe the idea of making a third name method but I think there are three cases here:
It is possible the getName,getDecoratedName concept is flawed. Perhaps I need getName() and getSigil() but I think even this would still need a third method for semantic name. So having rambled through this I wonder if we should have getSemanticName()? So then the real recommendation would be to: getName -> '-' This however requires considerable change to CallNode so perhaps for now use my original recommendation of getname -> -@ and decoratedname -> -. Expect this to change later to accommodate difference between semantic and lexical needs though (unless you have some other thoughts on how this should be addressed). |
|
I'm not sure how I managed to change Ruby18Parser.java without changing Ruby18Parser.y. I'll look at that again. I follow your reasoning, but I think your solution for now, getName -> -@ and getDecoratedName -> -, has to be the least intuitive of them! The decorated version returns the shorter name! However if you think that's best, I'll implement that. I'm just keen on being able to detect unary ops however it's done. |
|
yeah I am mostly form-fitting here. Perhaps Unary calls can become a specialized node type. That would then still return '-' for both name and decorated name but it would be easily detectabe? |
|
This just removes the unary @ in getDecoratedName. I'm not terribly familiar with Ruby - is there a risk that we remove the @ from a method that isn't expecting to have it removed? I think your last commit recreated the 1.8 parser. |
|
Ok Chris, I was just thinking about how to solve this nicely and I think perhaps we just need to make the names clearer. I think there are only two method named: getName() and getLexicalName(). getName() represents semantically what is needed for making a runtime. We dispatch to @- so getName() will return that. getLexicalName() returns what is needed to rewrite the AST back to source essentially. In this case, it would just return '-'. Note the case of unary minus is different than most: getName() -> 'foo' As you can guess I just plan on renaming getDecoratedName to getLexicalName. At the time I made the method I did not realize that it had cases like unary minus and just went with the wrong concept in my head. Renaming lexical to me makes this much more intuitive. What do you think? |
|
Yes, those names seem nice and clear and will solve my use case. My PR patch has the bug that it adds the sigil to all unary ops, such as Let me know if you want my patch updating in some way, or feel free to discard it or whatever, I'm not attached. |
|
Is this the right way around? You said that |
|
Ah I think I see what I did to confuse this... For the def @- then the lexical name is @- and the same as @foo. I was thinking that at a callsite the lexer was supposed to provide '@-' where then that would be the name but '-' would be the lexical name. |
|
Yeah, it's not simple is it. What's more you can do |
|
Actually your example made me realize that unary as a call op is special and should be made a specialized node. Your example number.-@() is not special and it just an ordinary call. So I think we need UnaryCallNode or something like that? The special class makes getName and getLexical name require no special logic then. |
|
I should have stated that number.-@() is doing nothing special lexically... |
|
A |
|
I'm proposing https://github.com/chrisseaton/jruby-parser/blob/issue-8-proposed-specs/spec/parser/calls_spec.rb as a set of specs to work against for calls. It says that only for the operators Note that in writing these specs I'm not sure about our 1.8: 1.8 seems right, but 1.9 replaces it with a call to the |
|
I've made a right mess of the issues for this bug. This is a pull request, that we're no longer going to merge, so I'll close it and continue discussion on the original bug #4. |
Fixes #4.
It's debatable whether getName() and getDecoratedName() should return different things here. My thought is that -@ is the name of the method. It's not decorated - that is the name. Anything else is a syntactic shortcut.
Also a note about how to use Jay, as I found it a little confusing.