MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / yaml_parser_fetch_next_token

Function yaml_parser_fetch_next_token

xs/tools/yaml/scanner.c:881–1070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879 */
880
881static int
882yaml_parser_fetch_next_token(yaml_parser_t *parser)
883{
884 /* Ensure that the buffer is initialized. */
885
886 if (!CACHE(parser, 1))
887 return 0;
888
889 /* Check if we just started scanning. Fetch STREAM-START then. */
890
891 if (!parser->stream_start_produced)
892 return yaml_parser_fetch_stream_start(parser);
893
894 /* Eat whitespaces and comments until we reach the next token. */
895
896 if (!yaml_parser_scan_to_next_token(parser))
897 return 0;
898
899 /* Remove obsolete potential simple keys. */
900
901 if (!yaml_parser_stale_simple_keys(parser))
902 return 0;
903
904 /* Check the indentation level against the current column. */
905
906 if (!yaml_parser_unroll_indent(parser, parser->mark.column))
907 return 0;
908
909 /*
910 * Ensure that the buffer contains at least 4 characters. 4 is the length
911 * of the longest indicators ('--- ' and '... ').
912 */
913
914 if (!CACHE(parser, 4))
915 return 0;
916
917 /* Is it the end of the stream? */
918
919 if (IS_Z(parser->buffer))
920 return yaml_parser_fetch_stream_end(parser);
921
922 /* Is it a directive? */
923
924 if (parser->mark.column == 0 && CHECK(parser->buffer, '%'))
925 return yaml_parser_fetch_directive(parser);
926
927 /* Is it the document start indicator? */
928
929 if (parser->mark.column == 0
930 && CHECK_AT(parser->buffer, '-', 0)
931 && CHECK_AT(parser->buffer, '-', 1)
932 && CHECK_AT(parser->buffer, '-', 2)
933 && IS_BLANKZ_AT(parser->buffer, 3))
934 return yaml_parser_fetch_document_indicator(parser,
935 YAML_DOCUMENT_START_TOKEN);
936
937 /* Is it the document end indicator? */
938

Callers 1

Tested by

no test coverage detected