def content source · line 82 · raw
@why:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> 0x856d414a32087762da315b6efc605eaa/token.Error
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.
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
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).
Limits @size:Nat -> @depth:Nat -> @aliases:Nat -> @digits:Nat -> Limits
Data
The limits the composer checks: the size is checked before it runs.
Caps @depth:Nat -> @aliases:Nat -> @digits:Nat -> Caps
Data
A finished node, and whether it is the merge key "<<".
Item @val:0x856d414a32087762da315b6efc605eaa/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:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @items:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @start:Nat -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Open
OMap @anchor:Maybe<&2, String> -> @tag:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @items:List<&2, Item> -> @start:Nat -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Open
Data
An anchored node and how many nodes it holds.
Anchored @val:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @size:Nat -> Anchored
Data
A document and where it starts.
Doc @val:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @at:0x856d414a32087762da315b6efc605eaa/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), where the document started, how deep its collections nest here, and how many nodes aliases copied.
Co @stack:List<&2, Open> -> @anchors:Map<&2, Anchored> -> @count:Nat -> @root:Maybe<&2, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @docs:List<&2, Doc> -> @opened:0x856d414a32087762da315b6efc605eaa/token.Mark -> @depth:Nat -> @copied:Nat -> Co
Data
Keys in order, and each key's entry, looked up by its canon text.
Ord @index:Map<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> @order:List<&2, String> -> Ord
@-A:Type -> @hit:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A
@why:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> 0x856d414a32087762da315b6efc605eaa/token.Error
Ord
@o:Ord -> @+key:0x856d414a32087762da315b6efc605eaa/value.Yaml -> Bool
@hm:Pair(Map<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry>, Bool) -> @+order:List<&2, String> -> @+c:String -> @key:0x856d414a32087762da315b6efc605eaa/value.Yaml -> @val:0x856d414a32087762da315b6efc605eaa/value.Yaml -> Ord
@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.
@es:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> @o:Ord -> Ord
Each entry put in turn.
@es:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> @+o:Ord -> Ord
The entries whose keys aren't there yet.
@order:List<&2, String> -> @+m:Map<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry> -> List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry>
@o:Ord -> List<&2, 0x856d414a32087762da315b6efc605eaa/value.Entry>
@v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> String
@i:Item -> 0x856d414a32087762da315b6efc605eaa/value.Yaml
@i:Item -> Bool
@xs:List<&2, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @+o:Ord -> Result<&2, &2, String, Ord>
A list of mappings merged, the earlier winning.
@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.
@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).
@merged:Result<&2, &2, String, Ord> -> @own:Result<&2, &2, String, Ord> -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>
@s:String -> @n:Nat -> Bool
Whether +s+ has more than +n+ characters, looking at no more than that.
@v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> String
A key as an error shows it: its first 80 characters.
@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.
@+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.
@s:0x856d414a32087762da315b6efc605eaa/token.Style -> Bool
@s:Schema -> @t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @+text:String -> @+plain:Bool -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>
@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.
@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.
@s:Schema -> @+text:String -> Bool
@+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+.
@t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> @v:0x856d414a32087762da315b6efc605eaa/value.Yaml -> 0x856d414a32087762da315b6efc605eaa/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:0x856d414a32087762da315b6efc605eaa/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).
@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>
@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
@co:Co -> @+more:Nat -> Co
@co:Co -> Nat
@co:Co -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Co
@co:Co -> Co
@r:Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml> -> @t:0x856d414a32087762da315b6efc605eaa/parse.Tag -> Result<&2, &2, String, 0x856d414a32087762da315b6efc605eaa/value.Yaml>
@co:Co -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>
The collection on top ends.
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.
@l:Limits -> Nat
@l:Limits -> Nat
@l:Limits -> Nat
@l:Limits -> Nat
@+l:Limits -> Caps
@c:Caps -> Nat
@c:Caps -> Nat
@c:Caps -> Nat
@why:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> 0x856d414a32087762da315b6efc605eaa/token.Error
@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.
@ma:Pair(Map<&2, Anchored>, Anchored) -> @+co:Co -> @+limit:Nat -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>
@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.
@e:0x856d414a32087762da315b6efc605eaa/parse.Evt -> @+co:Co -> @+s:Schema -> @+c:Caps -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co>
@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>
Co
@r:Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Co> -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, List<&2, Doc>>
@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.
@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+.