Pedro Gimeno's gists (pastes with history), each in an independent (orphan) branch

Pedro Gimeno 1693f63c6e Indentation checker for Lua in Lua 2 年之前
README.md 1693f63c6e Indentation checker for Lua in Lua 2 年之前
indentchecker.lua 1693f63c6e Indentation checker for Lua in Lua 2 年之前

README.md

Indentation checker for Lua

This is a Lua program that can be used to check the indentation of another Lua program. It checks that block beginners and enders, specifically if/elseif/else/end, repeat/until, do/end, while/end, for/end are at the same level of indentation, and reports any violation. This is most useful for finding where the missing end is in several nested blocks, which Lua tends to report well past where the problem actually is.

For example, if your program looks like:

if a = b then
  if c = d then
    return x
  else
    return y
elseif e = f then
  return z
end

Lua will typically report an error at the end of the file, while the problem is the missing end right after return y. If you follow this kind of rigorous indentation, this program can help you find the point that violates this indentation, which is typically where the problem is.

It accepts code with mixed tab/spaces; the default tab size is 8 but you can change it with option -t.

Note this program won't check the syntax of the code. The code incorporates a quite complete scanner, but the parser is quite primitive and only looks for specific opening/closing tokens without much regard for proper structure.