Jason Morrison wrote: > Hey there folks, Hello there Jason! You live!
> I was wondering if anyone could point me in the right direction. I'm > looking into parsing partial/invalid Ruby code, specifically for the > intent of type inference for code completion. (See > http://soc.jayunit.net... I've disappeared under school work for a > while, but am trying to reach the surface under the guise of a project > for my Language Processors/Compiler Construction course ;) The biggest > roadblock I'd hit upon, and would like to revisit, is the fact > that,inside an IDE code completion (and therefore type inference) is > often requested at a point at which the code is not syntactically > valid. I.e.: > > def foo > if ( cond ) > puts myvar. # invoke completion > > class MyKlass > class << self; def method > #... and so on Oddly enough, I'm not a parser or grammar expert, but it's my understanding that the parsers ANTLR generates can recover from parse errors much more efficiently. Others on the list may be able to confirm or refute that. However the most efficient model I've heard about is called "parser combinators". I have no knowledge of it other than that it combines many "mini parsers" that individually handle smaller parts of the code, so you can cut off parsing at any point or parse subsections of a file. To my knowlege, there's no such parser for Ruby anywhere. ANTLR's probably your best bet for now. > If not, any thoughts on the idea? Is this something that can be > usefully resolved via error symbols? (Perhaps I am simply ignorant of > an error-recovery enabling flag in my trusty JRuby parsing calls, and > would be better served directing inquiry to the JRuby list?) I'd rather > not just blast an arbitrary number of close-parens and "end"s at the > cursor position until a valid parse surfaces, the quickest-and-dirtiest > solution that originally came to mind ; ) You're not missing anything in the JRuby parser. Most of the folks working on editors/IDEs are using their own hacks to get around it, and at least in the case of NetBeans I know Tor has used hacks plus completion to limit the likelihood that a file will be unparseable, but eventually there's a point that there's nothing you can do. Our (grammarians) grammar is actually one contributed by the XRuby project, and by most accounts it's the most complete ANTLR grammar yet available. Xue has managed to get XRuby to parse and compile everything in Ruby's "test.rb", which is no small feat. I believe this grammar could probably use an update (Xue, is this true?). I think we'd all love for someone to look at using Xue's grammar for other things, and of course on the JRuby side I'm just interested in potentially moving away from the YACC-based parser we have now. But it's pretty scary, since to our knowledge there's no other 100% complete and known perfect parser than the YACC-based versions. - Charlie _______________________________________________ Rubygrammar-grammarians mailing list [email protected] http://rubyforge.org/mailman/listinfo/rubygrammar-grammarians
