@@ -59,6 +59,10 @@ local Shebang = P"#!" * P(1 - Stop)^0
5959-- can't have P(false) because it causes preceding patterns not to run
6060local Cut = P (function () return false end )
6161
62+ local function ensure (patt , finally )
63+ return patt * finally + finally * Cut
64+ end
65+
6266-- auto declare Proper variables with lpeg.V
6367local function wrap_env (fn )
6468 local env = getfenv (fn )
@@ -224,7 +228,8 @@ local build_grammar = wrap_env(function()
224228 end
225229
226230 local function advance_indent (str , pos , indent )
227- if indent > _indent :top () then
231+ local top = _indent :top ()
232+ if top ~= - 1 and indent > _indent :top () then
228233 _indent :push (indent )
229234 return true
230235 end
@@ -283,6 +288,7 @@ local build_grammar = wrap_env(function()
283288
284289 Advance = # Cmt (Indent , advance_indent ), -- Advances the indent, gives back whitespace for CheckIndent
285290 PushIndent = Cmt (Indent , push_indent ),
291+ PreventIndent = Cmt (Cc (- 1 ), push_indent ),
286292 PopIndent = Cmt (" " , pop_indent ),
287293 InBlock = Advance * Block * PopIndent ,
288294
@@ -420,9 +426,9 @@ local build_grammar = wrap_env(function()
420426
421427 -- the unbounded table
422428 TableBlockInner = Ct (KeyValueLine * (SpaceBreak ^ 1 * KeyValueLine )^ 0 ),
423- TableBlock = SpaceBreak ^ 1 * Advance * TableBlockInner * PopIndent / mark " table" ,
429+ TableBlock = SpaceBreak ^ 1 * Advance * ensure ( TableBlockInner , PopIndent ) / mark " table" ,
424430
425- ClassDecl = key " class" * Name * (key " extends" * Exp + C " " )^- 1 * ClassBlock / mark " class" ,
431+ ClassDecl = key " class" * Name * (key " extends" * PreventIndent * ensure ( Exp , PopIndent ) + C " " )^- 1 * ClassBlock / mark " class" ,
426432
427433 ClassBlock = SpaceBreak ^ 1 * Advance *
428434 Ct (ClassLine * (SpaceBreak ^ 1 * ClassLine )^ 0 ) * PopIndent ,
@@ -455,7 +461,7 @@ local build_grammar = wrap_env(function()
455461 ExpList = Exp * (sym " ," * Exp )^ 0 ,
456462 ExpListLow = Exp * ((sym " ," + sym " ;" ) * Exp )^ 0 ,
457463
458- InvokeArgs = ExpList * (sym " ," * SpaceBreak * Advance * ArgBlock ) ^- 1 ,
464+ InvokeArgs = ExpList * (sym " ," * ( TableBlock + SpaceBreak * Advance * ArgBlock * TableBlock ^- 1 ) + TableBlock ) ^- 1 + TableBlock ,
459465 ArgBlock = ArgLine * (sym " ," * SpaceBreak * ArgLine )^ 0 * PopIndent ,
460466 ArgLine = CheckIndent * ExpList
461467 }
0 commit comments