Packages / yaml-for-bend@0.1.1.0 / parse.bend
parse.bend checks
raw source on the hub · import yaml-for-bend@0.1.1.0/parse.bend as Parse
The parser: tokens to events.
It follows libyaml's parser: a state machine with a stack of the states to
return to. Each step looks at the next token and may take it and may emit
an event. Where libyaml looks at two tokens in one call, this parser takes
two steps, with a state in between, so a step never looks past one token.
Where YAML 1.2 and libyaml disagree, it reads YAML 1.2: ": value" with no
key has an empty key, a flow mapping's key may end on an earlier line
than its ":", a stream may start with "...", and a bare document may
follow "...".
3 imports import Base
import ./token.bend as T
import ./scan.bend as S Types 10 Definitions 90
Types
Data A node's tag, resolved: none, or its full name ("!" when non-specific).
NoTag Tag Tag @name:String -> Tag
Data An event, as libyaml's are.
StreamStartEv Ev StreamEndEv Ev DocStartEv @explicit:Bool -> Ev DocEndEv @explicit:Bool -> Ev AliasEv @name:String -> Ev ScalarEv @anchor:Maybe<&2, String> -> @tag:Tag -> @text:String -> @style:0x856d414a32087762da315b6efc605eaa/token.Style -> Ev SeqStartEv @anchor:Maybe<&2, String> -> @tag:Tag -> @flow:Bool -> Ev SeqEndEv Ev MapStartEv @anchor:Maybe<&2, String> -> @tag:Tag -> @flow:Bool -> Ev MapEndEv Ev
Data An event and where its node starts.
Data A tag as written: its handle and suffix.
Data A %TAG directive: a handle and the prefix it stands for.
Data The parser's states. A collection's state keeps where it started, for
errors; "After" states have just taken an indicator and keep where it
ended, where an empty node would be.
SStreamStart St SFirstDoc St SDocStart @ended:Bool -> St SDocContent St SDocEnd St SNode @block:Bool -> @indentless:Bool -> @anchor:Maybe<&2, String> -> @tag:Maybe<&2, Written> -> @start:Maybe<&2, 0x856d414a32087762da315b6efc605eaa/token.Mark> -> St SBSeqFirst St SBSeqEntry @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SBSeqAfter @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SIndentless @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SIndentlessAfter @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SBMapFirst St SBMapKey @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SBMapAfterKey @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SBMapValue @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SBMapAfterValue @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFSeqFirst St SFSeqEntry @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @first:Bool -> St SFSeqMapKey @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFSeqMapValue @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFSeqMapAfterValue @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFSeqMapEnd @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFMapFirst St SFMapKey @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @first:Bool -> St SFMapAfterKey @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFMapValue @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFMapAfterValue @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SFMapEmpty @m:0x856d414a32087762da315b6efc605eaa/token.Mark -> St SEnd St
Data The parser: the tokens left, the state, the states to return to, the
document's tag prefixes, and the events so far (newest first).
Ps @toks:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> @state:St -> @states:List<&2, St> -> @tags:List<&2, Prefix> -> @out:List<&2, Evt> -> Ps
Data The events, and the error that ended them early, if one did.
Data The directives before a document: its %TAG prefixes (over the defaults),
checking that %YAML comes at most once and is 1.x and that no handle
repeats.
Dirs @toks:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> @tags:List<&2, Prefix> -> Dirs DirsBad @error:0x856d414a32087762da315b6efc605eaa/token.Error -> Dirs
Definitions
@-A:Type -> @hit:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A
@ps:Ps -> @ev:Ev -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Ps
@ps:Ps -> Ps Returns to the state on the stack.
@ps:Ps -> @why:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> PStep
@ps:Ps -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Ps
@t:0x856d414a32087762da315b6efc605eaa/token.Token -> 0x856d414a32087762da315b6efc605eaa/token.Tok
@t:0x856d414a32087762da315b6efc605eaa/token.Token -> 0x856d414a32087762da315b6efc605eaa/token.Mark
@t:0x856d414a32087762da315b6efc605eaa/token.Token -> 0x856d414a32087762da315b6efc605eaa/token.Mark
@t:0x856d414a32087762da315b6efc605eaa/token.Tok -> Nat A token's kind as a number, to test it against a few.
@+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @k:Nat -> Bool
@+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @ks:List<&2, Nat> -> Bool
@ts:List<&2, Prefix> -> @+handle:String -> Maybe<&2, String>
@m:Maybe<&2, String> -> @suffix:String -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Tag>
@w:Maybe<&2, Written> -> @ts:List<&2, Prefix> -> @at:0x856d414a32087762da315b6efc605eaa/token.Mark -> Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Tag> A written tag's full name, through the document's %TAG prefixes.
@m:Maybe<&2, String> -> Bool
@toks:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> @+user:List<&2, Prefix> -> @+seen:Bool -> Dirs
@ps:Ps -> @ts:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> Ps
@ps:Ps -> List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token>
@ts:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> @k:Nat -> Bool
@ts:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> 0x856d414a32087762da315b6efc605eaa/token.Mark
@d:Dirs -> @+ps:Ps -> PStep After the directives, "---" must start the document.
@+ended:Bool -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep A document starts: bare, when nothing came before or the last one ended
with "..."; or with directives and "---"; or the stream ends.
@+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@m:Maybe<&2, 0x856d414a32087762da315b6efc605eaa/token.Mark> -> @d:0x856d414a32087762da315b6efc605eaa/token.Mark -> 0x856d414a32087762da315b6efc605eaa/token.Mark
@m:Maybe<&2, String> -> Bool
@m:Maybe<&2, Written> -> Bool
@+block:Bool -> @+props:Bool -> @anchor:Maybe<&2, String> -> @tag:Tag -> @+at:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+ps:Ps -> PStep No content: an empty scalar, when the node has an anchor or a tag.
@k:0x856d414a32087762da315b6efc605eaa/token.Tok -> @+block:Bool -> @+indentless:Bool -> @+anchor:Maybe<&2, String> -> @+tag:Tag -> @+props:Bool -> @+at:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+ps:Ps -> PStep The node's content, after its anchor and tag.
@r:Result<&2, &2, 0x856d414a32087762da315b6efc605eaa/token.Error, Tag> -> @+k:0x856d414a32087762da315b6efc605eaa/token.Tok -> @+block:Bool -> @+indentless:Bool -> @+anchor:Maybe<&2, String> -> @+props:Bool -> @+at:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+ps:Ps -> PStep
@+block:Bool -> @+indentless:Bool -> @+anchor:Maybe<&2, String> -> @+tag:Maybe<&2, Written> -> @+bare:Bool -> @+at:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@k:0x856d414a32087762da315b6efc605eaa/token.Tok -> @+block:Bool -> @+indentless:Bool -> @+anchor:Maybe<&2, String> -> @+tag:Maybe<&2, Written> -> @+bare:Bool -> @+at:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+block:Bool -> @+indentless:Bool -> @+anchor:Maybe<&2, String> -> @+tag:Maybe<&2, Written> -> @+start:Maybe<&2, 0x856d414a32087762da315b6efc605eaa/token.Mark> -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep A node: its anchor and tag (in either order), then an alias or content.
@+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+block:Bool -> @+indentless:Bool -> @back:St -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+first:Bool -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep An implicit pair's key in a flow sequence.
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+first:Bool -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @e:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@+m:0x856d414a32087762da315b6efc605eaa/token.Mark -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep After a key with no KeyTok: a ":" on a later line is still its value (a
flow mapping's key may run over lines), else the value is empty.
@s:St -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep
@k:0x856d414a32087762da315b6efc605eaa/token.Tok -> @+t:0x856d414a32087762da315b6efc605eaa/token.Token -> @+ps:Ps -> PStep A Broken token stops the parser with its error.
@ts:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> @+ps:Ps -> PStep
@fuel:Nat -> @s:PStep -> Parsed
@+toks:List<&2, 0x856d414a32087762da315b6efc605eaa/token.Token> -> Parsed The events of a token stream.
@text:String -> @max:Nat -> Parsed The events of a YAML text, with flow collections nesting at most +max+
deep.
@c:Char -> @rest:String -> String
@s:String -> String A scalar's text as the YAML test suite writes it: backslashes, breaks
and tabs escaped.
@s:0x856d414a32087762da315b6efc605eaa/token.Style -> String
@a:Maybe<&2, String> -> String
@+flow:Bool -> @brackets:String -> String
@e:Ev -> String An event as the YAML test suite writes it: "+MAP {} &a <tag>", "=VAL :x".
@es:List<&2, Evt> -> String
@m:Maybe<&2, 0x856d414a32087762da315b6efc605eaa/token.Error> -> String
@p:Parsed -> String The events of a parse, one per line, and the error after them.