Module:Sandbox/Erutuon: Difference between revisions

Content deleted Content added
m error in throwing invalid character error
error if no subtags follow x
Line 358:
local parsed_subtags_mt = {}
parsed_subtags_mt.__index = parsed_subtags_mt
setmetatable(parsed_subtags_mt, parsed_subtags_mt)
 
function parsed_subtags_mt:throw(error, index)
self.error = error
Line 363 ⟶ 365:
return self:remove_unnecessary_fields()
end
 
function parsed_subtags_mt:remove_unnecessary_fields()
-- Only useful internally.
self.input = nil
return setmetatable(self, nil)
end
 
function parsed_subtags_mt:__call(input)
return setmetatable({ input = input }, self)
end
Line 378 ⟶ 385:
-- Returns nil if tag is not a string or empty.
-- Else returns a table with a map of subtag type to subtag for all subtags that
-- were parsed.
-- If there was an error, returns an "error" field with a description of the
-- description of the error, and an "invalid" field with the suffix of the tag starting at the
-- starting at the index where the error occurred.
 
-- Does not recognize "extension" tags, such as those introduced by "u" and
-- described here, as they are not needed on Wikipedia:
Line 397 ⟶ 406:
-- "invalid" is the portion of the tag after the last valid subtag (minus a
-- hyphen).
local potential_subtags = mw.text.split(tag, "-")
local parsed_subtags = {}
setmetatable(local parsed_subtags, = parsed_subtags_mt(potential_subtags)
local matched_count = 0
local potential_subtags = mw.text.split(tag, "-")
parsed_subtags.input = potential_subtags
-- Language tags probably only contain ASCII alphabetic and numerical
Line 470 ⟶ 476:
if potential_subtags[last_matched_subtag_i + 1] == "x" then
-- Check length of all following subtags.
forif i =not potential_subtags[last_matched_subtag_i + 1, #potential_subtags2] dothen
return parsed_subtags:throw("empty private-use subtag",
last_matched_subtag_i + 1)
end
for i = last_matched_subtag_i + 2, #potential_subtags do
local length = #potential_subtags[i]