grammar/spells.treetop

Summary

Maintainability
Test Coverage
grammar Spells
  include Spells::Punctuation
  include Spells::Symbols

  rule card_text
    ability ( new_line ability )* <ParseNode>
  end

  rule ability
    keyword ( space ( cost space )? opening_parentheses ( triggered_ability / activated_ability ) closing_parentheses )? /
    ( ability_word space dash space )? ( triggered_ability / activated_ability ) /
    triggered_ability / activated_ability
  end

  rule triggered_ability
    trigger_word space trigger_event comma space effect <TriggeredAbility>
  end

  rule trigger_word
    'Whenever' / 'When' / 'At'
  end

  rule trigger_event
    word ( space word )*
  end

  rule activated_ability
    cost colon space effect <ActivatedAbility>
  end

  rule keyword
    'Absorb'            /
    'Affinity'          /
    'Amplify'           /
    'Annihilator'       /
    'Aura swap'         /
    'Banding'           /
    'Battle cry'        /
    'Bestow'            /
    'Bloodthirst'       /
    'Bushido'           /
    'Buyback'           /
    'Cascade'           /
    'Champion'          /
    'Changeling'        /
    'Cipher'            /
    'Conspire'          /
    'Convoke'           /
    'Cumulative upkeep' /
    'Cycling'           /
    'Deathtouch'        /
    'Defender'          /
    'Delve'             /
    'Devour'            /
    'Double strike'     /
    'Dredge'            /
    'Echo'              /
    'Enchant'           /
    'Entwine'           /
    'Epic'              /
    'Equip'             /
    'Evergreen'         /
    'Evoke'             /
    'Evolve'            /
    'Exalted'           /
    'Extort'            /
    'Fading'            /
    'Fear'              /
    'First strike'      /
    'Flanking'          /
    'Flash'             /
    'Flashback'         /
    'Flying'            /
    'Forecast'          /
    'Fortify'           /
    'Frenzy'            /
    'Fuse'              /
    'Graft'             /
    'Gravestorm'        /
    'Haste'             /
    'Haunt'             /
    'Hexproof'          /
    'Hideaway'          /
    'Horsemanship'      /
    'Indestructible'    /
    'Infect'            /
    'Intimidate'        /
    'Kicker'            /
    'Landwalk'          /
    'Level up'          /
    'Lifelink'          /
    'Living weapon'     /
    'Madness'           /
    'Miracle'           /
    'Modular'           /
    'Morph'             /
    'Ninjutsu'          /
    'Offering'          /
    'Overload'          /
    'Persist'           /
    'Phasing'           /
    'Poisonous'         /
    'Protection'        /
    'Provoke'           /
    'Prowl'             /
    'Rampage'           /
    'Reach'             /
    'Rebound'           /
    'Recover'           /
    'Reinforce'         /
    'Replicate'         /
    'Retrace'           /
    'Ripple'            /
    'Scavenge'          /
    'Shadow'            /
    'Shroud'            /
    'Soulbond'          /
    'Soulshift'         /
    'Splice'            /
    'Split second'      /
    'Storm'             /
    'Sunburst'          /
    'Suspend'           /
    'Totem armor'       /
    'Trample'           /
    'Transfigure'       /
    'Transmute'         /
    'Tribute'           /
    'Undying'           /
    'Unearth'           /
    'Unleash'           /
    'Vanishing'         /
    'Vigilance'         /
    'Wither'
  end

  rule ability_word
    'Battalion'      /
    'Bloodrush'      /
    'Channel'        /
    'Chroma'         /
    'Domain'         /
    'Fateful hour'   /
    'Grandeur'       /
    'Hellbent'       /
    'Heroic'         /
    'Imprint'        /
    'Inspired'       /
    'Join forces'    /
    'Kinship'        /
    'Landfall'       /
    'Metalcraft'     /
    'Morbid'         /
    'Radiance'       /
    'Sweep'          /
    'Tempting offer' /
    'Threshold'
  end

  rule cost
    cost_part ( comma space cost_part )*
  end

  rule cost_part
    mana_cost / tap_symbol / text_cost
  end

  rule mana_cost
    mana_symbol+
  end

  rule tap_cost
    tap_symbol
  end

  rule text_cost
    word ( space word )*
  end

  rule effect
    word ( ( space / ( comma space ) / ( dot space ) ) word )* dot
  end

  rule word
    [A-Za-z1-9\-\'\+\/]+
  end
end