Skip to content

Commit 6bcc67f

Browse files
authored
Merge pull request #21 from bbonte-ovk/table_indentation
Fixing a large number of indentations in a table
2 parents f28b4f1 + 0805f4c commit 6bcc67f

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lua-parser/parser.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,12 @@ local function sepBy (patt, sep, label)
214214
end
215215
end
216216

217+
local function cut(s, idx, match)
218+
return idx, match
219+
end
220+
217221
local function chainOp (patt, sep, label)
218-
return Cf(sepBy(patt, sep, label), binaryOp)
222+
return Cmt(Cf(sepBy(patt, sep, label), binaryOp), cut)
219223
end
220224

221225
local function commaSep (patt, label)

test.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,28 @@ e = [=[
37523752
{ `Set{ { `Id "gl_f_ct" }, { `Number "0" } }, `Set{ { `Id "f" }, { `Function{ { }, { `If{ `Op{ "le", `Id "gl_f_ct", `Number "0" }, { `Set{ { `Id "gl_f_ct" }, { `Number "1" } }, `Return{ `Number "1000" } } }, `Return{ `Op{ "unm", `Number "1000" } } } } } }, `Call{ `Id "print", `Op{ "gt", `Call{ `Id "f", `String "1st call" }, `Call{ `Id "f", `String "2nd call" } } }, `Set{ { `Id "gl_f_ct" }, { `Number "0" } }, `Call{ `Id "print", `Op{ "lt", `Call{ `Id "f", `String "1st call" }, `Call{ `Id "f", `String "2nd call" } } } }
37533753
]=]
37543754

3755+
-- table indentation
3756+
3757+
s = [===[
3758+
return {{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}
3759+
]===]
3760+
e = [=[
3761+
{ `Return{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table } } } } } } } } } } } } } } } } }
3762+
]=]
3763+
3764+
r = parse(s)
3765+
assert(r == e)
3766+
3767+
s = [===[
3768+
return {{{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}}}
3769+
]===]
3770+
e = [=[
3771+
{ `Return{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table{ `Table } } } } } } } } } } } } } } } } } }
3772+
]=]
3773+
3774+
r = parse(s)
3775+
assert(r == e)
3776+
37553777
r = parse(s)
37563778
assert(r == e)
37573779

0 commit comments

Comments
 (0)