-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add element support to repr, move repr to data
- Loading branch information
Showing
12 changed files
with
140 additions
and
60 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
#import "../data.typ": fields, counter_ as counter, ctx, scope, func, eid, tid | ||
#import "../data.typ": fields, counter_ as counter, ctx, scope, func, eid, tid, repr_ as repr |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Public re-exports for type-related functions and constants. | ||
#import "../types/base.typ": ok, err, is-ok, any, never, custom-type, typeid, typename, repr_ as repr | ||
#import "../types/base.typ": ok, err, is-ok, any, never, custom-type, typeid, typename | ||
#import "../types/types.typ": option, smart, union, paint, literal, exact, wrap, array_ as array, default, validate as typeinfo, cast, generate-cast-error | ||
#import "../types/custom.typ": declare | ||
#import "native.typ" |
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,46 @@ | ||
#import "/src/lib.typ" as e: field, types | ||
|
||
#[ | ||
#let bigbox = e.element.declare( | ||
"bigbox", | ||
prefix: "@preview/my-package,v1", | ||
display: it => block(fill: it.fill, stroke: it.stroke, inset: 5pt, it.body), | ||
fields: ( | ||
field("body", types.option(content), doc: "Box contents", required: true), | ||
field("fill", types.option(types.paint), doc: "Box fill"), | ||
field("stroke", types.option(stroke), doc: "Box border", default: red) | ||
) | ||
) | ||
|
||
#bigbox[abc] | ||
|
||
#show: e.set_(bigbox, fill: red) | ||
|
||
#bigbox(stroke: blue + 2pt)[def] | ||
] | ||
|
||
#[ | ||
#let person = e.types.declare( | ||
"person", | ||
prefix: "@preview/my-package,v1", | ||
fields: ( | ||
field("name", str, doc: "Person's name", required: true), | ||
field("age", int, doc: "Person's age", default: 40), | ||
field("preference", types.any, doc: "Anything the person likes", default: none) | ||
), | ||
casts: ( | ||
(from: str, with: person => name => person(name)), | ||
) | ||
) | ||
|
||
#assert.eq( | ||
e.repr(person("John", age: 50, preference: "soup")), | ||
"person(age: 50, name: \"John\", preference: \"soup\")" | ||
) | ||
|
||
// Manually invoke typechecking and cast | ||
#assert.eq( | ||
types.cast("abc", person), | ||
(true, person("abc")) | ||
) | ||
] |
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