tree-sitter-recipe
v0.3.1
Published
Pharmacological recipe notation
Downloads
772
Maintainers
Readme
tree-sitter-recipe
Tree-sitter grammar for .recipe files — a digital notation for
pharmacological prescriptions in the Dutch/Latin KNMP/FNA tradition.
What it parses
Three section markers (case-insensitive):
| Marker | Meaning | Content |
| ------ | ----------- | ------------------------------------ |
| R/ | recipe | active ingredient(s), form, strength |
| Da/ | da/dispense | quantity to dispense |
| S/ | signa | directions to the patient |
Plus Latin abbreviations, modern frequencies (1 dd, 3 dd), numbers with
Dutch (0,1) or international (0.1) decimals, and a four-tier comment
system.
Example
/**
* Patient: 45yo female, chronic URTI
* Allergies: none known
*/
R/ claritromycin tablet 500mg
Da/ 14 tablets
S/ b.d.d. 1 tablet p.c.
#! empirical coverage for suspected CAP
R/ amoxicilline 500mg
Da/ 21 caps
S/ 3 dd 1 caps
# pharmacist: check interaction table before dispensingInstall
bun install # or: npm install
bun test # or: npm testDevelopment
npx tree-sitter generate # regenerate parser after grammar changes
npx tree-sitter test # run corpus tests
npx tree-sitter parse file.recipe # inspect parse tree
npx tree-sitter highlight file.recipe # visualize syntax highlighting
npx tree-sitter build --wasm # build WASM for playgroundComment system
| Syntax | Purpose | AST role |
| ---------- | ----------------- | -------------------- |
| # … | line comment | extra (no structure) |
| #! … | doc line comment | extra (sibling node) |
| /* … */ | block comment | extra (no structure) |
| /** … */ | doc block comment | extra (sibling node) |
All four live in extras, so they parse anywhere without affecting structure.
Doc variants (#!, /**) are intended for tooling (LSP, formatter, docgen)
to associate them with the next section by source position.
Supported abbreviations
Frequency: d.d., b.d.d., t.d.d., q.i.d., s.d.d. plus modern N dd
Dutch prose frequency: 3 keer per dag, driemaal daags, om de 8 uur
(structured into count/every/period fields)
Timing: a.c., p.c., a.n., m. et v.
Route: i.m., i.v., s.c., subling., o.d., o.s., a.u.e., u.e.
Compounding: ad (fill-to), dtd / d.t.d. (dispense-this-dose)
Dispensing/warning: d.s.p., u.c., z.n., d.c.p., d.s. monit.,
d.c. prohib., d.i.m.m., CITO, PIM
Forms: aq. pur., collut., lin., supp., gtt aur., gtt nas.,
gtt ophth.
Conditional: si nec. sit
Not yet supported
- International abbreviations (
Rx,Rp,sig.,prn,qd,qid,bid,tid,hs,stat) — reserved for#!dialect internationalpragma. iter N xrepeat directive — dropped due to lexical conflict withxappearing in signa phrases (2 x daags).- ISMP error-prone-abbreviation linting — future tooling, not a grammar concern.
- Nested language injection inside doc comments — reserved for a later release.
License
MIT © Kaj Kowalski
