A tree-sitter grammar for the Forge card-script DSL — the text format used to describe Magic: The Gathering cards in the Forge rules engine. Part of the ManaBrew project.
It parses the line-oriented card format: field lines (Name:, ManaCost:, …), ability/trigger/
static/replacement lines (A:, T:, S:, R:), SVar: definitions, keyword (K:) lines,
$-delimited parameter records, comments, and multi-face cards (ALTERNATE, SPECIALIZE,
AlternateMode).
The grammar is authored in grammar.ts (TypeScript DSL). Regenerate and test with the
tree-sitter CLI:
npm install # also builds the native node binding
npm run generate # tree-sitter generate
npm test # runs the corpus tests under test/corpus/
npm run parse <file>Syntax-highlighting queries live in queries/highlights.scm.
npm install tree-sitter-forge-card-script tree-sitterconst Parser = require("tree-sitter");
const ForgeCardScript = require("tree-sitter-forge-card-script");
const parser = new Parser();
parser.setLanguage(ForgeCardScript);
const tree = parser.parse("Name:Grizzly Bears\nPT:2/2\n");[dependencies]
tree-sitter = "0.24"
tree-sitter-forge-card-script = "0.1"let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_forge_card_script::language()).unwrap();
let tree = parser.parse("Name:Grizzly Bears\nPT:2/2\n", None).unwrap();The grammar recognises the common Forge field keys explicitly; an unrecognised Key: line will
produce an error node. The companion forge-card-script
crate is more permissive and degrades unknown fields gracefully, so the two can disagree on
unusual input.
MIT. See LICENSE.