Skip to content

Commit

Permalink
extend Inline and Block, and add String
Browse files Browse the repository at this point in the history
  • Loading branch information
gfngfn committed Sep 12, 2024
1 parent 94b7ac5 commit 2bd3a5d
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 44 deletions.
2 changes: 2 additions & 0 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/basic.satyg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Basic = struct

type paren = length -> length -> context -> inline-boxes * (length -> length)

type paddings = length * length * length * length

signature Ord = sig
type t :: o
val compare : t -> t -> ordering
Expand Down
24 changes: 16 additions & 8 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/block.satyh
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
use List
use Inline

module Block :> sig
val nil : block-boxes
val concat : list block-boxes -> block-boxes
val skip : length -> block-boxes
val clear-page : block-boxes
val form-paragraph : context -> inline-boxes -> block-boxes
val +skip : block [length]
val \skip : inline [length]
val +clear-page : block []
val +ragged-right : block [inline-text]
val +centering : block [inline-text]
val \skip : inline [length]
end = struct

val nil =
block-nil
val nil = block-nil %PRIMITIVE

val concat bbs =
List.fold ( +++ ) nil bbs

val skip = block-skip %PRIMITIVE

val clear-page = clear-page %PRIMITIVE

val form-paragraph =
line-break true true

val block ctx +skip len =
block-skip len

val inline ctx \skip len =
inline-fil ++ embed-block-breakable ctx (block-skip len) ++ omit-skip-after

val block ctx +clear-page =
clear-page

val block ctx +ragged-right it =
form-paragraph ctx (inline-fil ++ read-inline ctx it)
form-paragraph ctx (Inline.fil ++ read-inline ctx it)

val block ctx +centering it =
form-paragraph ctx (inline-fil ++ read-inline ctx it ++ inline-fil)
form-paragraph ctx (Inline.fil ++ read-inline ctx it ++ Inline.fil)

val inline ctx \skip len =
Inline.fil
++ Inline.embed-block-breakable ctx (skip len)
++ Inline.omit-skip-after

end
9 changes: 3 additions & 6 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/graphics.satyh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ module Graphics :> sig
val dashed-arrow : length -> length * length * length -> color -> length -> length -> length -> point -> point -> graphics
end = struct

val overlay =
unite-graphics
val overlay = unite-graphics %PRIMITIVE

val shift =
shift-graphics
val shift = shift-graphics %PRIMITIVE

val linear-transform =
linear-transform-graphics
val linear-transform = linear-transform-graphics %PRIMITIVE

val rotate centpt angle gr =
let (centx, centy) = centpt in
Expand Down
79 changes: 61 additions & 18 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/inline.satyh
Original file line number Diff line number Diff line change
@@ -1,50 +1,93 @@
use open Basic
use List
use Deco

module Inline :> sig
val get-natural-advance : inline-boxes -> length
val nil : inline-boxes
val concat : list inline-boxes -> inline-boxes
val fil : inline-boxes
val get-natural-metrics : inline-boxes -> length * length * length
val get-natural-advance : inline-boxes -> length
val skip : length -> inline-boxes
val kern : length -> inline-boxes
val \skip : inline [length]
val glue : length -> length -> length -> inline-boxes
val frame-inner : paddings -> deco -> inline-boxes -> inline-boxes
val frame-outer : paddings -> deco -> inline-boxes -> inline-boxes
val frame-fixed : length -> paddings -> deco -> inline-boxes -> inline-boxes
val frame-breakable : paddings -> deco-set -> inline-boxes -> inline-boxes
val embed-block-breakable : context -> block-boxes -> inline-boxes
val graphics-fixed : length -> length -> length -> (point -> graphics) -> inline-boxes
val graphics-outer : length -> length -> (length -> point -> graphics) -> inline-boxes
val no-break : inline-boxes -> inline-boxes
val mandatory-break : context -> inline-boxes
val omit-skip-after : inline-boxes
val \skip : inline [length]
val \no-break : inline [inline-text]
val \fil : inline []
val \fil-both : inline []
val mandatory-break : context -> inline-boxes
val \mandatory-break : inline []
end = struct

val nil = inline-nil %PRIMITIVE

val concat ibs =
List.fold ( ++ ) nil ibs

val fil = inline-fil %PRIMITIVE

val get-natural-metrics = get-natural-metrics %PRIMITIVE

val get-natural-advance ib =
let (wid, _, _) = get-natural-metrics ib in
wid

val nil =
inline-nil
val skip = inline-skip %PRIMITIVE

val concat ibs =
List.fold ( ++ ) nil ibs
val kern len =
skip (0pt -' len)

val kern len = inline-skip (0pt -' len)
val glue = inline-glue %PRIMITIVE

val inline ctx \skip len =
inline-skip len
val discretionary = discretionary %PRIMITIVE

val mandatory-break ctx =
discretionary 0 (skip (get-text-width ctx *' 2.)) fil nil

val frame-inner = inline-frame-inner %PRIMITIVE

val frame-outer = inline-frame-outer %PRIMITIVE

val frame-fixed = inline-frame-fixed %PRIMITIVE

val frame-breakable = inline-frame-breakable %PRIMITIVE

val embed-block-breakable = embed-block-breakable %PRIMITIVE

val graphics-fixed = inline-graphics %PRIMITIVE

val graphics-outer = inline-graphics-outer %PRIMITIVE

val no-break ib =
inline-frame-outer (0pt, 0pt, 0pt, 0pt) (fun _ _ _ _ -> unite-graphics []) ib
inline-frame-outer (0pt, 0pt, 0pt, 0pt) Deco.empty ib

val inline ctx \no-break inner =
no-break (read-inline ctx inner)
val omit-skip-after = omit-skip-after %PRIMITIVE

val inline ctx \skip len =
skip len

val inline ctx \kern len =
kern len

val inline ctx \fil =
discretionary 0 inline-nil inline-fil inline-nil
discretionary 0 nil fil nil

val inline ctx \fil-both =
discretionary 0 inline-nil inline-fil inline-fil

val mandatory-break ctx =
discretionary 0 (inline-skip (get-text-width ctx *' 2.)) inline-fil inline-nil
discretionary 0 nil fil fil

val inline ctx \mandatory-break =
mandatory-break ctx

val inline ctx \no-break inner =
no-break (read-inline ctx inner)

end
34 changes: 26 additions & 8 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/ordering.satyg
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,39 @@ use open Basic

module Ordering :> sig
type t = ordering
val equal : ordering -> ordering -> bool
val show : ordering -> string
val ~lift : ordering -> code ordering
val persistent ~compare : ordering -> ordering -> ordering
val persistent ~equal : ordering -> ordering -> bool
val persistent ~show : ordering -> string
end = struct

type t = ordering

val equal o1 o2 =
val ~lift o =
match o with
| Less -> &(Less)
| Equal -> &(Equal)
| Greater -> &(Greater)
end

val persistent ~compare o1 o2 =
match (o1, o2) with
| (Less, Less) -> true
| (Equal, Equal) -> true
| (Greater, Greater) -> true
| _ -> false
| (Less, Less) -> Equal
| (Less, _) -> Less
| (_, Less) -> Greater
| (Equal, Equal) -> Equal
| (Equal, Greater) -> Less
| (Greater, Equal) -> Greater
| (Greater, Greater) -> Equal
end

val persistent ~equal o1 o2 =
match compare o1 o2 with
| Equal -> true
| _ -> false
end

val show o =
val persistent ~show o =
match o with
| Less -> `Less`
| Equal -> `Equal`
Expand Down
50 changes: 46 additions & 4 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/stdlib.satyh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use Basic
use Int
use Float
use String
use Ordering
use Option
use List
Expand Down Expand Up @@ -28,6 +29,7 @@ module Stdlib :> sig
type vector = length * length
type point = length * length
type paren = length -> length -> context -> inline-boxes * (length -> length)
type paddings = length * length * length * length
signature Ord = sig
type t :: o
val compare : t -> t -> ordering
Expand All @@ -49,10 +51,30 @@ module Stdlib :> sig
val persistent ~min : float -> float -> float
val persistent ~pi : float
end
module String : sig
type t = string
val ~lift : string -> code string
val persistent ~compare : string -> string -> ordering
val persistent ~equal : string -> string -> bool
val persistent ~append : string -> string -> string
val persistent ~length : string -> int
val persistent ~byte-length : string -> int
val persistent ~sub : string -> int -> int -> string
val persistent ~sub-bytes : string -> int -> int -> string
val persistent ~to-scalar-values : string -> list int
val persistent ~from-scalar-values : list int -> string
val persistent ~normalize-to-nfc : string -> string
val persistent ~normalize-to-nfd : string -> string
val persistent ~split-into-grapheme-clusters : string -> list string
val persistent ~empty : string
val persistent ~split-into-lines : string -> list (int * string)
end
module Ordering : sig
type t = ordering
val equal : ordering -> ordering -> bool
val show : ordering -> string
val ~lift : ordering -> code ordering
val persistent ~compare : ordering -> ordering -> ordering
val persistent ~equal : ordering -> ordering -> bool
val persistent ~show : ordering -> string
end
module Option : sig
type t 'a = option 'a
Expand Down Expand Up @@ -171,20 +193,39 @@ module Stdlib :> sig
val \TeX : inline []
end
module Inline : sig
val nil : inline-boxes
val concat : list inline-boxes -> inline-boxes
val fil : inline-boxes
val get-natural-metrics : inline-boxes -> length * length * length
val get-natural-advance : inline-boxes -> length
val skip : length -> inline-boxes
val kern : length -> inline-boxes
val \skip : inline [length]
val glue : length -> length -> length -> inline-boxes
val frame-inner : paddings -> deco -> inline-boxes -> inline-boxes
val frame-outer : paddings -> deco -> inline-boxes -> inline-boxes
val frame-fixed : length -> paddings -> deco -> inline-boxes -> inline-boxes
val frame-breakable : paddings -> deco-set -> inline-boxes -> inline-boxes
val embed-block-breakable : context -> block-boxes -> inline-boxes
val graphics-fixed : length -> length -> length -> (point -> graphics) -> inline-boxes
val graphics-outer : length -> length -> (length -> point -> graphics) -> inline-boxes
val no-break : inline-boxes -> inline-boxes
val mandatory-break : context -> inline-boxes
val omit-skip-after : inline-boxes
val \skip : inline [length]
val \no-break : inline [inline-text]
val \fil : inline []
val \fil-both : inline []
val mandatory-break : context -> inline-boxes
val \mandatory-break : inline []
end
module Block : sig
val nil : block-boxes
val concat : list block-boxes -> block-boxes
val form-paragraph : context -> inline-boxes -> block-boxes
val +skip : block [length]
val \skip : inline [length]
val +clear-page : block []
val +ragged-right : block [inline-text]
val +centering : block [inline-text]
end
module Ref : sig
val persistent ~increment : ref int -> unit
Expand Down Expand Up @@ -273,6 +314,7 @@ end = struct
include Basic
module Int = Int
module Float = Float
module String = String
module Ordering = Ordering
module Option = Option
module List = List
Expand Down
58 changes: 58 additions & 0 deletions lib-satysfi/packages/stdlib/stdlib.0.0.1/src/string.satyg
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use open Basic
use Int
use List

module String :> sig
type t = string
val ~lift : string -> code string
val persistent ~compare : string -> string -> ordering
val persistent ~equal : string -> string -> bool
val persistent ~append : string -> string -> string
val persistent ~length : string -> int
val persistent ~byte-length : string -> int
val persistent ~sub : string -> int -> int -> string
val persistent ~sub-bytes : string -> int -> int -> string
val persistent ~to-scalar-values : string -> list int
val persistent ~from-scalar-values : list int -> string
val persistent ~normalize-to-nfc : string -> string
val persistent ~normalize-to-nfd : string -> string
val persistent ~split-into-grapheme-clusters : string -> list string
val persistent ~empty : string
val persistent ~split-into-lines : string -> list (int * string)
end = struct

type t = string

val ~lift = lift-string %PRIMITIVE

val persistent ~equal = string-same %PRIMITIVE

val persistent ~append = ( ^ ) %PRIMITIVE

val persistent ~length = string-length %PRIMITIVE

val persistent ~byte-length = string-byte-length %PRIMITIVE

val persistent ~sub = string-sub %PRIMITIVE

val persistent ~sub-bytes = string-sub-bytes %PRIMITIVE

val persistent ~to-scalar-values = string-explode %PRIMITIVE

val persistent ~from-scalar-values = string-unexplode %PRIMITIVE

val persistent ~normalize-to-nfc = normalize-string-to-nfc %PRIMITIVE

val persistent ~normalize-to-nfd = normalize-string-to-nfd %PRIMITIVE

val persistent ~split-into-grapheme-clusters = split-grapheme-cluster %PRIMITIVE

val persistent ~compare s1 s2 =
List.compare Int.compare (to-scalar-values s1) (to-scalar-values s2)

val persistent ~empty =
` `

val persistent ~split-into-lines = split-into-lines %PRIMITIVE

end

0 comments on commit 2bd3a5d

Please sign in to comment.