Parse directives.
(parser *yaml_parser_t, version_directive_ref **yaml_version_directive_t, tag_directives_ref *[]yaml_tag_directive_t)
| 1174 | |
| 1175 | // Parse directives. |
| 1176 | func yaml_parser_process_directives(parser *yaml_parser_t, |
| 1177 | version_directive_ref **yaml_version_directive_t, |
| 1178 | tag_directives_ref *[]yaml_tag_directive_t) bool { |
| 1179 | |
| 1180 | var version_directive *yaml_version_directive_t |
| 1181 | var tag_directives []yaml_tag_directive_t |
| 1182 | |
| 1183 | token := peek_token(parser) |
| 1184 | if token == nil { |
| 1185 | return false |
| 1186 | } |
| 1187 | |
| 1188 | for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN { |
| 1189 | if token.typ == yaml_VERSION_DIRECTIVE_TOKEN { |
| 1190 | if version_directive != nil { |
| 1191 | yaml_parser_set_parser_error(parser, |
| 1192 | "found duplicate %YAML directive", token.start_mark) |
| 1193 | return false |
| 1194 | } |
| 1195 | if token.major != 1 || token.minor != 1 { |
| 1196 | yaml_parser_set_parser_error(parser, |
| 1197 | "found incompatible YAML document", token.start_mark) |
| 1198 | return false |
| 1199 | } |
| 1200 | version_directive = &yaml_version_directive_t{ |
| 1201 | major: token.major, |
| 1202 | minor: token.minor, |
| 1203 | } |
| 1204 | } else if token.typ == yaml_TAG_DIRECTIVE_TOKEN { |
| 1205 | value := yaml_tag_directive_t{ |
| 1206 | handle: token.value, |
| 1207 | prefix: token.prefix, |
| 1208 | } |
| 1209 | if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) { |
| 1210 | return false |
| 1211 | } |
| 1212 | tag_directives = append(tag_directives, value) |
| 1213 | } |
| 1214 | |
| 1215 | skip_token(parser) |
| 1216 | token = peek_token(parser) |
| 1217 | if token == nil { |
| 1218 | return false |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | for i := range default_tag_directives { |
| 1223 | if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) { |
| 1224 | return false |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | if version_directive_ref != nil { |
| 1229 | *version_directive_ref = version_directive |
| 1230 | } |
| 1231 | if tag_directives_ref != nil { |
| 1232 | *tag_directives_ref = tag_directives |
| 1233 | } |
no test coverage detected