From 472f3a2e6ec803bf7e1fefaf7d6d99d6798c7528 Mon Sep 17 00:00:00 2001 From: James R Swift Date: Sun, 30 Jun 2024 18:43:14 +0100 Subject: [PATCH 1/3] Separate name from description --- src/base-type.typ | 2 ++ src/types/array.typ | 3 ++- src/types/dictionary.typ | 11 ++++------- src/types/logical.typ | 5 +++-- src/types/number.typ | 4 ++-- src/types/string.typ | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/base-type.typ b/src/base-type.typ index 38b2db7..f7d55e0 100644 --- a/src/base-type.typ +++ b/src/base-type.typ @@ -4,6 +4,7 @@ /// Schema generator. Provides default values for when defining custom types. #let base-type( name: "unknown", + description: none, optional: false, default: none, types: (), @@ -21,6 +22,7 @@ return ( valkyrie-type: true, name: name, + description: if (description != none){ description } else { name }, optional: optional, default: default, types: types, diff --git a/src/types/array.typ b/src/types/array.typ index 832c816..497c3da 100644 --- a/src/types/array.typ +++ b/src/types/array.typ @@ -18,7 +18,8 @@ assert-positive-type(max, types: (int,), name: "Maximum length") base-type( - name: "array[" + (descendents-schema.name) + "]", + name: name, + description: name + "[" + (descendents-schema.description) + "]", default: (), types: (array-type,), ..args.named(), diff --git a/src/types/dictionary.typ b/src/types/dictionary.typ index 4b94150..d3ea6ac 100644 --- a/src/types/dictionary.typ +++ b/src/types/dictionary.typ @@ -10,22 +10,19 @@ /// -> schema #let dictionary( dictionary-schema, + name: "dictionary", default: (:), - optional: false, - assertions: (), pre-transform: (self, it) => it, - post-transform: (self, it) => it, aliases: (:), + ..args, ) = { assert-base-type-dictionary(dictionary-schema) base-type( - name: "dictionary", - optional: optional, + name: name, default: default, types: (dictionary-type,), - assertions: assertions, pre-transform: (self, it) => { it = pre-transform(self, it) for (src, dst) in aliases { @@ -37,7 +34,7 @@ } return it }, - post-transform: post-transform, + ..args.named() ) + ( dictionary-schema: dictionary-schema, handle-descendents: (self, it, ctx: z-ctx(), scope: ()) => { diff --git a/src/types/logical.typ b/src/types/logical.typ index 73e72e6..cda7a75 100644 --- a/src/types/logical.typ +++ b/src/types/logical.typ @@ -17,7 +17,8 @@ assert-base-type-array(args.pos(), scope: ("arguments",)) base-type( - name: "[" + args.pos().map(it => it.name).join(", ", last: " or ") + "]", + name: "either", + description: "[" + args.pos().map(it => it.name).join(", ", last: " or ") + "]", ..args.named(), ) + ( strict: strict, @@ -36,7 +37,7 @@ } let message = ( - "Type failed to match any of possible options: " + self.options.map(it => it.name).join( + "Type failed to match any of possible options: " + self.options.map(it => it.description).join( ", ", last: " or ", ) + ". Got " + type(it) diff --git a/src/types/number.typ b/src/types/number.typ index 33f04eb..cef828a 100644 --- a/src/types/number.typ +++ b/src/types/number.typ @@ -30,5 +30,5 @@ ) } -#let integer = number.with(name: "integer", types: (int,)) -#let floating-point = number.with(name: "float", types: (float,)) \ No newline at end of file +#let integer = number.with(description: "integer", types: (int,)) +#let floating-point = number.with(description: "float", types: (float,)) \ No newline at end of file diff --git a/src/types/string.typ b/src/types/string.typ index a65acfc..1a1fb88 100644 --- a/src/types/string.typ +++ b/src/types/string.typ @@ -39,7 +39,7 @@ } #let email = string.with( - name: "email", + description: "email", assertions: ( matches( regex("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{2,3}){1,2}$"), @@ -49,7 +49,7 @@ ); #let ip = string.with( - name: "ip", + description: "ip", assertions: ( matches( regex("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"), From 67b6bd64982f374a0783dad539b3d7dda56532c2 Mon Sep 17 00:00:00 2001 From: James R Swift Date: Sun, 30 Jun 2024 18:47:50 +0100 Subject: [PATCH 2/3] Remove skipped code --- src/types/string.typ | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/string.typ b/src/types/string.typ index 1a1fb88..d502345 100644 --- a/src/types/string.typ +++ b/src/types/string.typ @@ -7,8 +7,6 @@ /// Valkyrie schema generator for strings /// /// -> schema -#let string = base-type.with(name: "string", types: (str,)) - #let string( assertions: (), min: none, From 6ac3921301aefdea7d3d7a9d1dc33a1f004b5771 Mon Sep 17 00:00:00 2001 From: James R Swift Date: Sun, 30 Jun 2024 18:49:49 +0100 Subject: [PATCH 3/3] Use descriptions for enumerations --- src/schemas/enumerations.typ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schemas/enumerations.typ b/src/schemas/enumerations.typ index abdcbac..a86ded7 100644 --- a/src/schemas/enumerations.typ +++ b/src/schemas/enumerations.typ @@ -1,7 +1,7 @@ #import "../types.typ" as z; #let papersize = z.choice.with( - name: "paper size", + description: "paper size", ( "a0", "a1",