Module:BucketGet: Difference between revisions

Created Module:BucketGet
 
Added upstream update and bug fixes for BucketGet
Line 4: Line 4:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local Bucket = mw.bucket
local Bucket = mw.bucket
local NULL = {}


local TYPE_ORDER = { ["nil"] = 1, number = 2, string = 3, boolean = 4, table = 5 }
local TYPE_ORDER = { ["nil"] = 1, number = 2, string = 3, boolean = 4, table = 5 }
Line 650: Line 651:
end
end


local T = { PARENTHESIS_L = 1, PARENTHESIS_R = 2, AND = 3, OR = 4, NOT = 5, COMP = 7, STR = 8, NUM = 9, BOOL = 10, ID = 11, EOF = 12 }
local T = { PARENTHESIS_L = 1, PARENTHESIS_R = 2, AND = 3, OR = 4, NOT = 5, NULL = 6, COMP = 7, STR = 8, NUM = 9, BOOL = 10, ID = 11, EOF = 12 }
local KW = {
local KW = {
['AND'] = T.AND,
['AND'] = T.AND,
Line 656: Line 657:
['NOT'] = T.NOT,
['NOT'] = T.NOT,
['true'] = T.BOOL,
['true'] = T.BOOL,
['false'] = T.BOOL
['false'] = T.BOOL,
['NULL'] = T.NULL,
}
}
local FILTER_OPS = { CONTAINS = true, ICONTAINS = true, MATCH = true }
local FILTER_OPS = { CONTAINS = true, ICONTAINS = true, MATCH = true }
Line 772: Line 774:
elseif op_tok and op_tok.type == T.COMP then
elseif op_tok and op_tok.type == T.COMP then
local v = toks[pos + 2]
local v = toks[pos + 2]
if v.type ~= T.STR and v.type ~= T.NUM and v.type ~= T.BOOL then
if v.type ~= T.STR and v.type ~= T.NUM and v.type ~= T.BOOL and v.type ~= T.NULL then
error("Expected value after comparison operator at position " .. (pos + 2))
error("Expected value after comparison operator at position " .. (pos + 2))
end
end
return { type = 'comparison', field = toks[pos].val, op = op_tok.val, value = v.val }, pos + 3
local value
if v.type == T.NULL then
value = NULL
elseif v.type == T.BOOL then
value = (v.val == 'true')
else
value = v.val
end
return { type = 'comparison', field = toks[pos].val, op = op_tok.val, value = value }, pos + 3
else
else
error("Expected comparison or filter operator after identifier at position " .. (pos + 1))
error("Expected comparison or filter operator after identifier at position " .. (pos + 1))
Line 797: Line 807:
return Bucket.Not(toBucket(n.operand))
return Bucket.Not(toBucket(n.operand))
elseif n.type == 'comparison' then
elseif n.type == 'comparison' then
return { n.field, n.op, n.value }
local val = (n.value == NULL) and Bucket.Null() or n.value
return { n.field, n.op, val }
end
end
end
end
Line 812: Line 823:


local COMP_FUNCS = {
local COMP_FUNCS = {
['=']  = function(a, b) return a == b end,
['=']  = function(a, b) if b == NULL then return a == nil end; return a == b end,
['!='] = function(a, b) return a ~= b end,
['!='] = function(a, b) if b == NULL then return a ~= nil end; return a ~= b end,
['<']  = function(a, b) return compareValues(a, b) == -1 end,
['<']  = function(a, b) return compareValues(a, b) == -1 end,
['>']  = function(a, b) return compareValues(a, b) == 1 end,
['>']  = function(a, b) return compareValues(a, b) == 1 end,
Line 989: Line 1,000:
   prefix = resultsHeader .. "\n"
   prefix = resultsHeader .. "\n"
end
end
 
if format == "table" then
if format == "table" then
text = formatTable(frame, results, columns, args)
text = formatTable(frame, results, columns, args)
Line 1,010: Line 1,021:
p.parseAggregateArg = parseAggregateArg
p.parseAggregateArg = parseAggregateArg
p.T = T
p.T = T
p.NULL = NULL
p.tokenize = tokenize
p.tokenize = tokenize
p.parseCond = parseCond
p.parseCond = parseCond