summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-17 21:23:52 +0800
committersumneko <sumneko@hotmail.com>2019-04-17 21:23:52 +0800
commit085ad34e5ea996d2af23dcb574742dd6880cee65 (patch)
treefeb512db226bbd1ac6124d6ba3ee95319ce3bfc8 /server
parentb62070c2e217bd90a7c00fefd0167c1b828128fa (diff)
downloadlua-language-server-085ad34e5ea996d2af23dcb574742dd6880cee65.zip
更新 LuaParser
Diffstat (limited to 'server')
-rw-r--r--server/src/parser/ast.lua112
-rw-r--r--server/src/parser/grammar.lua80
2 files changed, 191 insertions, 1 deletions
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index ba40a060..839f9b76 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1090,6 +1090,118 @@ local Defs = {
return {...}
end,
+ -- EmmyLua 支持
+ EmmyName = function (start, str)
+ return {
+ type = 'emmyName',
+ start = start,
+ finish = start + #str - 1,
+ [1] = str,
+ }
+ end,
+ DirtyEmmyName = function (pos)
+ pushError {
+ type = 'MISS_NAME',
+ start = pos,
+ finish = pos,
+ }
+ return {
+ type = 'emmyName',
+ start = pos,
+ finish = pos,
+ [1] = ''
+ }
+ end,
+ EmmyClass = function (class, extends)
+ return {
+ type = 'emmyClass',
+ [1] = class,
+ [2] = extends,
+ }
+ end,
+ EmmyType = function (typeDef, ...)
+ if ... then
+ typeDef.enum = {...}
+ end
+ return typeDef
+ end,
+ EmmyCommonType = function (...)
+ return {
+ type = 'emmyType',
+ ...
+ }
+ end,
+ EmmyArrayType = function (typeName)
+ typeName.type = 'emmyArrayType'
+ return typeName
+ end,
+ EmmyTableType = function (typeName, keyType, valueType)
+ typeName.type = 'emmyTableType'
+ typeName[2] = keyType
+ typeName[3] = valueType
+ return typeName
+ end,
+ EmmyFunctionType = function (...)
+ return {
+ type = 'emmyFunctionType',
+ ...
+ }
+ end,
+ EmmyAlias = function (name, emmyName)
+ return {
+ type = 'emmyAlias',
+ [1] = name,
+ [2] = emmyName,
+ }
+ end,
+ EmmyParam = function (argName, emmyName)
+ return {
+ type = 'emmyParam',
+ [1] = argName,
+ [2] = emmyName,
+ }
+ end,
+ EmmyReturn = function (...)
+ return {
+ type = 'emmyReturn',
+ ...
+ }
+ end,
+ EmmyField = function (access, fieldName, ...)
+ return {
+ type = 'emmyField',
+ access, fieldName,
+ ...
+ }
+ end,
+ EmmyGenericBlock = function (genericName, parentName)
+ return { genericName, parentName }
+ end,
+ EmmyGeneric = function (...)
+ return {
+ type = 'emmyGeneric',
+ ...
+ }
+ end,
+ EmmyVararg = function (typeName)
+ return {
+ type = 'emmyVararg',
+ typeName,
+ }
+ end,
+ EmmyLanguage = function (language)
+ return {
+ type = 'emmyLanguage',
+ language,
+ }
+ end,
+ EmmySee = function (className, methodName)
+ return {
+ type = 'emmySee',
+ className, methodName
+ }
+ end,
+
-- 捕获错误
UnknownSymbol = function (start, symbol)
pushError {
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index d0a2baaf..c2d2a2a5 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -365,7 +365,8 @@ Set <- END
]]
grammar 'Action' [[
-Action <- Sp (CrtAction / UnkAction)
+Action <- Emmy
+ / Sp (CrtAction / UnkAction)
CrtAction <- Semicolon
/ Do
/ Break
@@ -502,6 +503,83 @@ FunctionNamedBody
FuncName <- (MustName (DOT MustName)* FuncMethod?)
-> Simple
FuncMethod <- COLON Name / COLON {} -> MissMethod
+
+-- 占位
+Emmy <- '---@'
+]]
+
+grammar 'Emmy' [[
+Emmy <- '---@' EmmyBody ShortComment %nl*
+EmmyBody <- 'class' %s+ EmmyClass -> EmmyClass
+ / 'type' %s+ EmmyType -> EmmyType
+ / 'alias' %s+ EmmyAlias -> EmmyAlias
+ / 'param' %s+ EmmyParam -> EmmyParam
+ / 'return' %s+ EmmyReturn -> EmmyReturn
+ / 'field' %s+ EmmyField -> EmmyField
+ / 'generic' %s+ EmmyGeneric -> EmmyGeneric
+ / 'vararg' %s+ EmmyVararg -> EmmyVararg
+ / 'language' %s+ EmmyLanguage -> EmmyLanguage
+ / 'see' %s+ EmmySee -> EmmySee
+
+EmmyName <- ({} {[a-zA-Z_] [a-zA-Z0-9_]*})
+ -> EmmyName
+MustEmmyName <- EmmyName / DirtyEmmyName
+DirtyEmmyName <- {} -> DirtyEmmyName
+EmmyLongName <- ({} {(!%nl .)+})
+ -> EmmyName
+
+EmmyClass <- (MustEmmyName EmmyParentClass?)
+EmmyParentClass <- %s* ':' %s* MustEmmyName
+
+EmmyType <- (EmmyTypeDef EmmyTypeEnums*)
+ -> EmmyType
+EmmyTypeDef <- EmmyFunctionType
+ / EmmyArrayType
+ / EmmyTableType
+ / EmmyCommonType
+EmmyCommonType <- EmmyTypeNames
+ -> EmmyCommonType
+EmmyTypeNames <- EmmyTypeName ('|' EmmyTypeName)*
+EmmyTypeName <- EmmyFunctionType
+ / EmmyArrayType
+ / EmmyTableType
+ / MustEmmyName
+EmmyTypeEnums <- %s+ '|' %s+ String
+
+EmmyAlias <- MustEmmyName %s+ EmmyType
+
+EmmyParam <- MustEmmyName %s+ EmmyType
+
+EmmyReturn <- EmmyType
+
+EmmyField <- (EmmyFieldAccess MustEmmyName %s+ EmmyType)
+EmmyFieldAccess <- ({'public'} %s+)
+ / ({'protected'} %s+)
+ / ({'private'} %s+)
+ / {} -> 'public'
+
+EmmyGeneric <- EmmyGenericBlock
+ (%s* ',' %s* EmmyGenericBlock)*
+EmmyGenericBlock<- (MustEmmyName %s* (':' %s* EmmyType)?)
+ -> EmmyGenericBlock
+
+EmmyVararg <- EmmyType
+
+EmmyLanguage <- MustEmmyName
+
+EmmyArrayType <- (MustEmmyName '[]')
+ -> EmmyArrayType
+
+EmmyTableType <- (MustEmmyName '<' %s* EmmyType %s* ',' %s* EmmyType %s* '>')
+ -> EmmyTableType
+
+EmmyFunctionType<- ('fun' Cut %s* EmmyFunctionArgs? %s* EmmyFunctionRtn?)
+ -> EmmyFunctionType
+EmmyFunctionArgs<- '(' %s* EmmyFunctionArg %s* (',' %s* EmmyFunctionArg %s*)* ')'
+EmmyFunctionRtn <- ':' %s* EmmyType
+EmmyFunctionArg <- MustEmmyName %s* ':' %s* EmmyType
+
+EmmySee <- MustEmmyName '#' MustEmmyName
]]
grammar 'Lua' [[