Merge pull request #63 from jpsim/nn-remove-unused-libyaml-files
Remove unused libYAML files
This commit is contained in:
commit
9103e0454a
|
@ -1,394 +0,0 @@
|
|||
|
||||
#include "yaml_private.h"
|
||||
|
||||
/*
|
||||
* API functions.
|
||||
*/
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_emitter_open(yaml_emitter_t *emitter);
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_emitter_close(yaml_emitter_t *emitter);
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document);
|
||||
|
||||
/*
|
||||
* Clean up functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter);
|
||||
|
||||
/*
|
||||
* Anchor functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index);
|
||||
|
||||
static yaml_char_t *
|
||||
yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id);
|
||||
|
||||
|
||||
/*
|
||||
* Serialize functions.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_node(yaml_emitter_t *emitter, int index);
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor);
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node,
|
||||
yaml_char_t *anchor);
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node,
|
||||
yaml_char_t *anchor);
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node,
|
||||
yaml_char_t *anchor);
|
||||
|
||||
/*
|
||||
* Issue a STREAM-START event.
|
||||
*/
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_emitter_open(yaml_emitter_t *emitter)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
assert(emitter); /* Non-NULL emitter object is required. */
|
||||
assert(!emitter->opened); /* Emitter should not be opened yet. */
|
||||
|
||||
STREAM_START_EVENT_INIT(event, YAML_ANY_ENCODING, mark, mark);
|
||||
|
||||
if (!yaml_emitter_emit(emitter, &event)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
emitter->opened = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue a STREAM-END event.
|
||||
*/
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_emitter_close(yaml_emitter_t *emitter)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
assert(emitter); /* Non-NULL emitter object is required. */
|
||||
assert(emitter->opened); /* Emitter should be opened. */
|
||||
|
||||
if (emitter->closed) return 1;
|
||||
|
||||
STREAM_END_EVENT_INIT(event, mark, mark);
|
||||
|
||||
if (!yaml_emitter_emit(emitter, &event)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
emitter->closed = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump a YAML document.
|
||||
*/
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
assert(emitter); /* Non-NULL emitter object is required. */
|
||||
assert(document); /* Non-NULL emitter object is expected. */
|
||||
|
||||
emitter->document = document;
|
||||
|
||||
if (!emitter->opened) {
|
||||
if (!yaml_emitter_open(emitter)) goto error;
|
||||
}
|
||||
|
||||
if (STACK_EMPTY(emitter, document->nodes)) {
|
||||
if (!yaml_emitter_close(emitter)) goto error;
|
||||
yaml_emitter_delete_document_and_anchors(emitter);
|
||||
return 1;
|
||||
}
|
||||
|
||||
assert(emitter->opened); /* Emitter should be opened. */
|
||||
|
||||
emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
|
||||
* (document->nodes.top - document->nodes.start));
|
||||
if (!emitter->anchors) goto error;
|
||||
memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
|
||||
* (document->nodes.top - document->nodes.start));
|
||||
|
||||
DOCUMENT_START_EVENT_INIT(event, document->version_directive,
|
||||
document->tag_directives.start, document->tag_directives.end,
|
||||
document->start_implicit, mark, mark);
|
||||
if (!yaml_emitter_emit(emitter, &event)) goto error;
|
||||
|
||||
yaml_emitter_anchor_node(emitter, 1);
|
||||
if (!yaml_emitter_dump_node(emitter, 1)) goto error;
|
||||
|
||||
DOCUMENT_END_EVENT_INIT(event, document->end_implicit, mark, mark);
|
||||
if (!yaml_emitter_emit(emitter, &event)) goto error;
|
||||
|
||||
yaml_emitter_delete_document_and_anchors(emitter);
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
|
||||
yaml_emitter_delete_document_and_anchors(emitter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clean up the emitter object after a document is dumped.
|
||||
*/
|
||||
|
||||
static void
|
||||
yaml_emitter_delete_document_and_anchors(yaml_emitter_t *emitter)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (!emitter->anchors) {
|
||||
yaml_document_delete(emitter->document);
|
||||
emitter->document = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
for (index = 0; emitter->document->nodes.start + index
|
||||
< emitter->document->nodes.top; index ++) {
|
||||
yaml_node_t node = emitter->document->nodes.start[index];
|
||||
if (!emitter->anchors[index].serialized) {
|
||||
yaml_free(node.tag);
|
||||
if (node.type == YAML_SCALAR_NODE) {
|
||||
yaml_free(node.data.scalar.value);
|
||||
}
|
||||
}
|
||||
if (node.type == YAML_SEQUENCE_NODE) {
|
||||
STACK_DEL(emitter, node.data.sequence.items);
|
||||
}
|
||||
if (node.type == YAML_MAPPING_NODE) {
|
||||
STACK_DEL(emitter, node.data.mapping.pairs);
|
||||
}
|
||||
}
|
||||
|
||||
STACK_DEL(emitter, emitter->document->nodes);
|
||||
yaml_free(emitter->anchors);
|
||||
|
||||
emitter->anchors = NULL;
|
||||
emitter->last_anchor_id = 0;
|
||||
emitter->document = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the references of a node and assign the anchor id if needed.
|
||||
*/
|
||||
|
||||
static void
|
||||
yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index)
|
||||
{
|
||||
yaml_node_t *node = emitter->document->nodes.start + index - 1;
|
||||
yaml_node_item_t *item;
|
||||
yaml_node_pair_t *pair;
|
||||
|
||||
emitter->anchors[index-1].references ++;
|
||||
|
||||
if (emitter->anchors[index-1].references == 1) {
|
||||
switch (node->type) {
|
||||
case YAML_SEQUENCE_NODE:
|
||||
for (item = node->data.sequence.items.start;
|
||||
item < node->data.sequence.items.top; item ++) {
|
||||
yaml_emitter_anchor_node(emitter, *item);
|
||||
}
|
||||
break;
|
||||
case YAML_MAPPING_NODE:
|
||||
for (pair = node->data.mapping.pairs.start;
|
||||
pair < node->data.mapping.pairs.top; pair ++) {
|
||||
yaml_emitter_anchor_node(emitter, pair->key);
|
||||
yaml_emitter_anchor_node(emitter, pair->value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (emitter->anchors[index-1].references == 2) {
|
||||
emitter->anchors[index-1].anchor = (++ emitter->last_anchor_id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate a textual representation for an anchor.
|
||||
*/
|
||||
|
||||
#define ANCHOR_TEMPLATE "id%03d"
|
||||
#define ANCHOR_TEMPLATE_LENGTH 16
|
||||
|
||||
static yaml_char_t *
|
||||
yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id)
|
||||
{
|
||||
yaml_char_t *anchor = yaml_malloc(ANCHOR_TEMPLATE_LENGTH);
|
||||
|
||||
if (!anchor) return NULL;
|
||||
|
||||
sprintf((char *)anchor, ANCHOR_TEMPLATE, anchor_id);
|
||||
|
||||
return anchor;
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a node.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_node(yaml_emitter_t *emitter, int index)
|
||||
{
|
||||
yaml_node_t *node = emitter->document->nodes.start + index - 1;
|
||||
int anchor_id = emitter->anchors[index-1].anchor;
|
||||
yaml_char_t *anchor = NULL;
|
||||
|
||||
if (anchor_id) {
|
||||
anchor = yaml_emitter_generate_anchor(emitter, anchor_id);
|
||||
if (!anchor) return 0;
|
||||
}
|
||||
|
||||
if (emitter->anchors[index-1].serialized) {
|
||||
return yaml_emitter_dump_alias(emitter, anchor);
|
||||
}
|
||||
|
||||
emitter->anchors[index-1].serialized = 1;
|
||||
|
||||
switch (node->type) {
|
||||
case YAML_SCALAR_NODE:
|
||||
return yaml_emitter_dump_scalar(emitter, node, anchor);
|
||||
case YAML_SEQUENCE_NODE:
|
||||
return yaml_emitter_dump_sequence(emitter, node, anchor);
|
||||
case YAML_MAPPING_NODE:
|
||||
return yaml_emitter_dump_mapping(emitter, node, anchor);
|
||||
default:
|
||||
assert(0); /* Could not happen. */
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; /* Could not happen. */
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize an alias.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_alias(yaml_emitter_t *emitter, yaml_char_t *anchor)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
ALIAS_EVENT_INIT(event, anchor, mark, mark);
|
||||
|
||||
return yaml_emitter_emit(emitter, &event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a scalar.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_scalar(yaml_emitter_t *emitter, yaml_node_t *node,
|
||||
yaml_char_t *anchor)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
int plain_implicit = (strcmp((char *)node->tag,
|
||||
YAML_DEFAULT_SCALAR_TAG) == 0);
|
||||
int quoted_implicit = (strcmp((char *)node->tag,
|
||||
YAML_DEFAULT_SCALAR_TAG) == 0);
|
||||
|
||||
SCALAR_EVENT_INIT(event, anchor, node->tag, node->data.scalar.value,
|
||||
node->data.scalar.length, plain_implicit, quoted_implicit,
|
||||
node->data.scalar.style, mark, mark);
|
||||
|
||||
return yaml_emitter_emit(emitter, &event);
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a sequence.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node,
|
||||
yaml_char_t *anchor)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_SEQUENCE_TAG) == 0);
|
||||
|
||||
yaml_node_item_t *item;
|
||||
|
||||
SEQUENCE_START_EVENT_INIT(event, anchor, node->tag, implicit,
|
||||
node->data.sequence.style, mark, mark);
|
||||
if (!yaml_emitter_emit(emitter, &event)) return 0;
|
||||
|
||||
for (item = node->data.sequence.items.start;
|
||||
item < node->data.sequence.items.top; item ++) {
|
||||
if (!yaml_emitter_dump_node(emitter, *item)) return 0;
|
||||
}
|
||||
|
||||
SEQUENCE_END_EVENT_INIT(event, mark, mark);
|
||||
if (!yaml_emitter_emit(emitter, &event)) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a mapping.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node,
|
||||
yaml_char_t *anchor)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_mark_t mark = { 0, 0, 0 };
|
||||
|
||||
int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_MAPPING_TAG) == 0);
|
||||
|
||||
yaml_node_pair_t *pair;
|
||||
|
||||
MAPPING_START_EVENT_INIT(event, anchor, node->tag, implicit,
|
||||
node->data.mapping.style, mark, mark);
|
||||
if (!yaml_emitter_emit(emitter, &event)) return 0;
|
||||
|
||||
for (pair = node->data.mapping.pairs.start;
|
||||
pair < node->data.mapping.pairs.top; pair ++) {
|
||||
if (!yaml_emitter_dump_node(emitter, pair->key)) return 0;
|
||||
if (!yaml_emitter_dump_node(emitter, pair->value)) return 0;
|
||||
}
|
||||
|
||||
MAPPING_END_EVENT_INIT(event, mark, mark);
|
||||
if (!yaml_emitter_emit(emitter, &event)) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,453 +0,0 @@
|
|||
|
||||
#include "yaml_private.h"
|
||||
|
||||
/*
|
||||
* API functions.
|
||||
*/
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
|
||||
|
||||
/*
|
||||
* Error handling.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_set_composer_error(yaml_parser_t *parser,
|
||||
const char *problem, yaml_mark_t problem_mark);
|
||||
|
||||
static int
|
||||
yaml_parser_set_composer_error_context(yaml_parser_t *parser,
|
||||
const char *context, yaml_mark_t context_mark,
|
||||
const char *problem, yaml_mark_t problem_mark);
|
||||
|
||||
|
||||
/*
|
||||
* Alias handling.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_register_anchor(yaml_parser_t *parser,
|
||||
int index, yaml_char_t *anchor);
|
||||
|
||||
/*
|
||||
* Clean up functions.
|
||||
*/
|
||||
|
||||
static void
|
||||
yaml_parser_delete_aliases(yaml_parser_t *parser);
|
||||
|
||||
/*
|
||||
* Composer functions.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event);
|
||||
|
||||
static int
|
||||
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event);
|
||||
|
||||
static int
|
||||
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event);
|
||||
|
||||
static int
|
||||
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event);
|
||||
|
||||
static int
|
||||
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event);
|
||||
|
||||
static int
|
||||
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event);
|
||||
|
||||
/*
|
||||
* Load the next document of the stream.
|
||||
*/
|
||||
|
||||
YAML_DECLARE(int)
|
||||
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
|
||||
{
|
||||
yaml_event_t event;
|
||||
|
||||
assert(parser); /* Non-NULL parser object is expected. */
|
||||
assert(document); /* Non-NULL document object is expected. */
|
||||
|
||||
memset(document, 0, sizeof(yaml_document_t));
|
||||
if (!STACK_INIT(parser, document->nodes, INITIAL_STACK_SIZE))
|
||||
goto error;
|
||||
|
||||
if (!parser->stream_start_produced) {
|
||||
if (!yaml_parser_parse(parser, &event)) goto error;
|
||||
assert(event.type == YAML_STREAM_START_EVENT);
|
||||
/* STREAM-START is expected. */
|
||||
}
|
||||
|
||||
if (parser->stream_end_produced) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!yaml_parser_parse(parser, &event)) goto error;
|
||||
if (event.type == YAML_STREAM_END_EVENT) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!STACK_INIT(parser, parser->aliases, INITIAL_STACK_SIZE))
|
||||
goto error;
|
||||
|
||||
parser->document = document;
|
||||
|
||||
if (!yaml_parser_load_document(parser, &event)) goto error;
|
||||
|
||||
yaml_parser_delete_aliases(parser);
|
||||
parser->document = NULL;
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
|
||||
yaml_parser_delete_aliases(parser);
|
||||
yaml_document_delete(document);
|
||||
parser->document = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set composer error.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_set_composer_error(yaml_parser_t *parser,
|
||||
const char *problem, yaml_mark_t problem_mark)
|
||||
{
|
||||
parser->error = YAML_COMPOSER_ERROR;
|
||||
parser->problem = problem;
|
||||
parser->problem_mark = problem_mark;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set composer error with context.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_set_composer_error_context(yaml_parser_t *parser,
|
||||
const char *context, yaml_mark_t context_mark,
|
||||
const char *problem, yaml_mark_t problem_mark)
|
||||
{
|
||||
parser->error = YAML_COMPOSER_ERROR;
|
||||
parser->context = context;
|
||||
parser->context_mark = context_mark;
|
||||
parser->problem = problem;
|
||||
parser->problem_mark = problem_mark;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete the stack of aliases.
|
||||
*/
|
||||
|
||||
static void
|
||||
yaml_parser_delete_aliases(yaml_parser_t *parser)
|
||||
{
|
||||
while (!STACK_EMPTY(parser, parser->aliases)) {
|
||||
yaml_free(POP(parser, parser->aliases).anchor);
|
||||
}
|
||||
STACK_DEL(parser, parser->aliases);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compose a document object.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event)
|
||||
{
|
||||
yaml_event_t event;
|
||||
|
||||
assert(first_event->type == YAML_DOCUMENT_START_EVENT);
|
||||
/* DOCUMENT-START is expected. */
|
||||
|
||||
parser->document->version_directive
|
||||
= first_event->data.document_start.version_directive;
|
||||
parser->document->tag_directives.start
|
||||
= first_event->data.document_start.tag_directives.start;
|
||||
parser->document->tag_directives.end
|
||||
= first_event->data.document_start.tag_directives.end;
|
||||
parser->document->start_implicit
|
||||
= first_event->data.document_start.implicit;
|
||||
parser->document->start_mark = first_event->start_mark;
|
||||
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
|
||||
if (!yaml_parser_load_node(parser, &event)) return 0;
|
||||
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
assert(event.type == YAML_DOCUMENT_END_EVENT);
|
||||
/* DOCUMENT-END is expected. */
|
||||
|
||||
parser->document->end_implicit = event.data.document_end.implicit;
|
||||
parser->document->end_mark = event.end_mark;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compose a node.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event)
|
||||
{
|
||||
switch (first_event->type) {
|
||||
case YAML_ALIAS_EVENT:
|
||||
return yaml_parser_load_alias(parser, first_event);
|
||||
case YAML_SCALAR_EVENT:
|
||||
return yaml_parser_load_scalar(parser, first_event);
|
||||
case YAML_SEQUENCE_START_EVENT:
|
||||
return yaml_parser_load_sequence(parser, first_event);
|
||||
case YAML_MAPPING_START_EVENT:
|
||||
return yaml_parser_load_mapping(parser, first_event);
|
||||
default:
|
||||
assert(0); /* Could not happen. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an anchor.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_register_anchor(yaml_parser_t *parser,
|
||||
int index, yaml_char_t *anchor)
|
||||
{
|
||||
yaml_alias_data_t data;
|
||||
yaml_alias_data_t *alias_data;
|
||||
|
||||
if (!anchor) return 1;
|
||||
|
||||
data.anchor = anchor;
|
||||
data.index = index;
|
||||
data.mark = parser->document->nodes.start[index-1].start_mark;
|
||||
|
||||
for (alias_data = parser->aliases.start;
|
||||
alias_data != parser->aliases.top; alias_data ++) {
|
||||
if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
|
||||
yaml_free(anchor);
|
||||
return yaml_parser_set_composer_error_context(parser,
|
||||
"found duplicate anchor; first occurence",
|
||||
alias_data->mark, "second occurence", data.mark);
|
||||
}
|
||||
}
|
||||
|
||||
if (!PUSH(parser, parser->aliases, data)) {
|
||||
yaml_free(anchor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compose a node corresponding to an alias.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
|
||||
{
|
||||
yaml_char_t *anchor = first_event->data.alias.anchor;
|
||||
yaml_alias_data_t *alias_data;
|
||||
|
||||
for (alias_data = parser->aliases.start;
|
||||
alias_data != parser->aliases.top; alias_data ++) {
|
||||
if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
|
||||
yaml_free(anchor);
|
||||
return alias_data->index;
|
||||
}
|
||||
}
|
||||
|
||||
yaml_free(anchor);
|
||||
return yaml_parser_set_composer_error(parser, "found undefined alias",
|
||||
first_event->start_mark);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compose a scalar node.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
|
||||
{
|
||||
yaml_node_t node;
|
||||
int index;
|
||||
yaml_char_t *tag = first_event->data.scalar.tag;
|
||||
|
||||
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
|
||||
|
||||
if (!tag || strcmp((char *)tag, "!") == 0) {
|
||||
yaml_free(tag);
|
||||
tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SCALAR_TAG);
|
||||
if (!tag) goto error;
|
||||
}
|
||||
|
||||
SCALAR_NODE_INIT(node, tag, first_event->data.scalar.value,
|
||||
first_event->data.scalar.length, first_event->data.scalar.style,
|
||||
first_event->start_mark, first_event->end_mark);
|
||||
|
||||
if (!PUSH(parser, parser->document->nodes, node)) goto error;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
||||
index = parser->document->nodes.top - parser->document->nodes.start;
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (!yaml_parser_register_anchor(parser, index,
|
||||
first_event->data.scalar.anchor)) return 0;
|
||||
|
||||
return index;
|
||||
|
||||
error:
|
||||
yaml_free(tag);
|
||||
yaml_free(first_event->data.scalar.anchor);
|
||||
yaml_free(first_event->data.scalar.value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compose a sequence node.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_node_t node;
|
||||
struct {
|
||||
yaml_node_item_t *start;
|
||||
yaml_node_item_t *end;
|
||||
yaml_node_item_t *top;
|
||||
} items = { NULL, NULL, NULL };
|
||||
int index, item_index;
|
||||
yaml_char_t *tag = first_event->data.sequence_start.tag;
|
||||
|
||||
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
|
||||
|
||||
if (!tag || strcmp((char *)tag, "!") == 0) {
|
||||
yaml_free(tag);
|
||||
tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG);
|
||||
if (!tag) goto error;
|
||||
}
|
||||
|
||||
if (!STACK_INIT(parser, items, INITIAL_STACK_SIZE)) goto error;
|
||||
|
||||
SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
|
||||
first_event->data.sequence_start.style,
|
||||
first_event->start_mark, first_event->end_mark);
|
||||
|
||||
if (!PUSH(parser, parser->document->nodes, node)) goto error;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
||||
index = parser->document->nodes.top - parser->document->nodes.start;
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (!yaml_parser_register_anchor(parser, index,
|
||||
first_event->data.sequence_start.anchor)) return 0;
|
||||
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
|
||||
while (event.type != YAML_SEQUENCE_END_EVENT) {
|
||||
if (!STACK_LIMIT(parser,
|
||||
parser->document->nodes.start[index-1].data.sequence.items,
|
||||
INT_MAX-1)) return 0;
|
||||
item_index = yaml_parser_load_node(parser, &event);
|
||||
if (!item_index) return 0;
|
||||
if (!PUSH(parser,
|
||||
parser->document->nodes.start[index-1].data.sequence.items,
|
||||
item_index)) return 0;
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
}
|
||||
|
||||
parser->document->nodes.start[index-1].end_mark = event.end_mark;
|
||||
|
||||
return index;
|
||||
|
||||
error:
|
||||
yaml_free(tag);
|
||||
yaml_free(first_event->data.sequence_start.anchor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compose a mapping node.
|
||||
*/
|
||||
|
||||
static int
|
||||
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
|
||||
{
|
||||
yaml_event_t event;
|
||||
yaml_node_t node;
|
||||
struct {
|
||||
yaml_node_pair_t *start;
|
||||
yaml_node_pair_t *end;
|
||||
yaml_node_pair_t *top;
|
||||
} pairs = { NULL, NULL, NULL };
|
||||
int index;
|
||||
yaml_node_pair_t pair;
|
||||
yaml_char_t *tag = first_event->data.mapping_start.tag;
|
||||
|
||||
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
|
||||
|
||||
if (!tag || strcmp((char *)tag, "!") == 0) {
|
||||
yaml_free(tag);
|
||||
tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG);
|
||||
if (!tag) goto error;
|
||||
}
|
||||
|
||||
if (!STACK_INIT(parser, pairs, INITIAL_STACK_SIZE)) goto error;
|
||||
|
||||
MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
|
||||
first_event->data.mapping_start.style,
|
||||
first_event->start_mark, first_event->end_mark);
|
||||
|
||||
if (!PUSH(parser, parser->document->nodes, node)) goto error;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
||||
index = parser->document->nodes.top - parser->document->nodes.start;
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (!yaml_parser_register_anchor(parser, index,
|
||||
first_event->data.mapping_start.anchor)) return 0;
|
||||
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
|
||||
while (event.type != YAML_MAPPING_END_EVENT) {
|
||||
if (!STACK_LIMIT(parser,
|
||||
parser->document->nodes.start[index-1].data.mapping.pairs,
|
||||
INT_MAX-1)) return 0;
|
||||
pair.key = yaml_parser_load_node(parser, &event);
|
||||
if (!pair.key) return 0;
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
pair.value = yaml_parser_load_node(parser, &event);
|
||||
if (!pair.value) return 0;
|
||||
if (!PUSH(parser,
|
||||
parser->document->nodes.start[index-1].data.mapping.pairs,
|
||||
pair)) return 0;
|
||||
if (!yaml_parser_parse(parser, &event)) return 0;
|
||||
}
|
||||
|
||||
parser->document->nodes.start[index-1].end_mark = event.end_mark;
|
||||
|
||||
return index;
|
||||
|
||||
error:
|
||||
yaml_free(tag);
|
||||
yaml_free(first_event->data.mapping_start.anchor);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -31,9 +31,7 @@
|
|||
6CF0253A1E9D12680061FB47 /* MarkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF025391E9D12680061FB47 /* MarkTests.swift */; };
|
||||
6CF6CE091E0E3B1000CB87D4 /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF6CE081E0E3B1000CB87D4 /* PerformanceTests.swift */; };
|
||||
E8EDB8851DE2181B0062268D /* api.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_10 /* api.c */; };
|
||||
E8EDB8861DE2181B0062268D /* dumper.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* dumper.c */; };
|
||||
E8EDB8871DE2181B0062268D /* emitter.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_12 /* emitter.c */; };
|
||||
E8EDB8881DE2181B0062268D /* loader.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_13 /* loader.c */; };
|
||||
E8EDB8891DE2181B0062268D /* parser.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* parser.c */; };
|
||||
E8EDB88A1DE2181B0062268D /* reader.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_15 /* reader.c */; };
|
||||
E8EDB88B1DE2181B0062268D /* scanner.c in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_16 /* scanner.c */; };
|
||||
|
@ -81,9 +79,7 @@
|
|||
6CF6CE071E0E3A5900CB87D4 /* Fixtures */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Fixtures; sourceTree = "<group>"; };
|
||||
6CF6CE081E0E3B1000CB87D4 /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = "<group>"; };
|
||||
OBJ_10 /* api.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = api.c; sourceTree = "<group>"; };
|
||||
OBJ_11 /* dumper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = dumper.c; sourceTree = "<group>"; };
|
||||
OBJ_12 /* emitter.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = emitter.c; sourceTree = "<group>"; };
|
||||
OBJ_13 /* loader.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = loader.c; sourceTree = "<group>"; };
|
||||
OBJ_14 /* parser.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = parser.c; sourceTree = "<group>"; };
|
||||
OBJ_15 /* reader.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = reader.c; sourceTree = "<group>"; };
|
||||
OBJ_16 /* scanner.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = scanner.c; sourceTree = "<group>"; };
|
||||
|
@ -216,9 +212,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
OBJ_10 /* api.c */,
|
||||
OBJ_11 /* dumper.c */,
|
||||
OBJ_12 /* emitter.c */,
|
||||
OBJ_13 /* loader.c */,
|
||||
OBJ_14 /* parser.c */,
|
||||
OBJ_15 /* reader.c */,
|
||||
OBJ_16 /* scanner.c */,
|
||||
|
@ -337,14 +331,12 @@
|
|||
E8EDB8851DE2181B0062268D /* api.c in Sources */,
|
||||
6CC2E33F1E22347B00F62269 /* Representer.swift in Sources */,
|
||||
6CE603981E13502E00A13D8D /* Emitter.swift in Sources */,
|
||||
E8EDB8861DE2181B0062268D /* dumper.c in Sources */,
|
||||
6C6834CC1E0283980047B4D1 /* Parser.swift in Sources */,
|
||||
6C6834C81E0281880047B4D1 /* Node.swift in Sources */,
|
||||
6C0D2A361E0A934B00C45545 /* Constructor.swift in Sources */,
|
||||
6C6834D31E02B9760047B4D1 /* Resolver.swift in Sources */,
|
||||
6C0409AA1E6033DF00C95D83 /* Node.Sequence.swift in Sources */,
|
||||
6C0409A81E602E9A00C95D83 /* Node.Mapping.swift in Sources */,
|
||||
E8EDB8881DE2181B0062268D /* loader.c in Sources */,
|
||||
E8EDB88C1DE2181B0062268D /* writer.c in Sources */,
|
||||
E8EDB88B1DE2181B0062268D /* scanner.c in Sources */,
|
||||
6C0409AC1E607E9900C95D83 /* Node.Scalar.swift in Sources */,
|
||||
|
|
Loading…
Reference in New Issue