-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from typst-community/next
Merge `next` into `main`
- Loading branch information
Showing
15 changed files
with
325 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#import "../base-type.typ": base-type | ||
#import "../assertions-util.typ": * | ||
|
||
#let number( | ||
assertions: (), | ||
min: none, | ||
max: none, | ||
..args, | ||
) = { | ||
|
||
assert-positive-type(min, types: (int,), name: "Minimum length") | ||
assert-positive-type(max, types: (int,), name: "Maximum length") | ||
|
||
base-type(name: "number", types: (float, int), ..args) + ( | ||
min: min, | ||
max: max, | ||
assertions: ( | ||
( | ||
precondition: "min", | ||
condition: (self, it) => it >= self.min, | ||
message: (self, it) => "Value must be at least " + str(self.min), | ||
), | ||
( | ||
precondition: "max", | ||
condition: (self, it) => it <= self.max, | ||
message: (self, it) => "Value must be at most " + str(self.max), | ||
), | ||
..assertions, | ||
), | ||
) | ||
} | ||
|
||
#let integer = number.with(name: "integer", types: (int,)) | ||
#let floating-point = number.with(name: "float", types: (float,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#import "../base-type.typ": base-type | ||
#import "../assertions-util.typ": assert-base-type | ||
#import "../ctx.typ": z-ctx | ||
|
||
#let to-args-type(..args) = args | ||
|
||
#let sink( | ||
positional: none, | ||
named: none, | ||
..args, | ||
) = { | ||
|
||
if positional != none { | ||
assert-base-type(positional) | ||
} | ||
if named != none { | ||
assert-base-type(named) | ||
} | ||
|
||
base-type( | ||
name: "argument-sink", | ||
types: (arguments,), | ||
..args, | ||
) + ( | ||
positional-schema: positional, | ||
named-schema: named, | ||
handle-descendents: (self, it, ctx: z-ctx(), scope: ()) => { | ||
|
||
let positional = it.pos() | ||
if self.positional-schema == none { | ||
if positional.len() > 0 { | ||
(self.fail-validation)( | ||
self, | ||
it, | ||
scope: scope, | ||
ctx: ctx, | ||
message: "Unexpected positional arguments.", | ||
) | ||
} | ||
} else { | ||
positional = (self.positional-schema.validate)( | ||
self.positional-schema, | ||
it.pos(), | ||
ctx: ctx, | ||
scope: (..scope, "positional"), | ||
) | ||
} | ||
|
||
let named = it.named() | ||
if self.named-schema == none { | ||
if named.len() > 0 { | ||
(self.fail-validation)( | ||
self, | ||
it, | ||
scope: scope, | ||
ctx: ctx, | ||
message: "Unexpected named arguments.", | ||
) | ||
} | ||
} else { | ||
named = (self.named-schema.validate)( | ||
self.named-schema, | ||
it.named(), | ||
ctx: ctx, | ||
scope: (..scope, "named"), | ||
) | ||
} | ||
|
||
to-args-type(..positional, ..named) | ||
}, | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.