diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-15 11:20:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-15 11:20:05 +0800 |
commit | 385e2ce83035de582e9afb5f444820b259a008df (patch) | |
tree | 0b2147c8071d7804599e662cd8040e7b8a224b93 /script-beta/parser | |
parent | b576dfb1ba883fcee8a99f4213e6e7b26461fc0e (diff) | |
download | lua-language-server-385e2ce83035de582e9afb5f444820b259a008df.zip |
更新parser
Diffstat (limited to 'script-beta/parser')
-rw-r--r-- | script-beta/parser/ast.lua | 29 | ||||
-rw-r--r-- | script-beta/parser/grammar.lua | 13 | ||||
-rw-r--r-- | script-beta/parser/parse.lua | 6 |
3 files changed, 25 insertions, 23 deletions
diff --git a/script-beta/parser/ast.lua b/script-beta/parser/ast.lua index bdf15508..d8614eae 100644 --- a/script-beta/parser/ast.lua +++ b/script-beta/parser/ast.lua @@ -1,5 +1,3 @@ -local emmy = require 'parser.emmy' - local tonumber = tonumber local stringChar = string.char local utf8Char = utf8.char @@ -14,6 +12,7 @@ _ENV = nil local State local PushError local PushDiag +local PushComment -- goto 单独处理 local RESERVED = { @@ -258,6 +257,13 @@ local Defs = { [1] = false, } end, + ShortComment = function (start, text, finish) + PushComment { + start = start, + finish = finish - 1, + text = text, + } + end, LongComment = function (beforeEq, afterEq, str, missPos) if missPos then local endSymbol = ']' .. ('='):rep(afterEq-beforeEq) .. ']' @@ -1724,21 +1730,18 @@ local Defs = { end, } ---for k, v in pairs(emmy.ast) do --- Defs[k] = v ---end - local function init(state) - State = state - PushError = state.pushError - PushDiag = state.pushDiag - emmy.init(State) + State = state + PushError = state.pushError + PushDiag = state.pushDiag + PushComment = state.pushComment end local function close() - State = nil - PushError = function (_) end - PushDiag = function (_) end + State = nil + PushError = function (...) end + PushDiag = function (...) end + PushComment = function (...) end end return { diff --git a/script-beta/parser/grammar.lua b/script-beta/parser/grammar.lua index 292f0e52..06dae246 100644 --- a/script-beta/parser/grammar.lua +++ b/script-beta/parser/grammar.lua @@ -1,6 +1,5 @@ local re = require 'parser.relabel' local m = require 'lpeglabel' -local emmy = require 'parser.emmy' local ast = require 'parser.ast' local scriptBuf = '' @@ -93,15 +92,13 @@ LongComment <- ('--[' {} {:eq: '='* :} {} '[' ) -> CLongComment CommentClose <- ']' =eq ']' -ShortComment <- (!%nl .)* +ShortComment <- ({} {(!%nl .)*} {}) + -> ShortComment ]] grammar 'Sp' [[ -Sp <- (EmmyLua / Comment / %nl / %s)* -Sps <- (EmmyLua / Comment / %nl / %s)+ - --- 占位 -EmmyLua <- !. . +Sp <- (Comment / %nl / %s)* +Sps <- (Comment / %nl / %s)+ ]] grammar 'Common' [[ @@ -522,8 +519,6 @@ FuncName <- {| Single (Sp SuffixWithoutCall)* |} / {} -> MissName %nil ]] ---grammar 'EmmyLua' (emmy.grammar) - grammar 'Lua' [[ Lua <- Head? ({} {| Action* |} {}) -> Lua diff --git a/script-beta/parser/parse.lua b/script-beta/parser/parse.lua index bbc01b10..f813cc59 100644 --- a/script-beta/parser/parse.lua +++ b/script-beta/parser/parse.lua @@ -3,13 +3,14 @@ local ast = require 'parser.ast' return function (self, lua, mode, version) local errs = {} local diags = {} + local comms = {} local state = { version = version, lua = lua, - emmy = {}, root = {}, errs = errs, diags = diags, + comms = comms, pushError = function (err) if err.finish < err.start then err.finish = err.start @@ -29,6 +30,9 @@ return function (self, lua, mode, version) diags[code] = {} end diags[code][#diags[code]+1] = info + end, + pushComment = function (comment) + comms[#comms+1] = comment end } ast.init(state) |