Page 1 of 1

Cards Text Grammar

PostPosted: 09 Sep 2010, 12:48
by silly freak
This is a list of the possibilities of the "text" line in card files:

General Grammar
Code: Select all
Text:
  Effects
  ActivatedAbility
  TriggeredAbility

ActivatedAbility:
  Costs ":" Effects

TriggeredAbility:
  Trigger "," Effects

Costs:
  Cost
  Cost "," Costs

Effects:
  Effect "."
  Effect Effects
"Features"
Code: Select all
Cost:
  ManaSequence
  "{T}"
  "{Q}"
  "Sacrifice ~"

Effect:
  "Add" ManaSequence "to your mana pool"
  "Draw a card" | "Draw" Number "cards"
  "~ deals" Number "damage to all creatures"
  "Destroy all creatures" ". They can't be regenerated"?

Trigger:
  "When ~ enters the battlefield"
In Progress:
Code: Select all
Effect:
  "You gain" Number "life"
Generally, parsing uses regular expressions, so it is case-sensitive. However, the literals support lowercase in addition to the case in the examples; e.g.
Code: Select all
Example  Regex actually used
"You"    "[Yy]ou"
"you"    "you"
When different literals are combined, e.g.
Code: Select all
Trigger "," Effects
additional whitespace is allowed ("\s*")

Re: Cards Text Grammar

PostPosted: 09 Sep 2010, 19:01
by nantuko84
Have you tried ANTLR?
It generates lexer and parser with built-in constructions bases on grammar written in format very similar to BNF (Backus Normal Form).

Re: Cards Text Grammar

PostPosted: 09 Sep 2010, 19:27
by silly freak
I have heard (and read in your blog) of it, but not yet tried it. I played with DSLs in Scala, and will probably use ANTLR at some point.