Модуль:SummaryII/test2
Перейти к навигации
Перейти к поиску
<< = re~ param <- ( quoted / plain ) !. quoted <- link ( separator? link )* tail? link <- {| prefix? open !screen %s* title_quoted ( %s* pipe %s* alias )? %s* close suffix? |} prefix <- {:prefix: ( !( open !screen ) . )+ :} alias <- {:alias: ( !close . )+ :} suffix <- {:suffix: ( !separator !( open !screen ) . )+ :} tail <- {:tail: .+ :} plain <- title_plain ( separator title_plain )* tail? title_plain <- {| {:title: ( !separator legal )+ :} |} title_quoted <- {:title: ( !pipe !close legal )+ :} open <- "[[" screen <- ":" pipe <- "|" close <- "]]" separator <- {:separator: ( "<br" %s* "/>" ) / [,;%nl] :} legal <- [^]#<>[|{}_] ~|<<#|<<?prefix>>[[Has property::<<title>><<|\|<<alias>>|>>]]<<?suffix>><<,|<<?separator>>>>>><<?tail>> >>
Case | Wikitext | Parsed | Formatted |
---|---|---|---|
Quoted, ,-separated | Title1, title2 | table#1 {
|
[[Has property::Title1]], [[Has property::title2]] |
Plain text, NL-separated | Plain 1
Plain 2 |
table#1 {
|
[[Has property::Plain 1]] [[Has property::Plain 2]] |
Aliases, prefixes | Two titles 1 and 2 | table#1 {
|
Two titles [[Has property::Title1|1]] and [[Has property::Title2|2]] |
Quoted, ,-separated, suffices | Title1 (before), title2 (now) | table#1 {
|
[[Has property::Title1]] (before), [[Has property::title2]] (now) |
Quoted | Title | table#1 {
|
[[Has property::Title]] |
Plain text | Plain text 1 | table#1 {
|
[[Has property::Plain text 1]] |
Alias and no alias | Alias, Title2 | table#1 {
|
[[Has property::Title1|Alias]], [[Has property::Title2]] |
Screened | Title (in 1942) | table#1 {
|
[[Has property::Title]] (in [[:1942]]) |
Quoted, not separated | Title1 and title2 | table#1 {
|
[[Has property::Title1]] and [[Has property::title2]] |
Tail | Title (in 1942), allegedly | table#1 {
|
[[Has property::Title]] (in [[:1942]]), allegedly |
Alias | Alias | table#1 {
|
[[Has property::Title|Alias]] |
Plain text, ,-separated | Plain text 1, plain text 2 | table#1 {
|
[[Has property::Plain text 1]],[[Has property:: plain text 2]] |
local dependencies = require 'Module:SummaryII/dependencies'
local re = require 'Module:Re'
local grammar = [==[
param <- ( quoted / plain ) !.
quoted <- link ( separator? link )* tail?
link <- {| prefix? open !screen %s* title_quoted ( %s* pipe %s* alias )? %s* close suffix? |}
prefix <- {:prefix: ( !( open !screen ) . )+ :}
alias <- {:alias: ( !close . )+ :}
suffix <- {:suffix: ( !separator !( open !screen ) . )+ :}
tail <- {:tail: .+ :}
plain <- title_plain ( separator title_plain )* tail?
title_plain <- {| {:title: ( !separator legal )+ :} |}
title_quoted <- {:title: ( !pipe !close legal )+ :}
open <- "[["
screen <- ":"
pipe <- "|"
close <- "]]"
separator <- {:separator: ( "<br" %s* "/>" ) / [,;%nl] :}
legal <- [^]#<>[|{}_]
]==]
local lpeg = lpeg
local Cp, Ct = lpeg.Cp, lpeg.Ct
local compiled = Cp() * Ct (re.compile (grammar)) * Cp()
local format_string = '<< = re~' .. grammar .. '~|'
.. [==[<<#|<<?prefix>>[[Has property::<<title>><<|\|<<alias>>|>>]]<<?suffix>><<,|<<?separator>>>>>><<?tail>> ]==]
.. '>>'
local format = dependencies.formatter (format_string) --require 'Module:FormatterII'.formatter (format_string)
local cases = {
['Plain text'] = 'Plain text 1',
['Plain text, ,-separated'] = 'Plain text 1, plain text 2',
['Plain text, NL-separated'] =
[[Plain 1
Plain 2
]],
['Quoted'] = '[[Title]]',
['Quoted, ,-separated'] = '[[Title1]], [[title2]]',
['Quoted, not separated'] = '[[Title1]] and [[title2]]',
['Quoted, ,-separated, suffices'] = '[[Title1]] (before), [[title2]] (now)',
['Tail'] = '[[Title]] (in [[:1942]]), allegedly',
['Screened'] = '[[Title]] (in [[:1942]])',
['Alias'] = '[[Title|Alias]]',
['Alias and no alias'] = '[[Title1|Alias]], [[Title2]]',
['Aliases, prefixes'] = 'Two titles [[Title1|1]] and [[Title2|2]]'
}
return {
test = function (frame)
local result = {
frame:preprocess ( '<pre><nowiki>' .. format_string .. '</nowiki></pre>' ),
'{| class="wikitable"', '! Case !! Wikitext !! Parsed !! Formatted'
}
for title, wikitext in pairs (cases) do
result [#result + 1] = '|-'
result [#result + 1] = '| ' .. title
result [#result + 1] = '| ' .. wikitext
local parsed = { compiled:match (wikitext) }
result [#result + 1] = '| <code>' .. mw.dumpObject (parsed) .. '</code>'
--result [#result + 1] = '| ' .. frame:preprocess (format (parsed))
result [#result + 1] = '| ' .. frame:preprocess ( '<pre><nowiki>' .. format (wikitext) .. '</nowiki></pre>' ) --frame:preprocess (format (wikitext))
end
result [#result + 1] = '|}'
return table.concat (result, '\n')
end
}