Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mana_sort := sort_text@(order: "mixed(Coin|LB|Down|Once|White|Red|Blue|Green|Black|Colorless|ZW|ZR|ZU|ZG|ZB|ZC|W|R|U|G|B|C)")
- mana_filter_t := replace@( # Remove [] used for forcing mana symbols
- match: "[\\[\\]]",
- replace: ""
- ) + { mana_sort() }
- mana_context :=
- "(?ix) # case insensitive, ignore whitespace
- (^|[[:space:]\"(“']) # start of a word
- ( <match>: # G: something
- | <match>, # G, tap: something
- | <match>[ ]can[ ]be[ ]pay
- | (pays?|additional|costs?|the|by # pay X. creatures cost 1 less. pay an additional G.
- |adds?|pay(ed)?[ ](with|using)
- )
- ([ ]either)? # pay either X or Y
- ([ ](<sym[^>]*>)?(White|Red|Blue|Green|Black|Colorless)+(</sym[^>]*>)?,)* # pay X, Y or Z
- ([ ](<sym[^>]*>)?(White|Red|Blue|Green|Black|Colorless)+(</sym[^>]*>)?[ ](and|or|and/or))* # pay X or Y
- [ ]<match>
- ([,.)]|$ # (end of word)
- |[ ][^ .,]*$ # still typing...
- |[ ]( or | and | in | less | more | to | for ) # or next word is ...
- )
- )
- | <param-mana><match></param-mana> # keyword argument that is declared as mana
- | <param-cost>[ ]*<match></param-cost> # keyword argument that is declared as cost
- | <param-cost><match>, # keyword argument that is declared as cost
- ";
- text_filter :=
- # step 1 : remove all automatic tags
- remove_tag@(tag: "<sym-auto>") +
- remove_tag@(tag: "<i-auto>") +
- remove_tag@(tag: "<b-auto>") +
- remove_tag@(tag: "<error-spelling") +
- remove_tag@(tag: "<nospellcheck") +
- # step 2 : convert these skills into symbols no matter where they are
- replace@(
- match: "\\[Constant\\]",
- replace: {"<sym-auto>[Constant]</sym-auto>"} ) +
- replace@(
- match: "\\[On-Play\\]",
- replace: {"<sym-auto>[On-Play]</sym-auto>"} ) +
- replace@(
- match: "\\[Action\\]",
- replace: {"<sym-auto>[Action]</sym-auto>"} ) +
- replace@(
- match: "\\[Auto\\]",
- replace: {"<sym-auto>[Auto]</sym-auto>"} ) +
- replace@(
- match: "(>Cross\<)",
- replace: {"<sym-auto>>Cross\<</sym-auto>"} ) +
- replace@(
- match: "with Cross",
- replace: {"with <sym-auto>>Cross\<</sym-auto>"} ) +
- replace@(
- match: "\\[Cross Constant\\]",
- replace: {"<sym-auto>[Cross Constant]</sym-auto>"} ) +
- replace@(
- match: "\\[Cross On-Play\\]",
- replace: {"<sym-auto>[Cross On-Play]</sym-auto>"} ) +
- replace@(
- match: "\\[Cross Action\\]",
- replace: {"<sym-auto>[Cross Action]</sym-auto>"} ) +
- replace@(
- match: "\\[Cross Auto\\]",
- replace: {"<sym-auto>[Cross Auto]</sym-auto>"} ) +
- replace@(
- match: "\\[Attack Phase\\]",
- replace: {"<sym-auto>[Attack Phase]</sym-auto>"} ) +
- replace@(
- match: "\\[Main Phase\\]",
- replace: {"<sym-auto>[Main Phase]</sym-auto>"} ) +
- replace@(
- match: "\\[Spell Cut-In\\]",
- replace: {"<sym-auto>[Spell Cut-In]</sym-auto>"} ) +
- replace@(
- match: "\\(Layer\\)",
- replace: {"<sym-auto>(Layer)</sym-auto>"} ) +
- replace@(
- match: "\\(Play Condition\\)",
- replace: {"<sym-auto>(Play Condition)</sym-auto>"} ) +
- replace@(
- match: "Heaven Heaven",
- replace: {"<sym-auto>Heaven</sym-auto>"} ) +
- replace@(
- match: "Life Burst Life Burst",
- replace: {"LB"} ) +
- # step 3: annoying number replacements
- replace@(
- match: "(1 \<)",
- replace: {"one \<"} ) +
- replace@(
- match: "(2 \<)",
- replace: {"two \<"} ) +
- replace@(
- match: "(3 \<)",
- replace: {"three \<"} ) +
- replace@(
- match: "1 card",
- replace: {"one card"} ) +
- replace@(
- match: "2 cards",
- replace: {"two cards"} ) +
- replace@(
- match: "3 cards",
- replace: {"three cards"} ) +
- replace@(
- match: "1 SIGNI",
- replace: {"one SIGNI"} ) +
- replace@(
- match: "2 SIGNI",
- replace: {"two SIGNI"} ) +
- replace@(
- match: "3 SIGNI",
- replace: {"three SIGNI"} ) +
- replace@(
- match: "1 of",
- replace: {"one of"} ) +
- replace@(
- match: "2 of",
- replace: {"two of"} ) +
- replace@(
- match: "3 of",
- replace: {"three of"} ) +
- # step 5 : add mana & tap symbols
- replace@(
- match: "\\b(Coin|LB|Down|Once|White|Red|Blue|Green|Black|Colorless|ZW|ZR|ZU|ZG|ZB|ZC|W|R|U|G|B|C)+\\b",
- in_context: mana_context,
- replace: {"<sym-auto>" + mana_filter_t() + "</sym-auto>"} ) +
- # step 7 : italicize text in parenthesis
- replace@(
- match: "[(]([^)\n]|[(][^)\n]*[)])*[)]?",
- in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
- replace: "<i-auto>&</i-auto>") +
- replace@(
- match: "[\<]([^>\n]|[\<][^>\n]*[>])*[>]?",
- in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
- replace: "<b-auto>&</b-auto>") +
- # step 8 : automatic capitalization, but not after "("
- replace@(
- match: "([ ]*: |—| — )" # preceded by this
- + "([[:lower:]])" # match this
- + "(?![)])", # not followed by this
- replace: { _1 + to_upper(_2) })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement