-
-
Save agladysh/2bd2c4f507d46105c2cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- should be cut from here | |
local alpha | |
= FUNCTION ( -- this is NOT my line number | |
FUNCTION 'beta' { 'gamma' } () | |
and 'epsilon' | |
or 'zeta' | |
) | |
{ | |
'eta' | |
} -- should be cut from here | |
print("bar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local str = [[ | |
print("foo") | |
local alpha | |
= FUNCTION ( -- this is my line number | |
FUNCTION 'beta' { 'gamma' } () | |
and 'epsilon' | |
or 'zeta' | |
) | |
{ | |
'eta' | |
} -- should be cut from here above | |
local alpha | |
= FUNCTION ( -- this is NOT my line number | |
FUNCTION 'beta' { 'gamma' } () | |
and 'epsilon' | |
or 'zeta' | |
) | |
{ | |
'eta' | |
} | |
print("bar") | |
]] | |
-- enclose string literals and table constructors in temporary parentheses | |
str = str:gsub('%b""','(\0%0\0)'):gsub("%b''",'(\0%0\0)'):gsub("%b{}",'(\0%0\0)') | |
repeat | |
-- set "chained function call" mark | |
local ctr | |
str, ctr = str:gsub('(.*)%b()%s*%b()', '%1<\0>') | |
until ctr == 0 | |
-- search for last "chained function call" mark and remove all text before it | |
str = str:gsub('^.*<%z>', '') | |
-- remove temporary parentheses | |
str = str:gsub('%(%z', ''):gsub('%z%)', '') | |
print(str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment