src/text.bend checks
raw source on the hub · import ezsys@0.1.0.0/src/text.bend as Text
ezsys/src/text: text templates. A marker is an open delimiter, a key and a
close delimiter, {{name}} for text.fill. The scan reads the template
once, left to right, one character a step: at an open delimiter it starts a
key, and the key runs to the first close delimiter after it. A known key is
replaced by its value, written as it is (a value is never scanned again);
an unknown key, or a marker with no close, is left as written. Markers do
not nest. An empty open or close delimiter marks nothing.
1 import
import Base
Types
type Mode source · line 12 · raw
Data
where the scan is: in plain text, passing over the rest of an open delimiter, inside a key, or passing over the rest of a close delimiter
PlainMode
Opening@left:Nat -> Mode
InKey@key:String -> Mode
Closing@left:Nat -> Mode
Definitions
def text.Pairs source · line 19 · raw
Data
the keys and values, reusable
def text.own source · line 23 · raw
@xs:List<&1, Pair(String, String)> -> text.Pairs
a caller's pairs as reusable ones, in their order
def text.value.pick source · line 31 · raw
@hit:Bool -> @value:String -> @rest:(@_:Unit -> Maybe<&2, String>) -> Maybe<&2, String>
this pair's value when its key is the one asked for, else the rest's
def text.value source · line 43 · raw
@pairs:text.Pairs -> @+key:String -> Maybe<&2, String>
the value a key names: the first pair with that key
def text.tail source · line 52 · raw
@delim:String -> Nat
the characters of a delimiter after its first
def text.enter source · line 60 · raw
@left:Nat -> Mode
the mode after an open delimiter's first character, with left to pass
def text.leave source · line 68 · raw
@left:Nat -> Mode
the mode after a close delimiter's first character, with left to pass
def text.put source · line 76 · raw
@+open:String -> @+close:String -> @key:String -> @got:Maybe<&2, String> -> String
what a finished marker becomes: its value, or the marker as written
def text.plain source · line 89 · raw
@at:Bool -> @hd:Char -> @+open:String -> Pair(String, Mode)
a character in plain text: the start of a marker, or itself
def text.shut source · line 97 · raw
@at:Bool -> @hd:Char -> @+key:String -> @+open:String -> @+close:String -> @+pairs:text.Pairs -> Pair(String, Mode)
a character in a key: the start of the close delimiter, or part of the key
def text.step source · line 113 · raw
@+hd:Char -> @+tl:String -> @mode:Mode -> @+open:String -> @+close:String -> @+pairs:text.Pairs -> Pair(String, Mode)
one character: what it writes and the mode after it
def text.end source · line 133 · raw
@mode:Mode -> @+open:String -> String
the end of the template: an unclosed marker is written as it was
def text.join source · line 145 · raw
@pair:Pair(String, Mode) -> @rest:(@_:Mode -> String) -> String
write a step's text, then scan on in the mode after it
def text.go source · line 150 · raw
@tpl:String -> @mode:Mode -> @+open:String -> @+close:String -> @+pairs:text.Pairs -> String
the scan
def text.any source · line 165 · raw
@here:Bool -> @rest:(@_:Unit -> Bool) -> Bool
true when here is true, else what the rest says
def text.all source · line 173 · raw
@here:Bool -> @rest:(@_:Unit -> Bool) -> Bool
false when here is false, else what the rest says
def text.marked source · line 181 · raw
@+open:String -> @tpl:String -> Bool
whether an open delimiter starts anywhere in the text
def text.free source · line 190 · raw
@+close:String -> @key:String -> @+after:String -> Bool
whether no close delimiter starts at any character of key, in key ++ after
def text.fill_with source · line 199 · raw
@open:String -> @close:String -> @tpl:String -> @pairs:text.Pairs -> String
every marker between open and close replaced by its key's value
def text.fill source · line 214 · raw
@tpl:String -> @pairs:text.Pairs -> String
every {{key}} marker replaced by its key's value