def content source · line 67 · raw
@why:String -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> 0x36754ca959c7683aed7402df6aa2fca0/token.Error
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.
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
Data
How scalars resolve: the YAML 1.2 Core schema, or the YAML 1.1 types.
Core Schema
Yaml11 Schema
Data
A finished node, and whether it is the merge key "<<".
Item @val:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> @merge:Bool -> Item
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.
OSeq @anchor:Maybe<&2, String> -> @tag:0x36754ca959c7683aed7402df6aa2fca0/parse.Tag -> @items:List<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml> -> @start:Nat -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Open
OMap @anchor:Maybe<&2, String> -> @tag:0x36754ca959c7683aed7402df6aa2fca0/parse.Tag -> @items:List<&2, Item> -> @start:Nat -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Open
Data
An anchored node and how many nodes it holds.
Anchored @val:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> @size:Nat -> Anchored
Data
A document and where it starts.
Doc @val:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Doc
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.
Co @stack:List<&2, Open> -> @anchors:Map<&2, Anchored> -> @count:Nat -> @root:Maybe<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml> -> @docs:List<&2, Doc> -> @opened:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Co
Data
Keys in order, and each key's entry, looked up by its canon text.
Ord @index:Map<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry> -> @order:List<&2, String> -> Ord
@-A:Type -> @hit:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A
@why:String -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> 0x36754ca959c7683aed7402df6aa2fca0/token.Error
Ord
@o:Ord -> @+key:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> Bool
@hm:Pair(Map<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry>, Bool) -> @+order:List<&2, String> -> @+c:String -> @key:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> @val:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> Ord
@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.
@es:List<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry> -> @o:Ord -> Ord
Each entry put in turn.
@es:List<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry> -> @+o:Ord -> Ord
The entries whose keys aren't there yet.
@order:List<&2, String> -> @+m:Map<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry> -> List<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry>
@o:Ord -> List<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Entry>
@v:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> String
@i:Item -> 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml
@i:Item -> Bool
@xs:List<&2, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml> -> @+o:Ord -> Result<&2, &2, String, Ord>
A list of mappings merged, the earlier winning.
@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.
@r:Result<&2, &2, String, Ord> -> @+k:Item -> @v:Item -> @+seen:Bool -> Result<&2, &2, String, Ord>
@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).
@r:Result<&2, &2, String, Ord> -> @+k:Item -> @v:Item -> Result<&2, &2, String, Ord>
@items:List<&2, Item> -> @r:Result<&2, &2, String, Ord> -> Result<&2, &2, String, Ord>
The mapping's own entries, each key once.
@merged:Result<&2, &2, String, Ord> -> @own:Result<&2, &2, String, Ord> -> Result<&2, &2, String, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml>
@+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.
@s:0x36754ca959c7683aed7402df6aa2fca0/token.Style -> Bool
@s:Schema -> @t:0x36754ca959c7683aed7402df6aa2fca0/parse.Tag -> @+text:String -> @+plain:Bool -> Result<&2, &2, String, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml>
@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.
@t:0x36754ca959c7683aed7402df6aa2fca0/parse.Tag -> @v:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml
@co:Co -> Nat
@co:Co -> List<&2, Doc>
@co:Co -> @item:Item -> Co
A finished node goes to the collection it's in, or is the document.
@m:Map<&2, Anchored> -> @anchor:Maybe<&2, String> -> @v:0x36754ca959c7683aed7402df6aa2fca0/value.Yaml -> @size:Nat -> Map<&2, Anchored>
@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).
@co:Co -> @o:Open -> Co
@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>
@m:Maybe<&2, String> -> @+name:String -> Bool
@stack:List<&2, Open> -> @+name:String -> Bool
Whether a collection still open has the anchor +name+.
@hm:Pair(Map<&2, Anchored>, Bool) -> Bool
@ma:Pair(Map<&2, Anchored>, Anchored) -> @+co:Co -> @+limit:Nat -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co>
@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.
@co:Co -> @at:0x36754ca959c7683aed7402df6aa2fca0/token.Mark -> Co
@co:Co -> Co
@r:Result<&2, &2, String, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml> -> @t:0x36754ca959c7683aed7402df6aa2fca0/parse.Tag -> Result<&2, &2, String, 0x36754ca959c7683aed7402df6aa2fca0/value.Yaml>
@co:Co -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co>
The collection on top ends.
@e:0x36754ca959c7683aed7402df6aa2fca0/parse.Evt -> @+co:Co -> @+s:Schema -> @+limit:Nat -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co>
@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>
Nat
How many nodes aliases may make a document: past this, it's refused.
Co
@r:Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, Co> -> Result<&2, &2, 0x36754ca959c7683aed7402df6aa2fca0/token.Error, List<&2, Doc>>
@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.
@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.