Module:Road data/parser/hooks and Module:Road data/parser/hooks/sandbox: Difference between pages
(Difference between pages)
imported>Ahecht Avoid errors for routes with a letter (e.g. Brazil's 174B) |
imported>Chinissai m Corrected parser argument order. |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local parserModuleName = "Module:Road data/parser" | -- Change to "" upon deployment. | ||
local moduleSuffix = "/sandbox" | |||
local parserModuleName = "Module:Road data/parser" .. moduleSuffix | |||
function p.split(parameters, args) | function p.split(parameters, args) | ||
local route = tonumber | local route = tonumber(args.route) or 0 | ||
if route < parameters.split then | if route < parameters.split then | ||
return parameters.below | return parameters.below | ||
| Line 24: | Line 27: | ||
local lower = parameters.lower | local lower = parameters.lower | ||
local upper = parameters.upper | local upper = parameters.upper | ||
local route = tonumber | local route = tonumber(args.route) or 0 | ||
if route < lower or route >= upper then | if route < lower or route >= upper then | ||
return parameters.no | return parameters.no | ||
| Line 42: | Line 45: | ||
function p.padroute(parameters, args) | function p.padroute(parameters, args) | ||
local route = | local route = args.route | ||
local paddedLength = parameters.paddedLength | local paddedLength = parameters.paddedLength | ||
args.paddedRoute = | args.paddedRoute = string.format("%0" .. tostring(paddedLength) .. "d", route) | ||
return parameters.default | return parameters.default | ||
end | end | ||
| Line 75: | Line 76: | ||
--[[ | --[[ | ||
For the first element (pattern, action) in .actions such that | For the first element (pattern, action) in .actions such that | ||
require(Module:Road data/parser).parser(args, .entry, . | require(Module:Road data/parser).parser(args, .entry, .kind, .path) | ||
matches pattern as a regular expression, return action. | matches pattern as a regular expression, return action. | ||
If no such element exists, return .default (nil if unspecified). | If no such element exists, return .default (nil if unspecified). | ||
. | .kind and .path are optional. | ||
]] | ]] | ||
function p.match(parameters, args) | function p.match(parameters, args) | ||
| Line 86: | Line 87: | ||
local entry = parameters.entry | local entry = parameters.entry | ||
local kind = parameters.kind | |||
local path = parameters.path | local path = parameters.path | ||
local actions = parameters.actions | local actions = parameters.actions | ||
local value = parser(args, entry, path | local value = parser(args, entry, kind, path) | ||
for pattern,action in pairs(actions) do | for pattern,action in pairs(actions) do | ||
if mw.ustring.match(value, pattern) then | if mw.ustring.match(value, pattern) then | ||
| Line 97: | Line 98: | ||
return parameters.default | return parameters.default | ||
end | end | ||
return p | return p | ||