From: "Peña, Botp" Date: 2006-08-19T12:41:47+09:00 Subject: Re: Syntax checker wtf? From: Hal Fulton [mailto:hal9000@hypermetrics.com] # Bill Kelly wrote: # > I wonder... # > # > 0001: class Foo # > 0002: # > 0003: def initialize # > 0004: # whatever # > 0005: end # > 0006: # > [...] # > 0347: def bar # > 0348: if @gargle # > 0349: puts "glug!" # > 0350: #end (missing end for if) # > 0360: end # > [...] # > 0415: # > 0416: end # of class Foo # > # > Now, the error message we'd like is that the 'end' is # missing for the 'if' # > expression starting on line 348. # > # > But the parser did find an 'end' that paired up with the # 'if', at line 360. # > And it found an 'end' for the 'def' at line 416. # Ultimately, it reaches # > the # > end of the file, and is missing an 'end' for 'class Foo'. # > # > So, would "unexpected EOF, missing kEND from line 1" really be all # > that helpful? # > # > It seems like a missing 'end' would probably tend to be reported for # > whatever line the outermost class or module being compiled started # > on... (?) # # This is sort of an interesting idea, discussed before. I wonder what # Matz thinks about it. It's not like "enforcing" indentation, it's just # using it to "guess" about a syntax error. # # Of course, the way it works now, it DOES find an 'end' for the 'if'... # it's on line 360. :) What it doesn't find is an end for the class... # # So unless it was whitespace-sensitive, it would tell you that it # reached the end of file while parsing the expression that started # on line 1. :) is it possible for ruby to return list of end pairs pretty printed (think folding)? Error: unexpected EOF, missing kEND from line 1. Listing end pairs encountered: 0001: class Foo 0003: def initialize 0005: end 0347: def bar 0348: if @gargle 0360: end 0416: end # of class Foo <--- missing end here an intelligent editor may then possibly associate the end pairs with the actual code, like so (pls forgive the crude ascii art), 0001: class Foo ------------------------- 0001: class Foo 0003: def initialize ................. 0002: 0005: end ........................ '.. 0003: def initialize 0347: def bar -----------------.. | 0004: # whatever 0348: if @gargle .......... | '..... 0005: end 0360: end ............. | | 0006: 0416: end # of class Foo | | | <--| missing end here | | |........ 0347: def bar | | |........... 0348: if @gargle | | 0349: puts "glug!" | | 0350: #end | |.............. 0360: end | | 0415: |................................. 0416: end # of class Foo i think this could be a good ruby quiz/challenge. kind regards -botp