Pattern DSL primer
The DSL is a small text language for writing patterns. It's the same model the Builder uses, just spelled out as text. If you can copy a recipe, you can write a pattern in the DSL.
The pattern block
Every pattern starts with a pattern block:
pattern "My First Scarf" {
// Your pattern goes here
}Parameters
Parameters are the knobs the knitter sets when starting a project. They're declared at the top of the pattern.
pattern "Basic Scarf" {
param cast_on: int = 40 // Whole-number stitch count
param length_inches: int = 60 // Target length
param use_fringe: bool = true // True/false toggle
}Types are int (whole numbers), text (strings), or bool (true/false).
Segments
Segments divide a pattern into logical sections — Cuff, Body, Sleeve, Heel turn. Each segment holds an ordered list of rows, repeats, rule blocks, and notes.
segment "Cuff" {
// Instructions for the cuff
}
segment "Body" {
// Instructions for the body
}Rows and notes
A row is one instruction the tracker advances through. A note is informational text — shown to the knitter but not counted as a worked row.
row "Knit all stitches"
note "Place a marker at the start of the round."Mix text with parameters or counters using +:
row "Cast on " + cast_on + " stitches loosely."Repeats
Three forms.
Fixed — when you know the count up front:
repeat 10 {
row "K1, P1 ribbing"
}Until predicate — repeat until a counter or expression evaluates true:
repeat until total_sts == 100 {
row "Increase 1 st at each end"
delta total_sts: 2
}Until text — a milestone the knitter judges by eye:
repeat until "Piece measures 5 inches" {
row "Knit all stitches"
}Use as <name> to name the iteration counter (defaults to r):
repeat 20 as r {
row {
when r is odd: "RS: Knit all"
else: "WS: Purl all"
}
}Counters and deltas
Counters track values that change while knitting. Update them on a row with delta:
counter stitch_count = 64
segment "Decreases" {
repeat 4 {
row "k2tog at start and end"
delta stitch_count: -2
}
}A counter declared with := is derived — it's a formula, not a stored value:
counter instep_sts := cast_on / 2Conditionals (rule blocks)
Inside a row, when and else pick different instructions based on the current state — typically the iteration counter:
row {
when r is odd: "K1, P1 to end"
else: "P1, K1 to end"
}Common predicates: r is odd, r is even, total_sts > 50, or any expression that evaluates to a boolean.
Expressions
Operators available anywhere a value is expected:
- Math:
+-*/% - Comparison:
==!=<<=>>= - Logic:
andornot
Example:
note "You should have " + (cast_on / 2 + 2) + " stitches remaining."A complete example
A small sock cuff that uses parameters, a segment, a repeat, and a rule block:
pattern "Simple Sock Cuff" {
param cast_on: int = 64
param cuff_length: int = 15
segment "Cuff" {
note "Cast on " + cast_on + " sts and join for working in the round."
repeat cuff_length as r {
row {
when r < 5: "K1, P1 ribbing (tight)"
else: "K1, P1 ribbing (standard)"
}
}
note "Cuff complete! Prepare for the leg section."
}
}Where to next?
For the formal grammar — every keyword, every shape, every edge case — see the DSL specification. If you'd rather express patterns with native loops and template literals, try the JavaScript SDK. If text editing isn't your thing, the visual Builder covers the same model.