Модуль:SummaryII/types/string
< Модуль:SummaryII | types
Перейти к навигации
Перейти к поиску
String format | Case | Wikitext | Formatted |
---|---|---|---|
<<=re~ param <- ( quoted / plain / tail ) !. quoted <- item ( separator? item )* tail? item <- {| prefix? link suffix? |} link <- open !screen %s* value_quoted ( %s* pipe %s* alias )? %s* close atom <- screened / ( !open . ) prefix <- {:prefix: atom+ :} alias <- {:alias: ( !close . )+ :} suffix <- {:suffix: ( !separator atom )+ :} tail <- {:tail: atom+ :} plain <- {| value_plain |} ( separator {| value_plain |} )* tail? screened <- open screen (!close .)* close value_plain <- {:value: {/\d\d\.\d\d\d\.\d\d\d/} :} value_quoted <- {:value: {/\d\d\.\d\d\d\.\d\d\d/} :} open <- "[[" screen <- ":" pipe <- "|" close <- "]]" separator <- {:separator: ( ( "<br" ( %s* "/" )? ">" ) / [,;%nl] %s* ) %s* :} ~|<<|<<#|(<<?prefix>>)[[Has property::((<<value>>))<<|\|<<alias>>|>>]]<<?suffix>><<,|<<?separator>>>>|>>>>{<<?tail>>}>> | |||
\d\d\.\d\d\d\.\d\d\d | Single plain with suffix | 01.234.567 or something | ()[[Has property::((01.234.567))]]{ or something}
|
\d\d\.\d\d\d\.\d\d\d | Several quoted | 01.234.567 89.012.345 | ()[[Has property::((01.234.567))]] ()[[Has property::((89.012.345))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Single quoted | 01.234.567 | ()[[Has property::((01.234.567))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Separated plain | 01.234.567, 89.012.345 | ()[[Has property::((01.234.567))]], ()[[Has property::((89.012.345))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Screened and not | 01.234.567 89.012.345 | ([[:01.234.567]] )[[Has property::((89.012.345))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Screened and plain | 01.234.567 89.012.345 | {[[:01.234.567]] 89.012.345}
|
\d\d\.\d\d\d\.\d\d\d | Quoted but screened | 01.234.567 | {[[:01.234.567]]}
|
\d\d\.\d\d\d\.\d\d\d | Separated quoted | 01.234.567, 89.012.345 | ()[[Has property::((01.234.567))]], ()[[Has property::((89.012.345))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Single plain | 01.234.567 | ()[[Has property::((01.234.567))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Quoted with alias | you know | ()[[Has property::((01.234.567))|you know]]{}
|
\d\d\.\d\d\d\.\d\d\d | Single quoted with prefix | About 01.234.567 | (About )[[Has property::((01.234.567))]]{}
|
\d\d\.\d\d\d\.\d\d\d | Single quoted with suffix | 01.234.567 or something | ()[[Has property::((01.234.567))]] or something{}
|
\d\d\.\d\d\d\.\d\d\d | Single plain with prefix | About 01.234.567 | {About 01.234.567}
|
<<=re~ param <- ( quoted / plain / tail ) !. quoted <- item ( separator? item )* tail? item <- {| prefix? link suffix? |} link <- open !screen %s* value_quoted ( %s* pipe %s* alias )? %s* close atom <- screened / ( !open . ) prefix <- {:prefix: atom+ :} alias <- {:alias: ( !close . )+ :} suffix <- {:suffix: ( !separator atom )+ :} tail <- {:tail: atom+ :} plain <- {| value_plain |} ( separator {| value_plain |} )* tail? screened <- open screen (!close .)* close value_plain <- {:value: ( !separator !open !close . )+ :} value_quoted <- {:value: ( !pipe !close . )+ :} open <- "[[" screen <- ":" pipe <- "|" close <- "]]" separator <- {:separator: ( ( "<br" ( %s* "/" )? ">" ) / [,;%nl] %s* ) %s* :} ~|<<|<<#|(<<?prefix>>)[[Has property::((<<value>>))<<|\|<<alias>>|>>]]<<?suffix>><<,|<<?separator>>>>|>>>>{<<?tail>>}>> | |||
. | Single plain with suffix | 01.234.567 or something | ()[[Has property::((01.234.567 or something))]]{}
|
. | Several quoted | 01.234.567 89.012.345 | ()[[Has property::((01.234.567))]] ()[[Has property::((89.012.345))]]{}
|
. | Single quoted | 01.234.567 | ()[[Has property::((01.234.567))]]{}
|
. | Separated plain | 01.234.567, 89.012.345 | ()[[Has property::((01.234.567))]], ()[[Has property::((89.012.345))]]{}
|
. | Screened and not | 01.234.567 89.012.345 | ([[:01.234.567]] )[[Has property::((89.012.345))]]{}
|
. | Screened and plain | 01.234.567 89.012.345 | {[[:01.234.567]] 89.012.345}
|
. | Quoted but screened | 01.234.567 | {[[:01.234.567]]}
|
. | Separated quoted | 01.234.567, 89.012.345 | ()[[Has property::((01.234.567))]], ()[[Has property::((89.012.345))]]{}
|
. | Single plain | 01.234.567 | ()[[Has property::((01.234.567))]]{}
|
. | Quoted with alias | you know | ()[[Has property::((01.234.567))|you know]]{}
|
. | Single quoted with prefix | About 01.234.567 | (About )[[Has property::((01.234.567))]]{}
|
. | Single quoted with suffix | 01.234.567 or something | ()[[Has property::((01.234.567))]] or something{}
|
. | Single plain with prefix | About 01.234.567 | ()[[Has property::((About 01.234.567))]]{}
|
local dependencies = require 'Module:SummaryII/dependencies'
local p = require 'Module:SummaryII/types'
local concat = dependencies.join
local gsub = dependencies.gsub
function p.test (frame)
local tokens = dependencies.tokens
local open, pipe, close, equals, delim = tokens.open, tokens.pipe, tokens.close, tokens.equals, tokens.delim
local string_formats = {
['.'] = {
plain = '{:value: ( !separator !open !close . )+ :}',
quoted = '{:value: ( !pipe !close . )+ :}'
},
['\\d\\d\\.\\d\\d\\d\\.\\d\\d\\d'] = {
plain = '{:value: {/\\d\\d\\.\\d\\d\\d\\.\\d\\d\\d/} :}',
quoted = '{:value: {/\\d\\d\\.\\d\\d\\d\\.\\d\\d\\d/} :}'
}
}
local cases = {
['.'] = {
['Single plain'] = '01.234.567',
['Single plain with suffix'] = '01.234.567 or something',
['Single plain with prefix'] = 'About 01.234.567',
['Separated plain'] = '01.234.567, 89.012.345',
['Single quoted'] = '[[01.234.567]]',
['Single quoted with prefix'] = 'About [[01.234.567]]',
['Single quoted with suffix'] = '[[01.234.567]] or something',
['Quoted with alias'] = '[[01.234.567|you know]]',
['Several quoted'] = '[[01.234.567]] [[89.012.345]]',
['Separated quoted'] = '[[01.234.567]], [[89.012.345]]',
['Quoted but screened'] = '[[:01.234.567]]',
['Screened and not'] = '[[:01.234.567]] [[89.012.345]]',
['Screened and plain'] = '[[:01.234.567]] 89.012.345'
},
['\\d\\d\\.\\d\\d\\d\\.\\d\\d\\d'] = {
['Single plain'] = '01.234.567',
['Single plain with suffix'] = '01.234.567 or something',
['Single plain with prefix'] = 'About 01.234.567',
['Separated plain'] = '01.234.567, 89.012.345',
['Single quoted'] = '[[01.234.567]]',
['Single quoted with prefix'] = 'About [[01.234.567]]',
['Single quoted with suffix'] = '[[01.234.567]] or something',
['Quoted with alias'] = '[[01.234.567|you know]]',
['Several quoted'] = '[[01.234.567]] [[89.012.345]]',
['Separated quoted'] = '[[01.234.567]], [[89.012.345]]',
['Quoted but screened'] = '[[:01.234.567]]',
['Screened and not'] = '[[:01.234.567]] [[89.012.345]]',
['Screened and plain'] = '[[:01.234.567]] 89.012.345'
}
}
local result = { '{| class="wikitable"', '! String format !! Case !! Wikitext !! Formatted' }
for string_format, format_cases in pairs (cases) do
local plain = string_formats[string_format].plain
local quoted = string_formats[string_format].quoted
local flavour, regex = p.value (plain, quoted)
local format = open
.. equals .. flavour .. delim .. regex .. delim
.. pipe .. p.format 'Has property'
.. close
local formatter = dependencies.formatter (format)
result [#result + 1] = '|-\n| colspan="4" |\n'
.. frame:preprocess ( '<pre><nowiki>' .. format .. '</nowiki></pre>')
for title, wikitext in pairs (format_cases) do
local tbl = { param = wikitext }
result [#result + 1] = '|-'
result [#result + 1] = '| ' .. string_format
result [#result + 1] = '| ' .. title
result [#result + 1] = '| ' .. wikitext
result [#result + 1] = '| ' .. frame:preprocess ('<code><nowiki>'.. (type (formatter) == 'function'
and formatter (tbl)
or tostring (formatter)
) .. '</nowiki></code>')
end
end
result [#result + 1] = '|}'
return table.concat (result, '\n')
end
return p