···99type state =
1010 | Stream_start
1111 | Implicit_document_start
1212- | Document_start
1312 | Document_content
1413 | Document_content_done (* After parsing a node, check for unexpected content *)
1514 | Document_end
1616- | Block_node
1717- | Block_node_or_indentless_sequence
1818- | Flow_node
1915 | Block_sequence_first_entry
2016 | Block_sequence_entry
2117 | Indentless_sequence_entry
···3026 | Flow_mapping_first_key
3127 | Flow_mapping_key
3228 | Flow_mapping_value
3333- | Flow_mapping_empty_value
3429 | End
35303631type t = {
3732 scanner : Scanner.t;
3833 mutable state : state;
3934 mutable states : state list; (** State stack *)
4040- mutable marks : Span.t list; (** Mark stack for span tracking *)
4135 mutable version : (int * int) option;
4236 mutable tag_directives : (string * string) list;
4337 mutable current_token : Token.spanned option;
···5044 scanner;
5145 state = Stream_start;
5246 states = [];
5353- marks = [];
5447 version = None;
5548 tag_directives = [
5649 ("!", "!");
···645638 | _ ->
646639 parse_document_start t ~implicit:true)
647640648648- | Document_start ->
649649- parse_document_start t ~implicit:false
650650-651641 | Document_content ->
652642 if check t (function
653643 | Token.Version_directive _ | Token.Tag_directive _
···684674 | Document_end ->
685675 parse_document_end t
686676687687- | Block_node ->
688688- parse_node t ~block:true ~indentless:false
689689-690690- | Block_node_or_indentless_sequence ->
691691- parse_node t ~block:true ~indentless:true
692692-693693- | Flow_node ->
694694- parse_node t ~block:false ~indentless:false
695695-696677 | Block_sequence_first_entry ->
697678 t.state <- Block_sequence_entry;
698679 parse_block_sequence_entry t
···736717737718 | Flow_mapping_value ->
738719 parse_flow_mapping_value t ~empty:false
739739-740740- | Flow_mapping_empty_value ->
741741- parse_flow_mapping_value t ~empty:true
742720743721 | End ->
744722 let span = Span.point Position.initial in
+9-15
lib/scanner.ml
···1717type indent = {
1818 indent : int;
1919 needs_block_end : bool;
2020- sequence : bool; (** true if this is a sequence indent *)
2120}
22212322type t = {
2423 input : Input.t;
2525- mutable tokens : Token.spanned Queue.t;
2424+ tokens : Token.spanned Queue.t;
2625 mutable token_number : int;
2726 mutable tokens_taken : int;
2827 mutable stream_started : bool;
···3534 mutable leading_whitespace : bool; (** True when at start of line (only whitespace seen) *)
3635 mutable document_has_content : bool; (** True if we've emitted content tokens in current document *)
3736 mutable adjacent_value_allowed_at : Position.t option; (** Position where adjacent : is allowed *)
3838- mutable pending_value : bool; (** True if we've emitted a KEY and are waiting for VALUE *)
3937 mutable flow_mapping_stack : bool list; (** Stack of whether each flow level is a mapping *)
4038}
4139···5553 leading_whitespace = true; (* Start at beginning of stream *)
5654 document_has_content = false;
5755 adjacent_value_allowed_at = None;
5858- pending_value = false;
5956 flow_mapping_stack = [];
6057 }
6158···173170 end
174171175172(** Roll the indentation level *)
176176-let roll_indent t col ~sequence =
173173+let roll_indent t col =
177174 if t.flow_level = 0 && col > current_indent t then begin
178178- t.indent_stack <- { indent = col; needs_block_end = true; sequence } :: t.indent_stack;
175175+ t.indent_stack <- { indent = col; needs_block_end = true } :: t.indent_stack;
179176 true
180177 end else
181178 false
···12611258 if not t.allow_simple_key then
12621259 Error.raise_at (Input.mark t.input) Block_sequence_disallowed;
12631260 let col = column t in
12641264- if roll_indent t col ~sequence:true then begin
12611261+ if roll_indent t col then begin
12651262 let span = Span.point (Input.mark t.input) in
12661263 emit t span Token.Block_sequence_start
12671264 end
···13021299 if not t.allow_simple_key then
13031300 Error.raise_at (Input.mark t.input) Expected_key;
13041301 let col = column t in
13051305- if roll_indent t col ~sequence:false then begin
13021302+ if roll_indent t col then begin
13061303 let span = Span.point (Input.mark t.input) in
13071304 emit t span Token.Block_mapping_start
13081305 end
···13211318 end;
1322131913231320 let span = Span.make ~start ~stop:(Input.mark t.input) in
13241324- emit t span Token.Key;
13251325- t.pending_value <- true (* We've emitted a KEY, now waiting for VALUE *)
13211321+ emit t span Token.Key
1326132213271323and check_value t =
13281324 (* : followed by whitespace in block, or whitespace/flow indicator in flow, or adjacent value *)
···13661362 if insert_pos >= Array.length tokens then
13671363 Queue.add key_token t.tokens;
13681364 t.token_number <- t.token_number + 1;
13691369- t.pending_value <- true; (* We've inserted a KEY token, now waiting for VALUE *)
13701365 (* Roll indent for implicit block mapping *)
13711366 if t.flow_level = 0 then begin
13721367 let col = sk.sk_position.column in
13731373- if roll_indent t col ~sequence:false then begin
13681368+ if roll_indent t col then begin
13741369 let span = Span.point sk.sk_position in
13751370 (* Insert block mapping start before key *)
13761371 let bm_token = { Token.token = Token.Block_mapping_start; span } in
···13931388 if not t.allow_simple_key then
13941389 Error.raise_at (Input.mark t.input) Expected_key;
13951390 let col = column t in
13961396- if roll_indent t col ~sequence:false then begin
13911391+ if roll_indent t col then begin
13971392 let span = Span.point (Input.mark t.input) in
13981393 emit t span Token.Block_mapping_start
13991394 end
···14281423 skip_whitespace_and_comment t;
1429142414301425 let span = Span.make ~start ~stop:(Input.mark t.input) in
14311431- emit t span Token.Value;
14321432- t.pending_value <- false (* We've emitted a VALUE, no longer pending *)
14261426+ emit t span Token.Value
1433142714341428and fetch_anchor_or_alias t ~is_alias =
14351429 save_simple_key t;