jruby / jruby-parser

JRuby's parser customized for IDE usage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parses != as !(x==y)

chrisseaton opened this issue · comments

jruby-parser seems to parse x!=y as !(x==y). That is, this:

(q1 = p[1]) != 1

is parsed as:

(NotNode, (CallNode:==, (NewlineNode, (LocalAsgnNode:q1,
        (CallNode:[], (LocalVarNode:p), (ArrayNode,
        (FixnumNode))))), (ArrayNode, (FixnumNode))

Sorry, I was mistaken about the != operator. jruby-parser 0.2 returned a call to !=, but now I see you're just desugaring.

Yeah this is true it is desugaring but for rewriting we will probably need to return it to it's original lexical value. This is another ramification of porting back from a runtime to something which is supposed to remain lexically the same.

One place where this is still a problem is perhaps someone using jruby-parser would like to know the difference between someone writing != and ! ==. At the moment you return the same AST, but perhaps a rewriting tool would like to know which you wrote.

A good way to think about it may be to ask if the AST is giving you enough information to round trip the program. Here it isn't, unless I'm missing something.

yeah "here it isn't" is the correct answer :)

It should be changed. When I first ported MRI 1.9 parser to JRuby I tried to remove a bunch of these but not all of them since it was more expedient not to. MRI 1.9 had switched to Yarv and I think some of these were more desirable since it simplified the bytecode they made. In JRuby-parser none of these have any place in here. So we need to find each place and correct them. We are making a runtime and we want to preserve hopefully all lexically significant info.

I'm going to re-open this, since you concur we need to remove them, and it's been causing me a lot of headaches today - there is no guarantee that != will be implemented the same as !(==).

Note to myself since I might not get this finished today. Only 1.8 parser exhibits this behavior. Partially AST represents more then lexical structure in JRuby and MRI. Changes like this one demonstrate execution semantics. This representation is not useful for jruby-parser, so I will change 1.8 to match 1.9 and 2.0.

fixed in commit f9980a9.