summaryrefslogtreecommitdiff
path: root/script/parser/luadoc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/parser/luadoc.lua')
-rw-r--r--script/parser/luadoc.lua45
1 files changed, 35 insertions, 10 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index d8e31950..99ef8781 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -12,11 +12,13 @@ local Parser = re.compile([[
Main <- (Token / Sp)*
Sp <- %s+
X16 <- [a-fA-F0-9]
-Token <- Integer / Name / String / Symbol
+Token <- Integer / Name / String / Code / Symbol
Name <- ({} {%name} {})
-> Name
Integer <- ({} {[0-9]+} !'.' {})
-> Integer
+Code <- ({} '`' { (!'`' .)*} '`' {})
+ -> Code
String <- ({} StringDef {})
-> String
StringDef <- {'"'}
@@ -48,7 +50,7 @@ EChar <- 'a' -> ea
/ ([0-9] [0-9]? [0-9]?) -> Char10
/ ('u{' {X16*} '}') -> CharUtf8
Symbol <- ({} {
- [:|,<>()?+#`{}]
+ [:|,<>()?+#{}]
/ '[]'
/ '...'
/ '['
@@ -114,6 +116,13 @@ Symbol <- ({} {
TokenFinishs[Ci] = finish - 1
TokenContents[Ci] = math.tointeger(content)
end,
+ Code = function (start, content, finish)
+ Ci = Ci + 1
+ TokenTypes[Ci] = 'code'
+ TokenStarts[Ci] = start
+ TokenFinishs[Ci] = finish - 1
+ TokenContents[Ci] = content
+ end,
Symbol = function (start, content, finish)
Ci = Ci + 1
TokenTypes[Ci] = 'symbol'
@@ -534,6 +543,22 @@ local function parseString(parent)
return str
end
+local function parseCode(parent)
+ local tp, content = peekToken()
+ if not tp or tp ~= 'code' then
+ return nil
+ end
+ nextToken()
+ local code = {
+ type = 'doc.type.code',
+ start = getStart(),
+ finish = getFinish(),
+ parent = parent,
+ [1] = content,
+ }
+ return code
+end
+
local function parseInteger(parent)
local tp, content = peekToken()
if not tp or tp ~= 'integer' then
@@ -584,23 +609,16 @@ function parseTypeUnit(parent)
local result = parseFunction(parent)
or parseTable(parent)
or parseString(parent)
+ or parseCode(parent)
or parseInteger(parent)
or parseBoolean(parent)
or parseDots('doc.type.name', parent)
or parseParen(parent)
if not result then
- local literal = checkToken('symbol', '`', 1)
- if literal then
- nextToken()
- end
result = parseName('doc.type.name', parent)
if not result then
return nil
end
- if literal then
- result.literal = true
- nextSymbolOrError '`'
- end
end
while true do
local newResult = parseTypeUnitSign(parent, result)
@@ -1418,6 +1436,13 @@ local function bindGeneric(binded)
src.type = 'doc.generic.name'
end
end)
+ guide.eachSourceType(doc, 'doc.type.code', function (src)
+ local name = src[1]
+ if generics[name] then
+ src.type = 'doc.generic.name'
+ src.literal = true
+ end
+ end)
end
end
end