long comments work now

This commit is contained in:
SoniEx2 2019-04-08 14:48:31 -03:00
parent f56e1bd7e7
commit 772e7a9755
2 changed files with 26 additions and 29 deletions

View File

@ -484,38 +484,34 @@ do local tmaybe_comment = setmetatable({["-"] = "comment"}, {__index=defs})
mknewline(tmcomment, 1, defs) mknewline(tmcomment, 1, defs)
mknewline(tmcomment.comment_proper, 1, defs) mknewline(tmcomment.comment_proper, 1, defs)
tmcomment.comment_proper[""] = "self" tmcomment.comment_proper[""] = "self"
do local tlongcomment = {} do local tllongcomment_proper = selfify({[""] = "self", ["]"] = function(state, token) state.longcomment_close = 0 return "maybe_end" end})
tmcomment.longcomment = tlongcomment tmcomment.longcomment = tllongcomment_proper
do local tllongcomment_proper = selfify({[""] = "self", ["]"] = function(state, token) state.longcomment_close = 0 return "maybe_end" end}) do local tllmaybe_end = selfify({defs = defs}, "maybe_end")
do local tllmaybe_end = selfify({comment = tcomment}, "maybe_end") tllongcomment_proper.maybe_end = tllmaybe_end
tllongcomment_proper.maybe_end = tllmaybe_end tllmaybe_end.longcomment_proper = tllongcomment_proper
tllmaybe_end = tllongcomment_proper tllmaybe_end["="] = function(state, token)
tllmaybe_end["="] = function(state, token) state.longcomment_close = state.longcomment_close + 1
state.longcomment_close = state.longcomment_close + 1 return "maybe_end"
end
tllmaybe_end["]"] = function(state, token)
if state.longcomment_close == state.longcomment_count then
state.longcomment_close = nil
state.longcomment_count = nil
return "defs"
else
state.longcomment_close = 0
return "maybe_end" return "maybe_end"
end end
tllmaybe_end["]"] = function(state, token) end
if state.longcomment_close == state.longcomment_count then tllmaybe_end[""] = "longcomment_proper"
state.longcomment_close = nil tllmaybe_end[-1] = function(state, token, rule)
state.longcomment_count = nil if not rule then
return "defs" state.longcomment_close = nil
else
state.longcomment_close = 0
return "maybe_end"
end
end
tllmaybe_end[""] = "longcomment_proper"
tllmaybe_end[-1] = function(state, token, rule)
if not rule then
state.longcomment_close = nil
end
end end
end end
tlongcomment.longcomment_proper = tllongcomment_proper
mknewline(tlongcomment, 1, tllongcomment_proper)
setmetatable(tlongcomment, {__index=tllongcomment_proper})
end end
mknewline(tllongcomment_proper, 1, tllongcomment_proper)
end end
tmcomment.maybe_longcomment = setmetatable({ tmcomment.maybe_longcomment = setmetatable({
@ -536,7 +532,7 @@ do local tmaybe_comment = setmetatable({["-"] = "comment"}, {__index=defs})
return "longcomment_count" return "longcomment_count"
elseif token == "[" then elseif token == "[" then
state.longcomment_count = 0 state.longcomment_count = 0
return "longstring" return "longcomment"
end end
end, end,
}, {__index=tmcomment}) }, {__index=tmcomment})

View File

@ -385,6 +385,7 @@ do -- long comments
local luatokens = require "luatokens" local luatokens = require "luatokens"
local tokens = luatokens.defs local tokens = luatokens.defs
local state, err, etoken, estate = parser.parse(tokens, [==[--[[ local state, err, etoken, estate = parser.parse(tokens, [==[--[[
--]]]==]) --]]]==])
local case = case() local case = case()
if not state then if not state then
@ -396,7 +397,7 @@ do -- long comments
print(case, "---- OUT TOKENS ----") print(case, "---- OUT TOKENS ----")
else else
assert(table.remove(state, 1) == nil) assert(table.remove(state, 1) == nil)
assert(state.line == 2) assert(state.line == 3)
end end
end -- long comments end -- long comments