diff options
-rw-r--r-- | server/src/parser/ast.lua | 50 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 22 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 6 |
3 files changed, 48 insertions, 30 deletions
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 3b397c0d..136d7565 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -629,8 +629,10 @@ local Defs = { end if isField then table[#table+1] = arg - wantField = false - start = arg.finish + 1 + if arg.finish then + wantField = false + start = arg.finish + 1 + end else wantField = true start = arg @@ -646,8 +648,7 @@ local Defs = { key, value, } end, - NewIndex = function (start, key, finish, value) - key.index = true + NewIndex = function (key, value) return { type = 'pair', start = key.start, @@ -1113,7 +1114,10 @@ local Defs = { [1] = '' } end, - EmmyClass = function (class, extends) + EmmyClass = function (class, startPos, extends) + if extends and extends[1] == '' then + extends.start = startPos + end return { type = 'emmyClass', start = class.start, @@ -1122,17 +1126,26 @@ local Defs = { [2] = extends, } end, - EmmyType = function (typeDef, ...) - if ... then - typeDef.enum = {...} - end + EmmyType = function (typeDef) return typeDef end, EmmyCommonType = function (...) - return { + local result = { type = 'emmyType', ... } + for i = 1, #result // 2 do + local startPos = result[i * 2] + local emmyName = result[i * 2 + 1] + if emmyName[1] == '' then + emmyName.start = startPos + end + result[i + 1] = emmyName + end + for i = #result // 2 + 2, #result do + result[i] = nil + end + return result end, EmmyArrayType = function (typeName) typeName.type = 'emmyArrayType' @@ -1145,23 +1158,26 @@ local Defs = { return typeName end, EmmyFunctionType = function (...) - return { + local result = { type = 'emmyFunctionType', ... } + return result end, - EmmyAlias = function (name, emmyName) + EmmyAlias = function (name, emmyName, ...) return { type = 'emmyAlias', - [1] = name, - [2] = emmyName, + name, + emmyName, + ... } end, - EmmyParam = function (argName, emmyName) + EmmyParam = function (argName, emmyName, ...) return { type = 'emmyParam', - [1] = argName, - [2] = emmyName, + argName, + emmyName, + ... } end, EmmyReturn = function (...) diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 6743ed89..42e52d05 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -306,11 +306,12 @@ Simple <- (Prefix (Sp Suffix)*) Prefix <- Sp ({} PL DirtyExp DirtyPR) -> Prefix / FreeName +Index <- ({} BL DirtyExp DirtyBR) -> Index Suffix <- DOT Name / DOT {} -> MissField / Method (!(Sp CallStart) {} -> MissPL)? / ({} Table {}) -> Call / ({} String {}) -> Call - / ({} BL DirtyExp DirtyBR) -> Index + / Index / ({} PL CallArgList DirtyPR) -> Call Method <- COLON Name / COLON {} -> MissMethod CallStart <- PL @@ -338,10 +339,10 @@ ArgList <- (DOTS / Name / Sp {} COMMA)* Table <- Sp ({} TL TableFields? DirtyTR) -> Table -TableFields <- (TableSep {} / TableField)+ +TableFields <- (Emmy / TableSep {} / TableField)+ TableSep <- COMMA / SEMICOLON TableField <- NewIndex / NewField / Exp -NewIndex <- Sp ({} BL DirtyExp DirtyBR NeedAssign DirtyExp) +NewIndex <- Sp (Index NeedAssign DirtyExp) -> NewIndex NewField <- (MustName ASSIGN DirtyExp) -> NewField @@ -362,6 +363,7 @@ LabelEnd <- {} -> LabelEnd -- 纯占位,修改了 `relabel.lua` 使重复定义不抛错 Action <- !END . Set <- END +Emmy <- '---@' ]] grammar 'Action' [[ @@ -533,26 +535,24 @@ EmmyIncomplete <- MustEmmyName -> EmmyIncomplete EmmyClass <- (MustEmmyName EmmyParentClass?) -EmmyParentClass <- %s* ':' %s* MustEmmyName +EmmyParentClass <- %s* {} ':' %s* MustEmmyName -EmmyType <- (EmmyTypeDef EmmyTypeEnums*) - -> EmmyType -EmmyTypeDef <- EmmyFunctionType +EmmyType <- EmmyFunctionType / EmmyArrayType / EmmyTableType / EmmyCommonType EmmyCommonType <- EmmyTypeNames -> EmmyCommonType -EmmyTypeNames <- EmmyTypeName ('|' EmmyTypeName)* +EmmyTypeNames <- EmmyTypeName (%s* {} '|' %s* !String EmmyTypeName)* EmmyTypeName <- EmmyFunctionType / EmmyArrayType / EmmyTableType / MustEmmyName -EmmyTypeEnums <- %s+ '|' %s+ String +EmmyTypeEnums <- %s* '|' %s* String -EmmyAlias <- MustEmmyName %s+ EmmyType +EmmyAlias <- MustEmmyName %s+ EmmyType EmmyTypeEnums* -EmmyParam <- MustEmmyName %s+ EmmyType +EmmyParam <- MustEmmyName %s+ EmmyType EmmyTypeEnums* EmmyReturn <- EmmyType diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 0e84468b..57301ed5 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -47,8 +47,8 @@ function mt:buildTable(source) self:instantSource(obj) self:instantSource(key) key:bindValue(value, 'set') - if key.index then - local index = self:getIndex(obj) + if key.type == 'index' then + local index = self:getIndex(key) key:set('parent', tbl) tbl:setChild(index, value, key) else @@ -695,6 +695,8 @@ function mt:getExp(exp) return value elseif tp == 'simple' then return self:getSimple(exp) + elseif tp == 'index' then + return self:getIndex(exp) elseif tp == 'binary' then return self:getBinary(exp) elseif tp == 'unary' then |