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

Function yaml_parser_process_directives

xs/tools/yaml/parser.c:1254–1356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1252 */
1253
1254static int
1255yaml_parser_process_directives(yaml_parser_t *parser,
1256 yaml_version_directive_t **version_directive_ref,
1257 yaml_tag_directive_t **tag_directives_start_ref,
1258 yaml_tag_directive_t **tag_directives_end_ref)
1259{
1260 yaml_tag_directive_t default_tag_directives[] = {
1261 {(yaml_char_t *)"!", (yaml_char_t *)"!"},
1262 {(yaml_char_t *)"!!", (yaml_char_t *)"tag:yaml.org,2002:"},
1263 {NULL, NULL}
1264 };
1265 yaml_tag_directive_t *default_tag_directive;
1266 yaml_version_directive_t *version_directive = NULL;
1267 struct {
1268 yaml_tag_directive_t *start;
1269 yaml_tag_directive_t *end;
1270 yaml_tag_directive_t *top;
1271 } tag_directives = { NULL, NULL, NULL };
1272 yaml_token_t *token;
1273
1274 if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_SIZE))
1275 goto error;
1276
1277 token = PEEK_TOKEN(parser);
1278 if (!token) goto error;
1279
1280 while (token->type == YAML_VERSION_DIRECTIVE_TOKEN ||
1281 token->type == YAML_TAG_DIRECTIVE_TOKEN)
1282 {
1283 if (token->type == YAML_VERSION_DIRECTIVE_TOKEN) {
1284 if (version_directive) {
1285 yaml_parser_set_parser_error(parser,
1286 "found duplicate %YAML directive", token->start_mark);
1287 goto error;
1288 }
1289 if (token->data.version_directive.major != 1
1290 || token->data.version_directive.minor != 1) {
1291 yaml_parser_set_parser_error(parser,
1292 "found incompatible YAML document", token->start_mark);
1293 goto error;
1294 }
1295 version_directive = yaml_malloc(sizeof(yaml_version_directive_t));
1296 if (!version_directive) {
1297 parser->error = YAML_MEMORY_ERROR;
1298 goto error;
1299 }
1300 version_directive->major = token->data.version_directive.major;
1301 version_directive->minor = token->data.version_directive.minor;
1302 }
1303
1304 else if (token->type == YAML_TAG_DIRECTIVE_TOKEN) {
1305 yaml_tag_directive_t value;
1306 value.handle = token->data.tag_directive.handle;
1307 value.prefix = token->data.tag_directive.prefix;
1308
1309 if (!yaml_parser_append_tag_directive(parser, value, 0,
1310 token->start_mark))
1311 goto error;

Callers 1

Calls 4

yaml_mallocFunction · 0.85
yaml_freeFunction · 0.85

Tested by

no test coverage detected