lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Jan 12, 2014 at 12:30 AM, Rena <hyperhacker@gmail.com> wrote:
> If you leave out an 'end', the error message isn't very helpful:
>
> $ lua -e "if x then"
> lua: (command line):1: 'end' expected near <eof>
>
> Some compilers I've used give you a more detailed message telling you what
> the 'end' would be closing, like: "'end' expected near <eof> to close 'if'
> at (command line):1"
>

Notice that the error message can be very confusing in the case of
nested blocks. If you forget to close the inner block, for example,
the parser assumes that the first "end" it encounters is closing this
block, then the next "end" closes the one surrounding it, and so on,
with the missing "end" assigned to the outer block, which obviously is
not be the case.

---- do.lua -
do
   print("1")
   do
      print("2")
      do
         print("3")
   end
end
------

$ lua do.lua
lua: do.lua:10: 'end' expected (to close 'do' at line 1) near <eof>

> This would be helpful for editing and for editors like Textadept, which highlight lines with syntax > errors, so that they could highlight the line with the unclosed statement instead of just jumping > to the end of the file.

A text editor can have a slower parser that uses an identation as an
heuristic to better pinpoint the location of the missing "end".

--
Fabio Mascarenhas