tree-sitter-forge-card-script 0.1.1

Tree-sitter grammar for the Forge card-script DSL used by Magic: The Gathering rules engines
Documentation

tree-sitter-forge-card-script

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).

Development

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.

Node binding

npm install tree-sitter-forge-card-script tree-sitter
const 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");

Rust binding

[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();

Coverage note

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.

License

MIT. See LICENSE.