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

Function yaml_parser_scan_directive

scannerc.go:1622–1717  ·  view source on GitHub ↗

Scan a YAML-DIRECTIVE or TAG-DIRECTIVE token. Scope: %YAML 1.1 # a comment \n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %TAG !yaml! tag:yaml.org,2002: \n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(parser *yaml_parser_t, token *yaml_token_t)

Source from the content-addressed store, hash-verified

1620// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1621//
1622func yaml_parser_scan_directive(parser *yaml_parser_t, token *yaml_token_t) bool {
1623 // Eat '%'.
1624 start_mark := parser.mark
1625 skip(parser)
1626
1627 // Scan the directive name.
1628 var name []byte
1629 if !yaml_parser_scan_directive_name(parser, start_mark, &name) {
1630 return false
1631 }
1632
1633 // Is it a YAML directive?
1634 if bytes.Equal(name, []byte("YAML")) {
1635 // Scan the VERSION directive value.
1636 var major, minor int8
1637 if !yaml_parser_scan_version_directive_value(parser, start_mark, &major, &minor) {
1638 return false
1639 }
1640 end_mark := parser.mark
1641
1642 // Create a VERSION-DIRECTIVE token.
1643 *token = yaml_token_t{
1644 typ: yaml_VERSION_DIRECTIVE_TOKEN,
1645 start_mark: start_mark,
1646 end_mark: end_mark,
1647 major: major,
1648 minor: minor,
1649 }
1650
1651 // Is it a TAG directive?
1652 } else if bytes.Equal(name, []byte("TAG")) {
1653 // Scan the TAG directive value.
1654 var handle, prefix []byte
1655 if !yaml_parser_scan_tag_directive_value(parser, start_mark, &handle, &prefix) {
1656 return false
1657 }
1658 end_mark := parser.mark
1659
1660 // Create a TAG-DIRECTIVE token.
1661 *token = yaml_token_t{
1662 typ: yaml_TAG_DIRECTIVE_TOKEN,
1663 start_mark: start_mark,
1664 end_mark: end_mark,
1665 value: handle,
1666 prefix: prefix,
1667 }
1668
1669 // Unknown directive.
1670 } else {
1671 yaml_parser_set_scanner_error(parser, "while scanning a directive",
1672 start_mark, "found unknown directive name")
1673 return false
1674 }
1675
1676 // Eat the rest of the line including any comments.
1677 if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) {
1678 return false
1679 }

Callers 1

Calls 10

skipFunction · 0.85
is_blankFunction · 0.85
is_breakzFunction · 0.85
is_breakFunction · 0.85
skip_lineFunction · 0.85

Tested by

no test coverage detected