diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-08-30 18:36:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-08-30 18:36:54 +0800 |
commit | 4ac49f6c54f44658beb46e362d7afedf311905f3 (patch) | |
tree | f42a3fcae48a28adc516338da26fdf89b0bb4aa2 | |
parent | f7965043138d450d16c89694ce218523c7c59c89 (diff) | |
download | lua-language-server-4ac49f6c54f44658beb46e362d7afedf311905f3.zip |
update
-rw-r--r-- | meta/whimsical/builtin.lua | 110 | ||||
-rw-r--r-- | meta/whimsical/rule.lua | 122 |
2 files changed, 128 insertions, 104 deletions
diff --git a/meta/whimsical/builtin.lua b/meta/whimsical/builtin.lua index 6521bb4b..17905798 100644 --- a/meta/whimsical/builtin.lua +++ b/meta/whimsical/builtin.lua @@ -1,110 +1,13 @@ ---@meta _ ---[[@@@ ----@inner class -> { - self.istruly = true - self.truly = self - self.falsy = Class 'never' - self.view = self.name -} ----@inner integer -> { - self.istruly = true - self.truly = self - self.falsy = Class 'never' - self.view = tostring(self.value) -} ----@inner string -> { - self.istruly = true - self.truly = self - self.falsy = Class 'never' - self.view = cat.util.viewString(self.value, self.quotation) -} ----@inner union -> { - self.istruly = function (subs) - local istruly = subs[1].istruly - if istruly == nil then - return nil - end - if istruly == true then - for i = 2, #subs do - if subs[i].istruly ~= true then - return nil - end - end - return true - else - for i = 2, #subs do - if subs[i].istruly ~= false then - return nil - end - end - return false - end - return nil - end - self.truly = function (subs) - local union = Union() - for i = 1, #subs do - union:add(subs[i].truly) - end - if union:len() == 0 then - return Class 'never' - end - if union:len() == 1 then - return union:first() - end - return union - end - self.falsy = function (subs) - local union = Union() - for i = 1, #subs do - union:add(subs[i].falsy) - end - if union:len() == 0 then - return Class 'never' - end - if union:len() == 1 then - return union:first() - end - return union - end - self.view = function (subs) - local views = {} - for i = 1, #subs do - views[i] = subs[i].view - end - if #views == 0 then - return 'never' - end - return table.concat(views, '|') - end -} ----@class nil -> { - self.istruly = false - self.truly = Class 'never' - self.falsy = self -} ----@class never -> { - self.istruly = nil -} ----@class true -> { - self.istruly = true - self.truly = self - self.falsy = Class 'never' -} ----@class false -> { - self.istruly = false - self.truly = Class 'never' - self.falsy = self -} ----@class any: { [unknown]: any } -> { - self.istruly = nil - self.truly = Class 'truly' - self.falsy = Class 'false' | Class 'nil' -} +---@class nil +---@class never +---@class true +---@class false +---@class any: { [unknown]: any } ---@class truly: { [unknown]: any } ---@class unknown: truly | false ----@class boolean: true | false +---@class boolean ---@class number ---@class thread ---@class table: { [unknown]: any } @@ -113,4 +16,3 @@ ---@class userdata: { [unknown]: any } ---@class lightuserdata ---@class function: fun(...): ... -]] diff --git a/meta/whimsical/rule.lua b/meta/whimsical/rule.lua new file mode 100644 index 00000000..2cfe865f --- /dev/null +++ b/meta/whimsical/rule.lua @@ -0,0 +1,122 @@ +local cat + +cat.rule.inner.default = function (self) + self.istruly = true + self.truly = self + self.falsy = cat.class 'never' + self.view = self.name +end + +cat.rule.inner.never = function (self) + self.istruly = nil +end + +cat.rule.inner.any = function (self) + self.istruly = nil + self.truly = cat.class 'truly' + self.falsy = cat.boolean(false) | cat.class 'nil' +end + +cat.rule.inner['nil'] = function (self) + self.istruly = false + self.truly = cat.class 'never' + self.falsy = self +end + +cat.rule.inner.boolean = function (self) + if self.value == true then + self.istruly = true + self.truly = self + self.falsy = cat.class 'never' + elseif self.value == false then + self.istruly = false + self.truly = cat.class 'never' + self.falsy = self + else + self.istruly = nil + self.truly = cat.boolean(true) + self.falsy = cat.boolean(false) + end +end + +cat.rule.inner.number = function (self) + self.istruly = true + self.truly = self + self.falsy = cat.class 'never' + self.view = tostring(self.value) +end + +cat.rule.inner.integer = function (self) + self.istruly = true + self.truly = self + self.falsy = cat.class 'never' + self.view = tostring(self.value) +end + +cat.rule.inner.string = function (self) + self.istruly = true + self.truly = self + self.falsy = cat.class 'never' + self.view = cat.util.viewString(self.value, self.quotation) +end + +cat.rule.inner.union = function (self) + self.istruly = function (union) + local istruly = union.subs[1].istruly + if istruly == nil then + return nil + end + if istruly == true then + for i = 2, #union.subs do + if union.subs[i].istruly ~= true then + return nil + end + end + return true + else + for i = 2, #union.subs do + if union.subs[i].istruly ~= false then + return nil + end + end + return false + end + return nil + end + self.truly = function (union) + local new = cat.union() + for i = 1, #union.subs do + new:add(union.subs[i].truly) + end + if new:len() == 0 then + return cat.class 'never' + end + if new:len() == 1 then + return new[1] + end + return new + end + self.falsy = function (union) + local new = cat.union() + for i = 1, #union.subs do + new:add(union.subs[i].falsy) + end + if new:len() == 0 then + return cat.class 'never' + end + if new:len() == 1 then + return new[1] + end + return new + end + self.view = function (union) + local views = {} + for i = 1, #union.subs do + views[i] = union.subs[i].view + end + if #views == 0 then + return 'never' + end + return table.concat(views, '|') + end +end |