~/bend-docscommunity

compose.bend checks

raw source on the hub · import yaml-for-bend@0.1.1.0/compose.bend as Compose

The composer: events to values, through a schema.

It reads the events in order with a stack of the collections still open. A scalar is resolved as it arrives; a collection is finished at its end event, where a mapping's keys are checked and merged. An anchored node is kept by name, and an alias is a copy of it. Every alias adds the size of its node to a count, and past the alias limit the document is refused, so a small text can't expand into a huge tree ("billion laughs"); past the depth limit, so can't a deep one. A number written in a base other than ten, past the digits limit, is refused before it is converted.

A key may appear once in a mapping; a repeat is an error. Under YAML 1.1, "<<" merges a mapping, or a list of them, into the mapping it's in: the mapping's own keys win, and among merged mappings the earlier wins.

6 imports
import Base
import ./token.bend as T
import ./parse.bend as P
import ./value.bend as V
import ./core.bend as C
import ./yaml11.bend as Y11

Types

type Schema source · line 29 · raw

Data

How scalars resolve: the YAML 1.2 Core schema, or the YAML 1.1 types.

type Limits source · line 38 · raw

Data

What a load may take, so a hostile text can't make it slow or huge: the characters in the text, how deep its collections may nest, how many nodes aliases may copy into a document, and how long a number may be when it is written in a base other than ten (converting one takes time that grows with the square of its length).

type Caps source · line 42 · raw

Data

The limits the composer checks: the size is checked before it runs.

type Item source · line 46 · raw

Data

A finished node, and whether it is the merge key "<<".

type Open source · line 52 · raw

Data

A collection still open: its anchor and tag, its items so far (newest first; a mapping's alternate keys and values), how many nodes came before it, and where it starts.

type Anchored source · line 57 · raw

Data

An anchored node and how many nodes it holds.

type Doc source · line 61 · raw

Data

A document and where it starts.

type Co source · line 68 · raw

Data

The composer: the open collections, the anchors, how many nodes the document has (aliases counted in full), the document's value once it has one, the documents so far (newest first), where the document started, how deep its collections nest here, and how many nodes aliases copied.

type Ord source · line 72 · raw

Data

Keys in order, and each key's entry, looked up by its canon text.

Definitions

def when source · line 75 · raw

@-A:Type -> @hit:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A

def content source · line 82 · raw

@why:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> 0x856d414a32087762da315b6efc605eaa/token.Error

def ord.new source · line 88 · raw

Ord

def ord.has source · line 91 · raw

@o:Ord -> @+key:0x856d414a32087762da315b6efc605eaa/value.Yaml -> Bool

def ord.put.at source · line 96 · raw

@hm:Pair(Map<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry>, Bool) -> @+order:List<&2, String> -> @+c:String -> @key:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @val:0x856d414a32087762da315b6efc605eaa/value.Yaml -> Ord

def ord.put source · line 101 · raw

@o:Ord -> @+key:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @val:0x856d414a32087762da315b6efc605eaa/value.Yaml -> Ord

Puts +key+'s value: in its place when it's there, else at the end.

def ord.merge source · line 108 · raw

@es:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> @o:Ord -> Ord

Each entry put in turn.

def ord.fill source · line 118 · raw

@es:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> @+o:Ord -> Ord

The entries whose keys aren't there yet.

def ord.list source · line 127 · raw

@order:List<&2, String> -> @+m:Map<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry>

def ord.entries source · line 134 · raw

@o:Ord -> List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry>

def key.full source · line 142 · raw

@v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> String

def item.val source · line 149 · raw

@i:Item -> 0x856d414a32087762da315b6efc605eaa/value.Yaml

def item.merge source · line 154 · raw

@i:Item -> Bool

def merge.list source · line 160 · raw

@xs:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @+o:Ord -> Result<&2, &2, String, Ord>

A list of mappings merged, the earlier winning.

def merge.value source · line 172 · raw

@v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @+o:Ord -> Result<&2, &2, String, Ord>

What a "<<" brings in: a mapping's entries, or each of a list's.

def merge.step source · line 181 · raw

@r:Result<&2, &2, String, Ord> -> @+k:Item -> @v:Item -> @+seen:Bool -> Result<&2, &2, String, Ord>

def merges source · line 190 · raw

@items:List<&2, Item> -> @r:Result<&2, &2, String, Ord> -> @+seen:Bool -> Result<&2, &2, String, Ord>

The merged entries, from the mapping's "<<" (it may have one).

def joined source · line 201 · raw

@merged:Result<&2, &2, String, Ord> -> @own:Result<&2, &2, String, Ord> -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>

def longer source · line 216 · raw

@s:String -> @n:Nat -> Bool

Whether +s+ has more than +n+ characters, looking at no more than that.

def key.text source · line 228 · raw

@v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> String

A key as an error shows it: its first 80 characters.

def own.step source · line 232 · raw

@r:Result<&2, &2, String, Ord> -> @+k:Item -> @v:Item -> Result<&2, &2, String, Ord>

def owns source · line 243 · raw

@items:List<&2, Item> -> @r:Result<&2, &2, String, Ord> -> Result<&2, &2, String, Ord>

The mapping's own entries, each key once.

def map.value source · line 256 · raw

@+items:List<&2, Item> -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>

A mapping from its keys and values, oldest first: merged entries first, then its own, which replace any merged ones with the same key.

def is_plain source · line 259 · raw

@s:0x856d414a32087762da315b6efc605eaa/token.Style -> Bool

def scalar.value source · line 266 · raw

@s:Schema -> @t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @+text:String -> @+plain:Bool -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>

def is_merge source · line 282 · raw

@s:Schema -> @t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @+text:String -> @+plain:Bool -> Bool

Whether a scalar is YAML 1.1's merge key: "<<" plain, or tagged !!merge.

def as.number source · line 295 · raw

@t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @+plain:Bool -> Bool

Whether a scalar's text is read as a number: plain without a tag, or tagged !!int or !!float.

def in.base source · line 302 · raw

@s:Schema -> @+text:String -> Bool

def too.long source · line 310 · raw

@+s:Schema -> @t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @+text:String -> @+plain:Bool -> @+limit:Nat -> Bool

Whether a scalar is a number in another base longer than +limit+.

def collection source · line 313 · raw

@t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> 0x856d414a32087762da315b6efc605eaa/value.Yaml

def co.count source · line 323 · raw

@co:Co -> Nat

def co.docs source · line 328 · raw

@co:Co -> List<&2, Doc>

def attach source · line 334 · raw

@co:Co -> @item:Item -> Co

A finished node goes to the collection it's in, or is the document.

def name.anchor source · line 347 · raw

@m:Map<&2, Anchored> -> @anchor:Maybe<&2, String> -> @v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @size:Nat -> Map<&2, Anchored>

def finish source · line 356 · raw

@co:Co -> @anchor:Maybe<&2, String> -> @+item:Item -> @+size:Nat -> @more:Nat -> Co

A node of +size+ nodes is finished: its anchor names it, and the count grows by +more+ (the nodes not counted yet: a collection's items were).

def node.done source · line 361 · raw

@r:Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @co:Co -> @anchor:Maybe<&2, String> -> @+merge:Bool -> @+size:Nat -> @more:Nat -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

def is_name source · line 368 · raw

@m:Maybe<&2, String> -> @+name:String -> Bool

def opens source · line 376 · raw

@stack:List<&2, Open> -> @+name:String -> Bool

Whether a collection still open has the anchor +name+.

def found source · line 387 · raw

@hm:Pair(Map<&2, Anchored>, Bool) -> Bool

def co.copied source · line 390 · raw

@co:Co -> @+more:Nat -> Co

def co.copied.count source · line 395 · raw

@co:Co -> Nat

def co.doc.start source · line 400 · raw

@co:Co -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Co

def co.doc.end source · line 405 · raw

@co:Co -> Co

def map.tagged source · line 410 · raw

@r:Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>

def co.close source · line 418 · raw

@co:Co -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

The collection on top ends.

def limits source · line 434 · raw

Limits

The default limits: a text of at most 1048576 characters (1 MiB), nesting at most 256 deep, aliases copying at most 100000 nodes into a document, and numbers in other bases at most 1000 characters long.

def limits.size source · line 437 · raw

@l:Limits -> Nat

def limits.depth source · line 442 · raw

@l:Limits -> Nat

def limits.aliases source · line 447 · raw

@l:Limits -> Nat

def limits.digits source · line 452 · raw

@l:Limits -> Nat

def caps source · line 457 · raw

@+l:Limits -> Caps

def caps.depth source · line 460 · raw

@c:Caps -> Nat

def caps.aliases source · line 465 · raw

@c:Caps -> Nat

def caps.digits source · line 470 · raw

@c:Caps -> Nat

def limit.error source · line 475 · raw

@why:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> 0x856d414a32087762da315b6efc605eaa/token.Error

def co.push source · line 479 · raw

@co:Co -> @o:Open -> @+limit:Nat -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

A collection opens, unless collections already nest as deep as allowed.

def alias.got source · line 485 · raw

@ma:Pair(Map<&2, Anchored>, Anchored) -> @+co:Co -> @+limit:Nat -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

def co.alias source · line 495 · raw

@co:Co -> @+name:String -> @+limit:Nat -> @+at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

An alias: a copy of its node, counted at the node's full size. An alias inside the node it names would make a cycle, which a tree can't hold.

def co.step source · line 504 · raw

@e:0x856d414a32087762da315b6efc605eaa/parse.Evt -> @+co:Co -> @+s:Schema -> @+c:Caps -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

def co.run source · line 532 · raw

@evs:List<&2, 0x856d414a32087762da315b6efc605eaa/parse.Evt> -> @+s:Schema -> @+c:Caps -> @r:Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co> -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>

def co.new source · line 543 · raw

Co

def composed.ok source · line 546 · raw

@r:Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co> -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, List<&2, Doc>>

def composed source · line 555 · raw

@r:Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co> -> @error:Maybe<&2, 0x856d414a32087762da315b6efc605eaa/token.Error> -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, List<&2, Doc>>

A text that isn't YAML is a syntax error, before anything its values do wrong.

def compose source · line 563 · raw

@p:0x856d414a32087762da315b6efc605eaa/parse.Parsed -> @+s:Schema -> @+lim:Limits -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, List<&2, Doc>>

The documents the events hold, through schema +s+, within limits +lim+.