diff options
Diffstat (limited to 'script/parser/ast.lua')
-rw-r--r-- | script/parser/ast.lua | 85 |
1 files changed, 46 insertions, 39 deletions
diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 0a188da4..4f27d37d 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -9,7 +9,12 @@ local tableSort = table.sort _ENV = nil -local State +local DefaultState = { + lua = '', + options = {}, +} + +local State = DefaultState local PushError local PushDiag local PushComment @@ -277,7 +282,7 @@ local Defs = { type = 'comment.long', start = start, finish = finish - 1, - text = '', + text = str, } if not close then local endSymbol = ']' .. ('='):rep(afterEq-beforeEq) .. ']' @@ -318,7 +323,7 @@ local Defs = { } end end, - CLongComment = function (start1, finish1, start2, finish2) + CLongComment = function (start1, finish1, str, start2, finish2) if State.options.nonstandardSymbol and State.options.nonstandardSymbol['/**/'] then else PushError { @@ -344,7 +349,7 @@ local Defs = { type = 'comment.clong', start = start1, finish = finish2 - 1, - text = '', + text = str, } end, CCommentPrefix = function (start, finish, commentFinish) @@ -983,19 +988,7 @@ local Defs = { finish = start, } end, - Function = function (functionStart, functionFinish, args, actions, endStart, endFinish) - actions.type = 'function' - actions.start = functionStart - actions.finish = endFinish - 1 - actions.args = args - actions.keyword= { - functionStart, functionFinish - 1, - endStart, endFinish - 1, - } - checkMissEnd(functionStart) - return actions - end, - NamedFunction = function (functionStart, functionFinish, name, args, actions, endStart, endFinish) + Function = function (functionStart, functionFinish, name, args, actions, endStart, endFinish) actions.type = 'function' actions.start = functionStart actions.finish = endFinish - 1 @@ -1006,7 +999,7 @@ local Defs = { } checkMissEnd(functionStart) if not name then - return + return actions end if name.type == 'getname' then name.type = 'setname' @@ -1030,35 +1023,49 @@ local Defs = { name.vstart = functionStart return name end, - LocalFunction = function (start, functionStart, functionFinish, name, args, actions, endStart, endFinish) - actions.type = 'function' - actions.start = start - actions.finish = endFinish - 1 - actions.args = args - actions.keyword= { - functionStart, functionFinish - 1, - endStart, endFinish - 1, - } - checkMissEnd(start) - - if not name then - return + LocalFunction = function (start, name) + if name.type == 'function' then + PushError { + type = 'MISS_NAME', + start = name.keyword[2] + 1, + finish = name.keyword[2] + 1, + } + return name end - - if name.type ~= 'getname' then + if name.type ~= 'setname' then PushError { type = 'UNEXPECT_LFUNC_NAME', start = name.start, finish = name.finish, } - return + return name end - local loc = createLocal(name, name.start, actions) + local loc = createLocal(name, name.start, name.value) loc.localfunction = true - loc.vstart = functionStart - - return loc + loc.vstart = name.value.start + return name + end, + NamedFunction = function (name) + if name.type == 'function' then + PushError { + type = 'MISS_NAME', + start = name.keyword[2] + 1, + finish = name.keyword[2] + 1, + } + end + return name + end, + ExpFunction = function (func) + if func.type ~= 'function' then + PushError { + type = 'UNEXPECT_EFUNC_NAME', + start = func.start, + finish = func.finish, + } + return func.value + end + return func end, Table = function (start, tbl, finish) tbl.type = 'table' @@ -1923,7 +1930,7 @@ local function init(state) end local function close() - State = nil + State = DefaultState PushError = function (...) end PushDiag = function (...) end PushComment = function (...) end |