From 903179832e08013421e1e1ef76d4b980d4eba81e Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 18 May 2026 10:02:10 +0200 Subject: [PATCH] feat: add annotations railroad diagrams --- syntax/annotations.typ | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 syntax/annotations.typ diff --git a/syntax/annotations.typ b/syntax/annotations.typ new file mode 100644 index 0000000..8909c80 --- /dev/null +++ b/syntax/annotations.typ @@ -0,0 +1,74 @@ +#import "@preview/fervojo:0.1.1": render + +#let value = ``` +{[`value` < + [`number` 'digit' * ! ], + [`boolean` <"False", "True">], + [`none` "None"] +>]} +``` + +#let constraint = ``` +{[`constraint` "(" <"_", 'value'> <">", "<", ">=", "<=", "==", "!="> <"_", 'value'> ")"]} +``` + +#let type-with-constraints = ``` +{[`type-with-constraints` 'identifier' ]} +``` + +#let column-def = ``` +{[`column-def` <"_", 'type-with-constraints'>]} +``` + +#let frame-def = ``` +{[`frame-def` 'column-def' * ","]} +``` + +#let annotation = ``` +{[`annotation` 'identifier' ]} +``` + +#let rules = ( + value, + constraint, + type-with-constraints, + column-def, + frame-def, + annotation, +) + +#set text(font: "Source Sans 3") + += Type annotation syntax + +#for rule in rules { + render(rule) +} + +/* +#let by-name = ( + annotation: annotation, + frame-def: frame-def, + column-def: column-def, + type-with-constraints: type-with-constraints, + constraint: constraint, + value: value, +) + +#let substitute(base-rule) = { + let new-rule = base-rule + for (key, rule) in by-name.pairs() { + new-rule = new-rule.replace("'" + key + "'", rule.text.slice(1, -1)) + } + if new-rule != base-rule { + new-rule = substitute(new-rule) + } + return new-rule +} + +#let combined = raw(substitute(annotation.text)) + + +#set page(flipped: true) +#render(combined) +*/ \ No newline at end of file