Skip to content

Instantly share code, notes, and snippets.

@agladysh
Created August 27, 2013 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agladysh/2bd2c4f507d46105c2cd to your computer and use it in GitHub Desktop.
Save agladysh/2bd2c4f507d46105c2cd to your computer and use it in GitHub Desktop.
-- 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")
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