jruby / jruby-parser

JRuby's parser customized for IDE usage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misses empty expressions in literal array

chrisseaton opened this issue · comments

Parses this:

[0, (), 2, (), 4]

as this:

(RootNode, (NewlineNode, (ArrayNode, (FixnumNode), (FixnumNode), (FixnumNode))))

which is wrong according to this:

https://github.com/rubyspec/rubyspec/blob/master/language/array_spec.rb#L13

Perhaps due to the work to remove the implicit nil nodes?

Yeah this is definitely fallout from that. I will try and figure out how to represent this better.

Crud. In most places where nilimplicitnils showed up the absence of it is not a big deal. Like a null body node in a rescue body. This is actually a representation of a data structure. This is horrible :)

My original main issue with implicitnilnode was that it represented semantics and not syntax (or at least I thought so). This ended up leading to lots of conditionals everywhere trying to not process these elements. In retrospect, this 'not processing' desire came from the fact that they were not given a valid position object.

I need to at least add in some AST node to address this. ImplicitNilNode might come back but be a new instance for each occurrence and have a reasonable position object associated with it. I will probably only address this in ArrayNode although I am thinking all ListNode-derived elements might need it.

I am resolving this even though there might be other places where this can occur. If so then new issues should be opened on related behavior.

There is a very generic place where for arbitrary expressions we can supply '()' and it will end up resolving to nil. I made a new class ImplicitNilNode which is used to mark this. It also properly sets its position to include the 'parens'. This fits into the longer-term scenario of weaving syntax elements back into the AST post parse (since those syntax elements are children of this new node).

Other possibilities exist for () in the grammar but an informal survey shows them to be for argument processing or methods and blocks. So I am hoping this one change is enough.

I see your reasoning for removing the implicit nils, but I found them quite useful: I could always visit every part of an expression without having to check what it was, and if it generated nothing that was fine. Now I have to conditionally check for nulls everywhere, so when you say this means less conditionals, that's not the effect it's had on my code base. This doesn't stop my doing anything though, so I guess it's all stylistic.

Thanks for the fix.

Yeah I apologize for changing so much lately. Eric is working on rsense stuff and I am working towards simplifying netbeans ruby codebase so I am just going for it a bit more than I probably should. OTOH, jruby-parser is still <1.0 so I would like to break some eggs to make an omelette :)