~/bend-docscommunity

compose.bend checks

raw source on the hub · import yaml-for-bend@0.1.0.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 a limit the document is refused, so a small text can't expand into a huge tree ("billion laughs").

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 27 · raw

Data

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

type Item source · line 32 · raw

Data

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

type Open source · line 38 · 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 43 · raw

Data

An anchored node and how many nodes it holds.

type Doc source · line 47 · raw

Data

A document and where it starts.

type Co source · line 53 · 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), and where the document started.

type Ord source · line 57 · raw

Data

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

Definitions

def when source · line 60 · raw

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

def content source · line 67 · raw

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

def ord.new source · line 73 · raw

Ord

def ord.has source · line 76 · raw

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

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

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

def ord.put source · line 86 · raw

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

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

def ord.merge source · line 93 · raw

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

Each entry put in turn.

def ord.fill source · line 103 · raw

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

The entries whose keys aren't there yet.

def ord.list source · line 112 · raw

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

def ord.entries source · line 119 · raw

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

def key.text source · line 127 · raw

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

def item.val source · line 134 · raw

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

def item.merge source · line 139 · raw

@i:Item -> Bool

def merge.list source · line 145 · raw

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

A list of mappings merged, the earlier winning.

def merge.value source · line 157 · raw

@v:0x36754ca959c7683aed7402df6aa2fca0/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 166 · raw

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

def merges source · line 175 · 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 own.step source · line 186 · raw

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

def owns source · line 197 · 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 joined source · line 208 · raw

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

def map.value source · line 221 · raw

@+items:List<&2, Item> -> Result<&2, &2, String, 0x36754ca959c7683aed7402df6aa2fca0/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 227 · raw

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

def scalar.value source · line 234 · raw

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

def is_merge source · line 250 · raw

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

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

def collection source · line 261 · raw

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

def co.count source · line 271 · raw

@co:Co -> Nat

def co.docs source · line 276 · raw

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

def attach source · line 282 · 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 295 · raw

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

def finish source · line 304 · 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 co.push source · line 309 · raw

@co:Co -> @o:Open -> Co

def node.done source · line 314 · raw

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

def is_name source · line 321 · raw

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

def opens source · line 329 · raw

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

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

def found source · line 340 · raw

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

def alias.got source · line 343 · raw

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

def co.alias source · line 353 · raw

@co:Co -> @+name:String -> @+limit:Nat -> @+at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/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.doc.start source · line 362 · raw

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

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

@co:Co -> Co

def map.tagged source · line 372 · raw

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

def co.close source · line 380 · raw

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

The collection on top ends.

def co.step source · line 393 · raw

@e:0x36754ca959c7683aed7402df6aa2fca0/parse.Evt -> @+co:Co -> @+s:Schema -> @+limit:Nat -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co>

def co.run source · line 419 · raw

@evs:List<&2, 0x36754ca959c7683aed7402df6aa2fca0/parse.Evt> -> @+s:Schema -> @+limit:Nat -> @r:Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co> -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co>

def alias.limit source · line 431 · raw

Nat

How many nodes aliases may make a document: past this, it's refused.

def co.new source · line 434 · raw

Co

def composed.ok source · line 437 · raw

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

def composed source · line 446 · raw

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

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

def compose.limited source · line 455 · raw

@p:0x36754ca959c7683aed7402df6aa2fca0/parse.Parsed -> @+s:Schema -> @+limit:Nat -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, List<&2, Doc>>

The documents the events hold, through schema +s+, with aliases making at most +limit+ nodes in a document.