diff --git a/syntax/annotations.typ b/syntax/annotations.typ index 8909c80..8c66031 100644 --- a/syntax/annotations.typ +++ b/syntax/annotations.typ @@ -9,11 +9,11 @@ ``` #let constraint = ``` -{[`constraint` "(" <"_", 'value'> <">", "<", ">=", "<=", "==", "!="> <"_", 'value'> ")"]} +{[`constraint` <"_", 'value'> <">", "<", ">=", "<=", "==", "!="> <"_", 'value'>]} ``` #let type-with-constraints = ``` -{[`type-with-constraints` 'identifier' ]} +{[`type-with-constraints` 'identifier' ]} ``` #let column-def = ``` diff --git a/syntax/midas.typ b/syntax/midas.typ new file mode 100644 index 0000000..17db6d6 --- /dev/null +++ b/syntax/midas.typ @@ -0,0 +1,97 @@ +#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 type-property = ``` +{[`type-property` 'identifier' ":" 'type-with-constraints']} +``` + +#let type-body = ``` +{[`type-body` "{" "}"]} +``` + +#let operation-type = ``` +{[`operation-type` "<" 'type-with-constraints' ">"]} +``` + +#let type-statement = ``` +{[`type-statement` "type" 'identifier' "<" 'type-with-constraints'*"," ">" ]} +``` + +#let operation-statement = ``` +{[`operation-statement` "op" 'operation-type' "operator" 'operation-type' "=" 'operation-type']} +``` + +#let constraint-statement = ``` +{[`constraint-statement` "constraint" 'identifier' "=" 'constraint']} +``` + +#let statement = ``` +{[`statement` <'type-statement', 'operation-statement', 'constraint-statement'>]} +``` + +#let rules = ( + value, + constraint, + type-with-constraints, + type-property, + type-body, + operation-type, + type-statement, + operation-statement, + constraint-statement, + statement, +) + +#set text(font: "Source Sans 3") + += Midas type definition syntax + +#for rule in rules { + render(rule) +} + +/* +#let by-name = ( + value: value, + constraint: constraint, + type-with-constraints: type-with-constraints, + type-property: type-property, + type-body: type-body, + operation-type: operation-type, + type-statement: type-statement, + operation-statement: operation-statement, + constraint-statement: constraint-statement, +) + +#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.replace(regex("`.*?`"), "") +} + +#let combined = raw(substitute(statement.text)) + + +#set page(flipped: true) +#render(combined) +*/ \ No newline at end of file