Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REG 4.75 KB | None | 0 0
  1. 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)")
  2.  
  3. mana_filter_t := replace@(               # Remove [] used for forcing mana symbols
  4.             match: "[\\[\\]]",
  5.             replace: ""
  6.         ) + { mana_sort() }
  7.    
  8. mana_context :=
  9.     "(?ix)              # case insensitive, ignore whitespace
  10.      (^|[[:space:]\"(“'])     # start of a word
  11.      (  <match>:            # G: something
  12.      |  <match>,            # G, tap: something
  13.      |  <match>[ ]can[ ]be[ ]pay
  14.      |  (pays?|additional|costs?|the|by # pay X. creatures cost 1 less. pay an additional G.
  15.         |adds?|pay(ed)?[ ](with|using)
  16.         )
  17.         ([ ]either)?             # pay either X or Y
  18.         ([ ](<sym[^>]*>)?(White|Red|Blue|Green|Black|Colorless)+(</sym[^>]*>)?,)* # pay X, Y or Z
  19.         ([ ](<sym[^>]*>)?(White|Red|Blue|Green|Black|Colorless)+(</sym[^>]*>)?[ ](and|or|and/or))* # pay X or Y
  20.         [ ]<match>
  21.         ([,.)]|$                # (end of word)
  22.         |[ ][^ .,]*$            # still typing...
  23.         |[ ]( or | and | in | less | more | to | for ) # or next word is ...
  24.         )
  25.         )
  26.      |  <param-mana><match></param-mana>        # keyword argument that is declared as mana
  27.      |  <param-cost>[ ]*<match></param-cost>    # keyword argument that is declared as cost
  28.      |  <param-cost><match>,            # keyword argument that is declared as cost
  29.      ";
  30.  
  31. text_filter :=
  32.                                                         # step 1 : remove all automatic tags
  33.     remove_tag@(tag: "<sym-auto>") +
  34.     remove_tag@(tag: "<i-auto>")   +
  35.     remove_tag@(tag: "<b-auto>")   +
  36.     remove_tag@(tag: "<error-spelling") +
  37.     remove_tag@(tag: "<nospellcheck") +
  38.                                                         # step 2 : convert these skills into symbols no matter where they are
  39.     replace@(
  40.         match: "\\[Constant\\]",
  41.         replace: {"<sym-auto>[Constant]</sym-auto>"} ) +
  42.     replace@(
  43.         match: "\\[On-Play\\]",
  44.         replace: {"<sym-auto>[On-Play]</sym-auto>"} ) +
  45.     replace@(
  46.         match: "\\[Action\\]",
  47.         replace: {"<sym-auto>[Action]</sym-auto>"} ) +
  48.     replace@(
  49.         match: "\\[Auto\\]",
  50.         replace: {"<sym-auto>[Auto]</sym-auto>"} ) +
  51.     replace@(
  52.         match: "(>Cross\<)",
  53.         replace: {"<sym-auto>>Cross\<</sym-auto>"} ) +
  54.     replace@(
  55.         match: "with Cross",
  56.         replace: {"with <sym-auto>>Cross\<</sym-auto>"} ) +
  57.     replace@(
  58.         match: "\\[Cross Constant\\]",
  59.         replace: {"<sym-auto>[Cross Constant]</sym-auto>"} ) +
  60.     replace@(
  61.         match: "\\[Cross On-Play\\]",
  62.         replace: {"<sym-auto>[Cross On-Play]</sym-auto>"} ) +
  63.     replace@(
  64.         match: "\\[Cross Action\\]",
  65.         replace: {"<sym-auto>[Cross Action]</sym-auto>"} ) +
  66.     replace@(
  67.         match: "\\[Cross Auto\\]",
  68.         replace: {"<sym-auto>[Cross Auto]</sym-auto>"} ) +
  69.     replace@(
  70.         match: "\\[Attack Phase\\]",
  71.         replace: {"<sym-auto>[Attack Phase]</sym-auto>"} ) +
  72.     replace@(
  73.         match: "\\[Main Phase\\]",
  74.         replace: {"<sym-auto>[Main Phase]</sym-auto>"} ) +
  75.     replace@(
  76.         match: "\\[Spell Cut-In\\]",
  77.         replace: {"<sym-auto>[Spell Cut-In]</sym-auto>"} ) +
  78.     replace@(
  79.         match: "\\(Layer\\)",
  80.         replace: {"<sym-auto>(Layer)</sym-auto>"} ) +
  81.     replace@(
  82.         match: "\\(Play Condition\\)",
  83.         replace: {"<sym-auto>(Play Condition)</sym-auto>"} ) +
  84.     replace@(
  85.         match: "Heaven Heaven",
  86.         replace: {"<sym-auto>Heaven</sym-auto>"} ) +
  87.     replace@(
  88.         match: "Life Burst Life Burst",
  89.         replace: {"LB"} ) +
  90.                                                         # step 3: annoying number replacements
  91.     replace@(
  92.         match: "(1 \<)",
  93.         replace: {"one \<"} ) +
  94.     replace@(
  95.         match: "(2 \<)",
  96.         replace: {"two \<"} ) +
  97.     replace@(
  98.         match: "(3 \<)",
  99.         replace: {"three \<"} ) +
  100.     replace@(
  101.         match: "1 card",
  102.         replace: {"one card"} ) +
  103.     replace@(
  104.         match: "2 cards",
  105.         replace: {"two cards"} ) +
  106.     replace@(
  107.         match: "3 cards",
  108.         replace: {"three cards"} ) +
  109.     replace@(
  110.         match: "1 SIGNI",
  111.         replace: {"one SIGNI"} ) +
  112.     replace@(
  113.         match: "2 SIGNI",
  114.         replace: {"two SIGNI"} ) +
  115.     replace@(
  116.         match: "3 SIGNI",
  117.         replace: {"three SIGNI"} ) +
  118.     replace@(
  119.         match: "1 of",
  120.         replace: {"one of"} ) +
  121.     replace@(
  122.         match: "2 of",
  123.         replace: {"two of"} ) +
  124.     replace@(
  125.         match: "3 of",
  126.         replace: {"three of"} ) +
  127.     # step 5 : add mana & tap symbols
  128.     replace@(
  129.         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",
  130.         in_context: mana_context,
  131.         replace: {"<sym-auto>" + mana_filter_t() + "</sym-auto>"} ) +
  132.     # step 7 : italicize text in parenthesis
  133.     replace@(
  134.         match: "[(]([^)\n]|[(][^)\n]*[)])*[)]?",
  135.         in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
  136.         replace: "<i-auto>&</i-auto>") +
  137.     replace@(
  138.         match: "[\<]([^>\n]|[\<][^>\n]*[>])*[>]?",
  139.         in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
  140.         replace: "<b-auto>&</b-auto>") +
  141.     # step 8 : automatic capitalization, but not after "("
  142.     replace@(
  143.         match: "([ ]*: |—| — )" # preceded by this
  144.              + "([[:lower:]])" # match this
  145.              + "(?![)])",      # not followed by this
  146.         replace: { _1 + to_upper(_2) })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement