| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #nop vim: set filetype=tt:;
- /*
- 本文件属于 PaoTin++ 的一部分。
- PaoTin++ © 2020~2026 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
- 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
- */
- #nop 本文件是 xtintin 的一部分,实现了一些正则表达式生成函数;
- ///=== {
- ///// 正则表达式生成函数:
- /////
- // #@ re.TableHeader <表格名称>
- // 生成一个正则表达式,用来匹配一个表格的表头。
- //
- // #@ re.TableTail
- // 生成一个正则表达式,用来匹配一个表格的结尾。
- //
- // #@ util.CurrentClass
- // 获取当前 class 的名称。
- // };
- #func {re.TableHeader} {
- #local title {%1};
- #local class {@util.CurrentClass{}};
- #return {^╭─{?:(?:─|┬)+}$title{?:(?:─|┬)+}─╮{|$class}$};
- };
- #func {re.TableTail} {
- #local class {@util.CurrentClass{}};
- #local end {@default{%0;$class}};
- #return {^╰─{?:(?:─|┴)+}%u{?:(?:─|┴)+}─╯{|$end}$};
- };
- #func {util.CurrentClass} {
- #line quiet #info classes save;
- #return {$info[CLASSES][1][arg1]};
- };
- VAR {服务器渲染的表格数据} gServerTable {};
- ///=== {
- // ## re.ParseServerTable [<回调代码>]
- // 通用的解析服务器表格的工具。
- // 如果提供了回调代码,那么当表格解析完成后,会调用它。
- // 本工具有两个变体,分别是 re.ParseServerTable/gag 和 re.ParseServerTable/nogag
- // 如果不使用变体后缀修饰,那么默认为 nogag 模式。
- // };
- #alias {re.ParseServerTable} {re.ParseServerTable.do {nogag} {%21}};
- #alias {re.ParseServerTable/gag} {re.ParseServerTable.do {gag} {%21}};
- #alias {re.ParseServerTable/nogag} {re.ParseServerTable.do {nogag} {%21}};
- #alias {re.ParseServerTable.do} {
- #local gag {%1};
- #local callback {%2};
- #var gServerTable {};
- #var gServerTable.helper[gag] {$gag};
- #var gServerTable.helper[callback] {$callback};
- #line oneshot #action {~{*UTF8}{?:^}%!c╭─{?:(?:─|┬)+}%c{\p{Han}+}%c{?:(?:─|┬)+}─╮%c{|re/ParseServerTable}$} {
- #var gServerTable[name] {%%2};
- #var gServerTable[nameColor] {@color.Trim{@str.Color{%%1}}};
- #if { "$gServerTable.helper[gag]" == "gag" } {
- #line gag;
- };
- re.ParseServerTable.body;
- };
- };
- #alias {re.ParseServerTable.body} {
- #class re.ParseServerTable open;
- #if { "$gServerTable.helper[gag]" == "gag" } {
- #gag {^%*{|re/ParseServerTable/body}$};
- };
- #local color {(?:\e\[[0-9;:]*m)*};
- #local color2 {(?:\e\[[0-9;:]*m|\s+)*};
- #line oneshot #action {~^{?:$color}│{($color\S+$color2│)+}%c{|re/ParseServerTable/header}$} {
- #local header {%%1};
- #list header explode {│};
- #var gServerTable[header] {$header};
- #local idx {};
- #foreach {*gServerTable[header][]} {idx} {
- #local header {$gServerTable[header][$idx]};
- #replace header {%*%C$} {&1};
- #replace header {^{(\e\[(|0|2;37;0)m)+}} {};
- #var gServerTable[header][$idx] {
- {color} {@color.Trim{@str.Color{$header}}}
- {text} {@str.Plain{$header}}
- };
- };
- } {4.9};
- #action {~^{?:$color}│%*%s%c│%c{|re/ParseServerTable/body}$} {
- #if { "%%1" != "%*│%*" } {
- #local note {%%1};
- #cat gServerTable[note] {$note};
- #return;
- };
- #local line {%%1};
- #list line explode {│};
- #local idx {};
- #local body {};
- #local colorBody {};
- #foreach {*line[]} {idx} {
- #local b {$line[$idx]};
- #replace b {%*%C$} {&1};
- #replace b {^{(\e\[(|0|2;37;0)m)+}} {};
- #local field {$gServerTable[header][$idx][text]};
- #local body[$field] {@str.Plain{$b}};
- #local colorBody[$field] {$b};
- };
- #local body[group] {$gServerTable.helper[group]};
- #local colorBody[group] {$gServerTable.helper[colorGroup]};
- #list gServerTable[body] add {{$body}};
- #list gServerTable[colorBody] add {{$colorBody}};
- } {4.95};
- #action {~{*UTF8}{?:^}%!c├─{?:(?:─|┼)*}%c{\p{Han}+}%c{?:(?:─|┼)+}──┤%c{|re/ParseServerTable/group}$} {
- #var gServerTable.helper[colorGroup] {%%1%%2};
- #var gServerTable.helper[group] {%%2};
- };
- #action {^├──{(─|┴)+}──┤$} {
- #var gServerTable[note] {};
- };
- #action {{*UTF8}{?:^}╰─{?:(?:─|┴)+}{\p{Han}+}{?:(?:─|┴)+}─╯{|re/ParseServerTable/body}$} {
- #class re.ParseServerTable kill;
- #if { "$gServerTable.helper[gag]" == "gag" } {
- #line gag;
- };
- #if { "$gServerTable.helper[callback]" !== "" } {
- #line sub {escapes;var;func} #delay 0 {
- $gServerTable.helper[callback];
- };
- };
- };
- #class re.ParseServerTable close;
- };
|