forge-card-script 0.1.0

Parser and intermediate representation for the Forge card-script DSL used by Magic: The Gathering rules engines
Documentation
  • Coverage
  • 0%
    0 out of 251 items documented0 out of 57 items with examples
  • Size
  • Source code size: 62.26 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.62 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • witchesofthehill/manabrew
    7 4 45
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • khaliostr

forge-card-script

A parser and intermediate representation for the Forge card-script DSL — the line-oriented text format used to describe Magic: The Gathering cards in the Forge rules engine (A:, T:, S:, R:, SVar:, K: lines, $-delimited parameter records, faces, and so on).

It is the shared front-end used by the ManaBrew engine and by forge-card-script-lsp.

What it does

  • Line classification — splits a card script into typed lines (Field, Ability, Trigger, StaticAbility, Replacement, SVar, Keyword, faces, …) with byte spans preserved for every key and value.
  • Parameter records — parses Key$ Value | Key$ Value records, including SVar values that nest abilities, parameter records, or numeric expressions (Count$, Remembered$, …).
  • Diagnostics — reports recoverable problems (missing :/$, empty keys, missing ability record, duplicate parameters) with spans, without ever failing to parse.
  • Semantic value typingParamEntry::semantic() classifies a raw value into a SemanticParamValue (amount, selector, zone list, cost, comparison, produced mana, …).
use forge_card_script::{ParsedCardScript, ScriptLineKind};

let script = "Name:Lightning Bolt\n\
              ManaCost:R\n\
              Types:Instant\n\
              A:SP$ DealDamage | ValidTgts$ Any | NumDmg$ 3\n";

let parsed = ParsedCardScript::parse(script);
assert!(parsed.diagnostics().is_empty());

for ability in parsed.abilities() {
    for param in ability.params.semantic_entries() {
        println!("{} => {:?}", param.key, param.value);
    }
}

A note on semantic typing

SemanticParamValue classification is heuristic — it is driven by parameter-key name patterns, not by an authoritative schema of the DSL. It is intended to power editor affordances (hover, highlighting) and convenience accessors, not to be a complete or normative interpretation of every Forge parameter. Treat Raw as the always-correct fallback.

License

GPL-3.0-or-later. See the repository for details.