MCPcopy
hub / github.com/go-yaml/yaml / yaml_parser_fetch_value

Function yaml_parser_fetch_value

scannerc.go:1370–1437  ·  view source on GitHub ↗

Produce the VALUE token.

(parser *yaml_parser_t)

Source from the content-addressed store, hash-verified

1368
1369// Produce the VALUE token.
1370func yaml_parser_fetch_value(parser *yaml_parser_t) bool {
1371
1372 simple_key := &parser.simple_keys[len(parser.simple_keys)-1]
1373
1374 // Have we found a simple key?
1375 if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok {
1376 return false
1377
1378 } else if valid {
1379
1380 // Create the KEY token and insert it into the queue.
1381 token := yaml_token_t{
1382 typ: yaml_KEY_TOKEN,
1383 start_mark: simple_key.mark,
1384 end_mark: simple_key.mark,
1385 }
1386 yaml_insert_token(parser, simple_key.token_number-parser.tokens_parsed, &token)
1387
1388 // In the block context, we may need to add the BLOCK-MAPPING-START token.
1389 if !yaml_parser_roll_indent(parser, simple_key.mark.column,
1390 simple_key.token_number,
1391 yaml_BLOCK_MAPPING_START_TOKEN, simple_key.mark) {
1392 return false
1393 }
1394
1395 // Remove the simple key.
1396 simple_key.possible = false
1397 delete(parser.simple_keys_by_tok, simple_key.token_number)
1398
1399 // A simple key cannot follow another simple key.
1400 parser.simple_key_allowed = false
1401
1402 } else {
1403 // The ':' indicator follows a complex key.
1404
1405 // In the block context, extra checks are required.
1406 if parser.flow_level == 0 {
1407
1408 // Check if we are allowed to start a complex value.
1409 if !parser.simple_key_allowed {
1410 return yaml_parser_set_scanner_error(parser, "", parser.mark,
1411 "mapping values are not allowed in this context")
1412 }
1413
1414 // Add the BLOCK-MAPPING-START token if needed.
1415 if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) {
1416 return false
1417 }
1418 }
1419
1420 // Simple keys after ':' are allowed in the block context.
1421 parser.simple_key_allowed = parser.flow_level == 0
1422 }
1423
1424 // Consume the token.
1425 start_mark := parser.mark
1426 skip(parser)
1427 end_mark := parser.mark

Callers 1

Calls 5

yaml_simple_key_is_validFunction · 0.85
yaml_insert_tokenFunction · 0.85
yaml_parser_roll_indentFunction · 0.85
skipFunction · 0.85

Tested by

no test coverage detected