magarena/grammar/mtg.peg

563 lines
9.8 KiB
Plaintext

MagicRule
= SpellEffect EOR
/ KeywordAbility EOR
/ StaticAbility EOR
/ ActivatedAbility EOR
/ TriggeredAbility EOR
;
SpellEffect
= Optional? Action EOS (SPACE Action EOS)*
;
Optional
= "you may have "
/ "you may "
;
KeywordAbility
= Keyword
/ Enchant
;
StaticAbility
= EntersTapped
/ EntersWithCounter
;
ActivatedAbility
= ActivationCosts ": " SpellEffect
;
TriggeredAbility
= Trigger ", " SpellEffect
;
Trigger
= EntersBattlefieldTrigger
/ LeavesBattlefieldTrigger
/ BeginningUpkeepTrigger
/ DiesTrigger
/ DealsDamageTrigger
/ AttacksTrigger
/ CastTrigger
;
Action
= DestroyNoRegenAction
/ DestroyAction
/ ExileAction
/ CounterAction
/ DamageAction
/ DrawAction
/ DiscardAction
/ TapAction
/ PreventAction
/ RegenerateAction
/ PumpAction
/ GainsAction
/ BounceAction
/ AddManaAction
/ ReturnAction
/ SacrificeAction
/ ChangeLifeAction
/ ChangeCounterAction
/ PutTokenAction
/ ControlAction
;
Keyword
= "flash"
/ "flying"
/ "haste"
/ "defender"
/ "vigilance"
/ "reach"
/ "battle cry"
/ "trample"
/ "first strike"
/ "double strike"
/ "infect"
/ "wither"
/ "fear"
/ "shadow"
/ "storm"
/ "swampwalk"
/ "forestwalk"
/ "islandwalk"
/ "mountainwalk"
/ "changeling"
/ "deathtouch"
/ "lifelink"
/ "exalted"
/ "shroud"
/ "persist"
/ "protection from black"
/ "protection from red"
/ "protection from white"
/ "protection from blue"
/ "protection from green"
/ "protection from artifacts"
/ "protection from creatures"
/ "protection from everything"
/ "@ can't block."
/ "hexproof"
/ "soulbond"
/ "undying"
/ "flanking"
/ "intimidate"
/ "living weapon"
/ "totem armor"
/ "bushido" SPACE Number
/ "soulshift" SPACE Number
/ "fading" SPACE Number
/ "devour" SPACE Number
/ "modular" SPACE Number
/ "vanishing" SPACE Number
/ "bloodthirst" SPACE Number
/ "buyback" SPACE ManaCost
/ "kicker" SPACE ManaCost
/ "equip" SPACE ManaCost
/ "cumulative upkeep" SPACE ManaCost
/ "@ is unblockable."
/ "@ attacks each turn if able."
/ "@ is indestructible."
/ "@ can't be countered."
/ "affinity for artifacts"
;
ActivationCosts
= ActivationCost ("," SPACE ActivationCost)*
;
SacrificeAction
= "sacrifice " SelectPermanent
;
ActivationCost
= "{t}"
/ ManaCost
/ Action
/ "pay " Number " life"
;
ColorlessCost
= "{" Number "}"
/ "{x}"
;
MonoSingleCost
= "{b}"
/ "{u}"
/ "{g}"
/ "{r}"
/ "{w}"
;
HybridSingleCost
= "{g/u}"
/ "{g/w}"
/ "{r/g}"
/ "{r/w}"
/ "{u/r}"
/ "{u/b}"
/ "{b/g}"
/ "{w/b}"
;
ManaCost
= ColorlessCost MonoSingleCost*
/ MonoSingleCost+
/ HybridSingleCost+
;
CastTrigger
= "whenever you cast " SelectSpell
;
LeavesBattlefieldTrigger
= "when @ leaves the battlefield"
;
EntersBattlefieldTrigger
= "when @ enters the battlefield"
/ "whenever @ or another ally enters the battlefield under your control"
;
BeginningUpkeepTrigger
= "at the beginning of your upkeep"
;
DiesTrigger
= "when @ dies"
;
DealsDamageTrigger
= "whenever @ deals " "combat "? "damage" " to a player"?
;
AttacksTrigger
= "whenever @ attacks"
;
PutTokenAction
= "put a 1/1 green saproling creature token onto the battlefield"
;
ControlAction
= SelectPlayer " control" "s"? SPACE SelectPermanent
;
ChangeCounterAction
= "remove a " CounterType " counter from " SelectPermanent
/ "remove " Count SPACE CounterType " counters from " SelectPermanent
/ "put a " CounterType " counter on " SelectPermanent
/ "put " Count SPACE CounterType " counters on " SelectPermanent
;
ChangeLifeAction
= SelectPlayer " loses " Number " life and you gain " Number " life"
/ SelectPlayer " loses " Number " life"
/ SelectPlayer " gain" "s"? SPACE Number " life"
;
SelectPlayer
= "target player"
/ "target opponent"
/ "that player"
/ "you"
;
ReturnAction
= "return " SelectCard " from your graveyard to your hand"
/ "return " SelectCard " from your graveyard to the battlefield"
/ "return " SelectCard " to the battlefield under its owner's control"
;
BounceAction
= "return " SelectPermanent SPACE "to its owner's hand"
/ "put " SelectPermanent SPACE "on top of its owner's library"
;
PreventAction
= "prevent the next " Number " damage that would be dealt to target creature or player this turn"
/ "prevent all combat damage that would be dealt this turn"
;
TapAction
= "tap" SPACE SelectPermanent
/ "untap" SPACE SelectPermanent
/ "tap or untap" SPACE SelectPermanent
;
RegenerateAction
= "regenerate @"
;
DamageAction
= "@ deals " Number " damage to " SelectCreature " or player"?
;
EntersTapped
= "@ enters the battlefield tapped."
;
EntersWithCounter
= "@ enters the battlefield with a " CounterType " counter on it."
/ "@ enters the battlefield with " Count SPACE CounterType " counters on it."
;
CounterType
= "+1/+1"
/ "-1/-1"
/ "+1/+0"
/ "charge"
/ "depletion"
/ "spore"
/ "storage"
/ "ki"
;
Count
= "one"
/ "two"
/ "three"
/ "four"
/ "five"
/ "six"
/ "seven"
/ "eight"
/ "nine"
/ "ten"
/ "x"
;
Enchant
= "enchant" SPACE RestrictedPermanent
/ "enchant player"
;
GainsAction
= SelectCreature " has " Keyword " until end of turn"?
/ SelectCreature " gains " Keyword " until end of turn"?
/ SelectCreature " loses " Keyword " until end of turn"?
;
PumpAction
= SelectCreature " get" "s"? SPACE SignedNumber "/" SignedNumber " until end of turn"?
;
AddManaAction
= "add " ManaSource " to your mana pool"
;
ManaSource
= "{1}"
/ "{b} or {r}"
/ "{g} or {w}"
/ "{r} or {g}"
/ "{u} or {b}"
/ "{w} or {u}"
/ "{g}"
/ "{b}"
/ "{u}"
/ "{w}"
/ "{r}"
/ "one mana of any color"
;
DrawAction
= "draw a card"
/ "draw " Count " cards"
;
DiscardAction
= "discard " SelectCard " at random"?
/ "discard " Count SPACE RestrictedCard " at random"
/ SelectPlayer " discards " SelectCard " at random"?
/ SelectPlayer " discards " Count SPACE RestrictedCard " at random"
;
DestroyNoRegenAction
= "destroy " SelectPermanent EOS SPACE NoRegen
;
DestroyAction
= "destroy " SelectPermanent
;
ExileAction
= "exile " SelectPermanent
;
CounterAction
= "counter " SelectSpell
;
SelectOp
= "target"
/ "all"
/ "an"
/ "a"
/ "each"
/ "enchanted"
/ "equipped"
/ "the"
/ "other"
;
SelectCard
= "@"
/ "it"
/ SelectOp SPACE RestrictedCard
;
SelectCreature
= "@"
/ "it"
/ SelectOp SPACE RestrictedCreature
;
SelectPermanent
= "@"
/ "it"
/ SelectOp SPACE RestrictedPermanentCombination
;
SelectSpell
= SelectOp SPACE RestrictedSpell
;
RestrictedPermanentCombination
= RestrictedPermanent ", " RestrictedPermanent ", or " RestrictedPermanent
/ RestrictedPermanent ", " RestrictedPermanent ", and " RestrictedPermanent
/ RestrictedPermanent " or " RestrictedPermanent
/ RestrictedPermanent " and " RestrictedPermanent
/ RestrictedPermanent
;
RestrictedPermanent
= (PermanentRestriction SPACE)? Permanent (SPACE PermanentRestriction)?
/ RestrictedCreature
/ RestrictedLand
/ SelectArtifact
/ SelectEnchantment
/ SelectTribal
;
PermanentRestriction
= "black or red"
/ "black"
/ "red"
/ "noncreature"
/ "you control"
;
SelectArtifact
= Artifact
;
SelectEnchantment
= Enchantment
;
RestrictedLand
= (LandRestriction SPACE)? Land (SPACE LandRestriction)?
;
LandRestriction
= "nonbasic"
/ "you control"
;
SelectTribal
= Tribal
;
RestrictedSpell
= (SpellRestriction SPACE)? Spell (SPACE SpellRestriction)?
;
SpellRestriction
= "creature"
/ "white, blue, black, or red"
/ "red or green"
/ "red"
/ "white"
/ "black"
/ "blue"
/ "green"
/ "multicolored"
/ "noncreature"
/ "enchantment"
/ "spirit or arcane"
/ "treefolk"
/ "vampire creature"
/ "wizard"
/ "during an opponent's turn"
;
RestrictedCard
= (CardRestriction SPACE)? Card
;
CardRestriction
= "creature"
/ "artifact"
/ "instant or sorcery"
/ "instant"
/ "sorcery"
/ "exiled"
;
RestrictedCreature
= (CreatureRestriction SPACE)? Creature (SPACE CreatureRestriction)?
;
CreatureRestriction
= "with converted mana cost 3 or less"
/ "with power 4 or greater"
/ "with power 2 or less"
/ "with flying"
/ "tapped or blocking"
/ "tapped"
/ "untapped"
/ "blocked"
/ "nonblack"
/ "nonartifact, nonblack"
/ "attacking or blocking"
/ "attacking"
/ "green or white"
/ "human"
/ "non-vampire, non-werewolf, non-zombie"
/ "nonartifact"
/ "artifact"
/ "you control"
;
Tribal
= "spirit" "s"?
/ "island" "s"?
/ "wall" "s"?
;
Creature
= "creature" "s"?
;
Artifact
= "artifact" "s"?
/ "equipment" "s"?
;
Land
= "land" "s"?
;
Enchantment
= "enchantment" "s"?
;
Permanent
= "permanent" "s"?
;
Card
= "card" "s"?
;
Spell
= "spell" "s"?
;
NoRegen
= "it can't be regenerated"
/ "they can't be regenerated"
;
SignedNumber
= Sign Number
;
Number
= [0-9]+
/ "that much"
;
Sign
= "+"
/ "-"
;
SPACE
= " "
;
EOS
= "."
;
EOR
= !_
;