Module:TemplatePar: Difference between revisions

Content deleted Content added
Migration zur Umparametrisierung abgeschlossen; keine Einbindungen mehr
update
Line 1:
--[=[ TemplatePar 2013-06-0110
Template parameter utility
* assert
* check
* count
Line 108 ⟶ 109:
end
return r
end -- factorycontainsCJK()
 
 
Line 545 ⟶ 546:
 
 
local function format( seekanalyze, options )
-- Check validity of onea particular template parametervalue
-- Precondition:
-- seek analyze -- string non-empty; name ofto templatebe parameteranalyzed
-- options -- table or nil; optional details
-- options.pattern
-- options.key
-- options.lowsay
-- options.min
-- options.max
Line 560 ⟶ 561:
-- Uses:
-- > Patterns
-- TemplatePar.downcase()
-- mw.getCurrentFrame()
-- frame:getParent()
-- failure()
-- mw.text.trim()
-- failsafe()
-- containsCJK()
local r = false
local s = false
local scan show = falsenil
local storyscan = false
if type( options.pattern ) ~== "tablestring" then
if options.key = { }then
r = failure( "dupRule", false, options )
end
if options.low then else
scan = options.pattern
story = TemplatePar.downcase( options )
end
else
if type( options.key ) == "string" then
story = mw.getCurrentFrame():getParent()
s = mw.text.trim( options.key )
end
if type( story ) == "table" then
story = ( story.args[ seek ] or "" )
if type( options.pattern ) == "string" then
if options.key then
r = failure( "dupRule", false, options )
else
scan = options.pattern
end
else
if type( options.key )s == "string+" then
end
s = mw.text.trim( options.key )
scan = Patterns[ s else]
if type( scan s) == "+string" then
endif s == "n" or s == "0,0" or s == "0.0" then
scan = Patterns[ s if not analyze:match( "[0-9]" ) then
if type( scan ) == "string" then scan = false
if s == "n" or s == "0,0" or s ==if "0options.0"say then
if not story:match( show = "[0-9]'" ).. thenoptions.say .. "'"
scan = false
r = failure( "invalid",
"'" .. seek .. "'",
options )
end
r = failure( "invalid", show, options )
end
else
r = failure( "unknownRule", s, options )
end
else
r = failure( "unknownRule", s, options )
end
else
r = story
end
if scan then
local legal, got = pcall( failsafe, storyanalyze, scan )
if legal then
if not got then
if s == "aa" then
got = containsCJK( storyanalyze )
end
if not got then
seekif = "'" .. seek .options.say "'"then
r show = failure( "invalid'", seek,.. options.say ).. "'"
end
r = failure( "invalid", show, options )
end
end
Line 639 ⟶ 627:
end
end
if #storyanalyze < options.min and not r then
rshow = failure(" <"tooShort", .. options.min
" <" ..if options.min .. " '" .. seek ..say "'",then
show = show .. " '" .. options.say .. options )"'"
end
r = failure( "tooShort", show, options )
end
else
Line 650 ⟶ 640:
if options.max and not r then
if type( options.max ) == "number" then
if #storyanalyze > options.max then
rshow = failure(" >"tooLong", .. options.max
" >" ..if options.max .. " '" .. seek ..say "'",then
show = show .. " '" .. options.say .. options )"'"
end
r = failure( "tooLong", show, options )
end
else
Line 661 ⟶ 653:
return r
end -- format()
 
 
 
local function formatted( assignment, access, options )
-- Check validity of one particular parameter in a collection
-- Precondition:
-- assignment -- collection
-- access -- id of parameter in collection
-- options -- table or nil; optional details
-- Postcondition:
-- Return string with error message as configured;
-- false if valid or no answer permitted
-- Uses:
-- > Patterns
-- failure()
-- mw.text.trim()
-- format()
-- failure()
local r = false
if type( assignment ) == "table" then
local story = assignment.args[ access ]
if type( story ) == "string" then
if type( options ) ~= "table" then
options = { }
end
options.say = access
r = format( story, options )
else
r = failure( "invalid", access, options )
end
end
return r
end -- formatted()
 
 
 
TemplatePar.assert = function ( analyze, append, options )
-- Perform parameter analysis on a single string
-- Precondition:
-- analyze -- string to be analyzed
-- append -- string: append error message, prepending <br />
-- false or nil: throw error with message
-- options -- table; optional details
-- Postcondition:
-- Return string with error message as configured;
-- false if valid
-- Uses:
-- format()
local r = format( analyze, options )
if ( r ) then
if ( type( append ) == "string" ) then
if ( append ~= "" ) then
r = append .. "<br />" .. r
end
else
error( r, 0 )
end
end
return r
end -- TemplatePar.assert()
 
 
Line 738 ⟶ 790:
 
 
TemplatePar.valid = function ( seekaccess, options )
-- Check validity of one particular template parameter
-- Precondition:
-- seek access -- string; nameid of parameter in template parametertransclusion
-- options -- table or nil; optional details
-- Postcondition:
Line 748 ⟶ 800:
-- Uses:
-- mw.text.trim()
-- formatTemplatePar.downcase()
-- mw.getCurrentFrame()
-- frame:getParent()
-- formatted()
-- failure()
-- finalize()
local r
if type( seekaccess ) == "string" then
r = mw.text.trim( seekaccess )
if #r == 0 then
r = false
Line 759 ⟶ 814:
end
if r then
rlocal = format( seek, options )params
if type( options ) ~= "table" then
options = { }
end
if options.low then
params = TemplatePar.downcase( options )
else
params = mw.getCurrentFrame():getParent()
end
r = formatted( params, access, options )
else
r = failure( "noname", false, options )
Line 905 ⟶ 969:
else
s = frame.args[ 1 ] or ""
r = tonumber( s )
if ( r ) then
s = r
end
r = TemplatePar.valid( s, options )
end