diff options
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/luadoc.lua | 111 | ||||
-rw-r--r-- | script/parser/newparser.lua | 22 |
2 files changed, 87 insertions, 46 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index e21e7c19..d206e6d7 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -10,9 +10,8 @@ local Parser = re.compile([[ Main <- (Token / Sp)* Sp <- %s+ X16 <- [a-fA-F0-9] -Word <- [a-zA-Z0-9_] Token <- Integer / Name / String / Symbol -Name <- ({} {[a-zA-Z_0-9] [a-zA-Z0-9_.*-]*} {}) +Name <- ({} {%name} {}) -> Name Integer <- ({} {[0-9]+} !'.' {}) -> Integer @@ -45,7 +44,7 @@ EChar <- 'a' -> ea / ('z' (%nl / %s)*) -> '' / ('x' {X16 X16}) -> Char16 / ([0-9] [0-9]? [0-9]?) -> Char10 - / ('u{' {Word*} '}') -> CharUtf8 + / ('u{' {X16*} '}') -> CharUtf8 Symbol <- ({} { [:|,<>()?+#`{}] / '[]' @@ -63,6 +62,7 @@ Symbol <- ({} { er = '\r', et = '\t', ev = '\v', + name = (m.R('az', 'AZ', '09', '\x80\xff') + m.S('_')) * (m.R('az', 'AZ', '__', '09', '\x80\xff') + m.S('_.*-'))^0, Char10 = function (char) char = tonumber(char) if not char or char < 0 or char > 255 then @@ -342,6 +342,21 @@ local function parseTypeUnitTable(parent, node) return result end +local function parseDots(tp, parent) + if not checkToken('symbol', '...', 1) then + return + end + nextToken() + local dots = { + type = tp, + start = getStart(), + finish = getFinish(), + parent = parent, + [1] = '...', + } + return dots +end + local function parseTypeUnitFunction() local typeUnit = { type = 'doc.type.function', @@ -361,47 +376,29 @@ local function parseTypeUnitFunction() type = 'doc.type.arg', parent = typeUnit, } - if checkToken('symbol', '...', 1) then - nextToken() - local vararg = { - type = 'doc.type.name', - start = getStart(), + arg.name = parseName('doc.type.name', arg) + or parseDots('doc.type.name', arg) + if not arg.name then + pushError { + type = 'LUADOC_MISS_ARG_NAME', + start = getFinish(), finish = getFinish(), - parent = arg, - [1] = '...', } - arg.name = vararg - if not arg.start then - arg.start = arg.name.start - end - arg.finish = getFinish() - else - arg.name = parseName('doc.type.name', arg) - if not arg.name then - pushError { - type = 'LUADOC_MISS_ARG_NAME', - start = getFinish(), - finish = getFinish(), - } - break - end - if not arg.start then - arg.start = arg.name.start - end - if checkToken('symbol', '?', 1) then - nextToken() - arg.optional = true - end - arg.finish = getFinish() - if not nextSymbolOrError(':') then - break - end + break + end + if not arg.start then + arg.start = arg.name.start + end + if checkToken('symbol', '?', 1) then + nextToken() + arg.optional = true + end + arg.finish = getFinish() + if checkToken('symbol', ':', 1) then + nextToken() arg.extends = parseType(arg) - if not arg.extends then - break - end - arg.finish = getFinish() end + arg.finish = getFinish() typeUnit.args[#typeUnit.args+1] = arg if checkToken('symbol', ',', 1) then nextToken() @@ -492,6 +489,19 @@ local function parseTypeUnitLiteralTable() end local function parseTypeUnit(parent, content) + if content == 'async' then + local tp, cont = peekToken() + if tp == 'name' then + if cont == 'fun' then + nextToken() + local func = parseTypeUnit(parent, cont) + if func then + func.async = true + return func + end + end + end + end local result if content == 'fun' then result = parseTypeUnitFunction() @@ -749,6 +759,7 @@ local function parseParam() type = 'doc.param', } result.param = parseName('doc.param.name', result) + or parseDots('doc.param.name', result) if not result.param then pushError { type = 'LUADOC_MISS_PARAM_NAME', @@ -1098,6 +1109,22 @@ local function parseModule() return result end +local function parseAsync() + return { + type = 'doc.async', + start = getFinish(), + finish = getFinish(), + } +end + +local function parseNoDiscard() + return { + type = 'doc.nodiscard', + start = getFinish(), + finish = getFinish(), + } +end + local function convertTokens() local tp, text = nextToken() if not tp then @@ -1141,6 +1168,10 @@ local function convertTokens() return parseDiagnostic() elseif text == 'module' then return parseModule() + elseif text == 'async' then + return parseAsync() + elseif text == 'nodiscard' then + return parseNoDiscard() end end diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 0b721a7a..0132350b 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -487,7 +487,13 @@ end local function skipComment(isAction) local token = Tokens[Index + 1] if token == '--' - or (token == '//' and isAction) then + or ( + token == '//' + and ( + isAction + or State.options.nonstandardSymbol['//'] + ) + ) then local start = Tokens[Index] local left = getPosition(start, 'left') local chead = false @@ -1527,7 +1533,7 @@ local function parseTable() local index = 0 local wantSep = false while true do - skipSpace() + skipSpace(true) local token = Tokens[Index + 1] if token == '}' then Index = Index + 2 @@ -2094,6 +2100,7 @@ local function parseParams(params) start = getPosition(Tokens[Index], 'left'), finish = getPosition(Tokens[Index] + 2, 'right'), parent = params, + [1] = '...', } local chunk = Chunk[#Chunk] chunk.vararg = vararg @@ -2161,7 +2168,7 @@ local function parseFunction(isLocal, isAction) Index = Index + 2 local LastLocalCount = LocalCount LocalCount = 0 - skipSpace() + skipSpace(true) local hasLeftParen = Tokens[Index + 1] == '(' if not hasLeftParen then local name = parseName() @@ -2191,7 +2198,7 @@ local function parseFunction(isLocal, isAction) finish = simple.finish, } end - skipSpace() + skipSpace(true) hasLeftParen = Tokens[Index + 1] == '(' end end @@ -2222,7 +2229,7 @@ local function parseFunction(isLocal, isAction) params.parent = func func.args = params end - skipSpace() + skipSpace(true) if Tokens[Index + 1] == ')' then local parenRight = getPosition(Tokens[Index], 'right') func.finish = parenRight @@ -2230,7 +2237,7 @@ local function parseFunction(isLocal, isAction) params.finish = parenRight end Index = Index + 2 - skipSpace() + skipSpace(true) else func.finish = lastRightPosition() if params then @@ -2339,6 +2346,9 @@ local function parseBinaryOP(asAction, level) if not symbol then return nil end + if symbol == '//' and State.options.nonstandardSymbol['//'] then + return nil + end local myLevel = BinarySymbol[symbol] if level and myLevel < level then return nil |