BlueGit

timfa posprint

Files

posprint / docs / DSL-SPEC.md

DSL-SPEC.md

DSL-SPEC.md 6.5 KiB Download Raw

Document DSL specification

A lightweight, markdown-inspired syntax for POS receipt templates. The DSL compiles to an AST and then to ESC/POS bytes or a screen preview.

> Implementation: Parser in src/dsl/parser.rs. All constructs below are implemented unless listed under Future extensions.

Design goals: easy to author, line-oriented, explicit about POS-specific features (barcodes, cut, feed), parameter-friendly.

---

Document structure

A document is a sequence of blocks. Blank lines become paper feeds (@feed 1). Blocks are not nested except for ${parameters} inside text.

---

Text blocks

Paragraphs

Plain text (and ${parameters}). One or more consecutive non-empty lines form a paragraph. There is no inline bold/italic/code markup.

Thank you for your purchase!
Visit us again soon.

Headings

# Store Name
## Receipt
  • # → large / double-height text (ESC/POS emphasis)
  • ## → bold emphasis
  • Maximum two levels in v1

Alignment

Prefix a paragraph with alignment markers:

:center:
Your Store Name

:right:
Total: ${Amount}
MarkerEffect
:left:Left (default)
:center:Centered
:right:Right-aligned

Bullet lists

- Milk
- Bread
- Eggs

Each line must start with - (dash + space). Consecutive list lines form one list block. A blank line ends the list.

Wrapped lines use a hanging indent:

* this is a
  long line

Parameters

SyntaxEffect
${Name}Parameter placeholder (see Parameters)

Parameters work inside any text, and inside barcode/QR/image directives (below).

Example:

Receipt #${DocumentNumber}
Date: ${Date}

Item: ${ItemName}     ${LineTotal}

Horizontal rule

---

Renders a dashed or solid separator line across the print width.

---

Directives (block-level)

Directives start with @ at the beginning of a line.

Feed (blank lines)

@feed 3

Advances paper by n lines.

Cut

@cut

Partial cut after content (if printer supports). Often placed at document end.

Image

@image path/to/logo.png
@image ${LogoPath} width=50%
@image assets/qr-promo.png width=384
AttributeDescription
path (positional)File path relative to .pos file or absolute; may be ${Param}
widthNN% of printable width, or absolute dots (e.g. 384)
alignleft (default), center, right

Images are converted to monochrome raster data and scaled to width (never wider than printable_dots).

Date / time

@date
@date DD-MM-YYYY
@time
@time 12h
@time 24h
DirectiveBehaviour
@dateSystem regional short date (%x)
@date PATTERNCustom pattern (YYYY, MM, DD, …)
@time / @time 24h24-hour HH:MM
@time 12h12-hour with AM/PM

Barcode

@barcode CODE128 ${Sku}
@barcode EAN13 ${EanCode} height=80
@barcode RASTER CODE128 ${Sku}
@barcode RASTER CODE93 ABC-1234
FieldValues
ModeOptional RASTER prefix; otherwise native ESC/POS
SymbologyNative: CODE128, EAN13, EAN8, CODE39, UPC-A, UPC-E, ITF, CODABAR. Raster-only: CODE93, CODE11
DataLiteral or ${Param}
heightModule / PNG height in dots (default: 64)
alignleft, center, right
show_textNative only: HRI below barcode

Raster barcodes stretch horizontally to full printable width.

QR code

@qr https://example.com/receipt/${DocumentNumber}
@qr ${PaymentUrl} size=6 ecc=H
@qr RASTER ${PaymentUrl} version=5 scale=4 ecc=M
AttributeNativeRaster
DataURL/text; may include ${Param}Same
sizeModule size 1–16 (default 4)—
scale—Pixels per module (default 4)
version—QR version 1–40 (optional)
eccL, M, Q, H (default M)Same
alignleft, center, rightSame

---

Parameters

Syntax

${ParameterName}
  • Names: [A-Za-z_][A-Za-z0-9_]* (ASCII letters, digits, underscore)
  • Case-sensitive: ${DocNo} and ${docno} are different
  • Uniqueness at input: all occurrences of the same name share one value entered at print time

Where parameters are allowed

LocationExample
TextOrder ${OrderId}
Barcode data@barcode CODE128 ${OrderId}
QR data@qr ${VerifyUrl}
Image path@image ${LogoPath}

Print-time behavior

1. Before print, scan AST for all ${...} tokens. 2. Deduplicate by name. 3. Show dialog with one field per unique name (or require CLI --set). 4. Pre-fill from last print session (in-memory). 5. Substitute into AST, then encode/print.

Missing parameter at print time: block print and highlight unresolved names.

---

Comments

<!-- this is not printed -->

HTML-style comments are stripped before parse.

---

Blank lines

A blank line (or whitespace-only line) inserts Feed(1) — same paper advance as @feed 1. On print this becomes ESC d 1 (reliable after raster graphics).

---

Error reporting

Parse errors include 1-based line and column. Typical causes:

  • Invalid barcode symbology
  • Invalid ${} name
  • Missing required directive argument
  • Unknown @time format

---

ESC/POS mapping (summary)

DSLESC/POS
# headingDouble width/height ON → text → OFF
## headingBold ON → text → OFF
- itemASCII * bullet + hanging wrap
:center:Justification center
@feed n / blank lineESC d n
@cutGS V partial cut
@barcodeGS k or GS v 0 raster
@qrGS ( k or GS v 0 raster
@imageGS v 0 raster bit image
@date / @timePlain text lines

Full command details: PRINTING.md.

---

Future extensions (not implemented)

  • @table for columnar line items
  • Nested lists / numbered lists
  • Bluetooth / network printer transports
  • Syntax highlighting in the editor

---

Example document

# ${StoreName}
:center:

123 Main Street

---
@date
@time
Receipt: ${DocumentNumber}

- Item one
- Item two

:right:
TOTAL: ${GrandTotal}

@barcode CODE128 ${DocumentNumber}
@feed 2
@qr RASTER https://shop.example.com/r/${DocumentNumber} scale=4

Thank you!
@feed 4
@cut
Source
1# Document DSL specification
2
3A lightweight, markdown-inspired syntax for POS receipt templates. The DSL compiles to an AST and then to ESC/POS bytes or a screen preview.
4
5> **Implementation:** Parser in `src/dsl/parser.rs`. All constructs below are implemented unless listed under [Future extensions](#future-extensions-not-implemented).
6
7**Design goals:** easy to author, line-oriented, explicit about POS-specific features (barcodes, cut, feed), parameter-friendly.
8
9---
10
11## Document structure
12
13A document is a sequence of **blocks**. Blank lines become paper feeds (`@feed 1`). Blocks are not nested except for `${parameters}` inside text.
14
15---
16
17## Text blocks
18
19### Paragraphs
20
21Plain text (and `${parameters}`). One or more consecutive non-empty lines form a paragraph. There is **no** inline bold/italic/code markup.
22
23```markdown
24Thank you for your purchase!
25Visit us again soon.
26```
27
28### Headings
29
30```markdown
31# Store Name
32## Receipt
33```
34
35- `#` → large / double-height text (ESC/POS emphasis)
36- `##` → bold emphasis
37- Maximum two levels in v1
38
39### Alignment
40
41Prefix a paragraph with alignment markers:
42
43```markdown
44:center:
45Your Store Name
46
47:right:
48Total: ${Amount}
49```
50
51| Marker | Effect |
52|--------|--------|
53| `:left:` | Left (default) |
54| `:center:` | Centered |
55| `:right:` | Right-aligned |
56
57### Bullet lists
58
59```markdown
60- Milk
61- Bread
62- Eggs
63```
64
65Each line must start with `- ` (dash + space). Consecutive list lines form one list block. A blank line ends the list.
66
67Wrapped lines use a hanging indent:
68
69```text
70* this is a
71 long line
72```
73
74### Parameters
75
76| Syntax | Effect |
77|--------|--------|
78| `${Name}` | Parameter placeholder (see Parameters) |
79
80Parameters work inside any text, and inside barcode/QR/image directives (below).
81
82**Example:**
83
84```markdown
85Receipt #${DocumentNumber}
86Date: ${Date}
87
88Item: ${ItemName} ${LineTotal}
89```
90
91### Horizontal rule
92
93```markdown
94---
95```
96
97Renders a dashed or solid separator line across the print width.
98
99---
100
101## Directives (block-level)
102
103Directives start with `@` at the beginning of a line.
104
105### Feed (blank lines)
106
107```markdown
108@feed 3
109```
110
111Advances paper by *n* lines.
112
113### Cut
114
115```markdown
116@cut
117```
118
119Partial cut after content (if printer supports). Often placed at document end.
120
121### Image
122
123```markdown
124@image path/to/logo.png
125@image ${LogoPath} width=50%
126@image assets/qr-promo.png width=384
127```
128
129| Attribute | Description |
130|-----------|-------------|
131| `path` (positional) | File path relative to `.pos` file or absolute; may be `${Param}` |
132| `width` | `NN%` of printable width, or absolute dots (e.g. `384`) |
133| `align` | `left` (default), `center`, `right` |
134
135Images are converted to monochrome raster data and scaled to width (never wider than `printable_dots`).
136
137### Date / time
138
139```markdown
140@date
141@date DD-MM-YYYY
142@time
143@time 12h
144@time 24h
145```
146
147| Directive | Behaviour |
148|-----------|-----------|
149| `@date` | System regional short date (`%x`) |
150| `@date PATTERN` | Custom pattern (`YYYY`, `MM`, `DD`, …) |
151| `@time` / `@time 24h` | 24-hour `HH:MM` |
152| `@time 12h` | 12-hour with AM/PM |
153
154### Barcode
155
156```markdown
157@barcode CODE128 ${Sku}
158@barcode EAN13 ${EanCode} height=80
159@barcode RASTER CODE128 ${Sku}
160@barcode RASTER CODE93 ABC-1234
161```
162
163| Field | Values |
164|-------|--------|
165| Mode | Optional `RASTER` prefix; otherwise native ESC/POS |
166| Symbology | Native: `CODE128`, `EAN13`, `EAN8`, `CODE39`, `UPC-A`, `UPC-E`, `ITF`, `CODABAR`. Raster-only: `CODE93`, `CODE11` |
167| Data | Literal or `${Param}` |
168| `height` | Module / PNG height in dots (default: 64) |
169| `align` | `left`, `center`, `right` |
170| `show_text` | Native only: HRI below barcode |
171
172Raster barcodes stretch horizontally to full printable width.
173
174### QR code
175
176```markdown
177@qr https://example.com/receipt/${DocumentNumber}
178@qr ${PaymentUrl} size=6 ecc=H
179@qr RASTER ${PaymentUrl} version=5 scale=4 ecc=M
180```
181
182| Attribute | Native | Raster |
183|-----------|--------|--------|
184| Data | URL/text; may include `${Param}` | Same |
185| `size` | Module size 1–16 (default 4) | — |
186| `scale` | — | Pixels per module (default 4) |
187| `version` | — | QR version 1–40 (optional) |
188| `ecc` | `L`, `M`, `Q`, `H` (default `M`) | Same |
189| `align` | `left`, `center`, `right` | Same |
190
191---
192
193## Parameters
194
195### Syntax
196
197```
198${ParameterName}
199```
200
201- **Names:** `[A-Za-z_][A-Za-z0-9_]*` (ASCII letters, digits, underscore)
202- **Case-sensitive:** `${DocNo}` and `${docno}` are different
203- **Uniqueness at input:** all occurrences of the same name share one value entered at print time
204
205### Where parameters are allowed
206
207| Location | Example |
208|----------|---------|
209| Text | `Order ${OrderId}` |
210| Barcode data | `@barcode CODE128 ${OrderId}` |
211| QR data | `@qr ${VerifyUrl}` |
212| Image path | `@image ${LogoPath}` |
213
214### Print-time behavior
215
2161. Before print, scan AST for all `${...}` tokens.
2172. Deduplicate by name.
2183. Show dialog with one field per unique name (or require CLI `--set`).
2194. Pre-fill from last print session (in-memory).
2205. Substitute into AST, then encode/print.
221
222Missing parameter at print time: block print and highlight unresolved names.
223
224---
225
226## Comments
227
228```markdown
229<!-- this is not printed -->
230```
231
232HTML-style comments are stripped before parse.
233
234---
235
236## Blank lines
237
238A blank line (or whitespace-only line) inserts `Feed(1)` — same paper advance as `@feed 1`. On print this becomes `ESC d 1` (reliable after raster graphics).
239
240---
241
242## Error reporting
243
244Parse errors include 1-based line and column. Typical causes:
245
246- Invalid barcode symbology
247- Invalid `${}` name
248- Missing required directive argument
249- Unknown `@time` format
250
251---
252
253## ESC/POS mapping (summary)
254
255| DSL | ESC/POS |
256|-----|---------|
257| `# heading` | Double width/height ON → text → OFF |
258| `## heading` | Bold ON → text → OFF |
259| `- item` | ASCII `* ` bullet + hanging wrap |
260| `:center:` | Justification center |
261| `@feed n` / blank line | ESC d n |
262| `@cut` | GS V partial cut |
263| `@barcode` | GS k or GS v 0 raster |
264| `@qr` | GS ( k or GS v 0 raster |
265| `@image` | GS v 0 raster bit image |
266| `@date` / `@time` | Plain text lines |
267
268Full command details: [PRINTING.md](PRINTING.md).
269
270---
271
272## Future extensions (not implemented)
273
274- `@table` for columnar line items
275- Nested lists / numbered lists
276- Bluetooth / network printer transports
277- Syntax highlighting in the editor
278
279---
280
281## Example document
282
283```markdown
284# ${StoreName}
285:center:
286
287123 Main Street
288
289---
290@date
291@time
292Receipt: ${DocumentNumber}
293
294- Item one
295- Item two
296
297:right:
298TOTAL: ${GrandTotal}
299
300@barcode CODE128 ${DocumentNumber}
301@feed 2
302@qr RASTER https://shop.example.com/r/${DocumentNumber} scale=4
303
304Thank you!
305@feed 4
306@cut
307```