psych 3.0.3.pre1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +1 -4
- data/Rakefile +4 -16
- data/ext/psych/depend +2 -0
- data/ext/psych/extconf.rb +6 -2
- data/ext/psych/psych.c +3 -3
- data/ext/psych/psych_parser.c +20 -33
- data/ext/psych/psych_yaml_tree.c +0 -12
- data/ext/psych/yaml/api.c +48 -47
- data/ext/psych/yaml/config.h +77 -7
- data/ext/psych/yaml/dumper.c +3 -3
- data/ext/psych/yaml/emitter.c +48 -19
- data/ext/psych/yaml/loader.c +210 -110
- data/ext/psych/yaml/parser.c +11 -6
- data/ext/psych/yaml/reader.c +3 -3
- data/ext/psych/yaml/scanner.c +52 -28
- data/ext/psych/yaml/yaml.h +44 -30
- data/ext/psych/yaml/yaml_private.h +46 -20
- data/lib/psych.rb +122 -60
- data/lib/psych/handler.rb +1 -1
- data/lib/psych/nodes/node.rb +2 -2
- data/lib/psych/scalar_scanner.rb +23 -36
- data/lib/psych/versions.rb +4 -3
- data/lib/psych/visitors/to_ruby.rb +42 -11
- data/lib/psych/visitors/yaml_tree.rb +29 -41
- data/psych.gemspec +18 -13
- metadata +10 -55
- data/.travis.yml +0 -20
- data/CHANGELOG.rdoc +0 -576
data/ext/psych/yaml/config.h
CHANGED
@@ -1,10 +1,80 @@
|
|
1
|
+
/* include/config.h. Generated from config.h.in by configure. */
|
2
|
+
/* include/config.h.in. Generated from configure.ac by autoheader. */
|
3
|
+
|
4
|
+
/* Define to 1 if you have the <dlfcn.h> header file. */
|
5
|
+
#define HAVE_DLFCN_H 1
|
6
|
+
|
7
|
+
/* Define to 1 if you have the <inttypes.h> header file. */
|
8
|
+
#define HAVE_INTTYPES_H 1
|
9
|
+
|
10
|
+
/* Define to 1 if you have the <memory.h> header file. */
|
11
|
+
#define HAVE_MEMORY_H 1
|
12
|
+
|
13
|
+
/* Define to 1 if you have the <stdint.h> header file. */
|
14
|
+
#define HAVE_STDINT_H 1
|
15
|
+
|
16
|
+
/* Define to 1 if you have the <stdlib.h> header file. */
|
17
|
+
#define HAVE_STDLIB_H 1
|
18
|
+
|
19
|
+
/* Define to 1 if you have the <strings.h> header file. */
|
20
|
+
#define HAVE_STRINGS_H 1
|
21
|
+
|
22
|
+
/* Define to 1 if you have the <string.h> header file. */
|
23
|
+
#define HAVE_STRING_H 1
|
24
|
+
|
25
|
+
/* Define to 1 if you have the <sys/stat.h> header file. */
|
26
|
+
#define HAVE_SYS_STAT_H 1
|
27
|
+
|
28
|
+
/* Define to 1 if you have the <sys/types.h> header file. */
|
29
|
+
#define HAVE_SYS_TYPES_H 1
|
30
|
+
|
31
|
+
/* Define to 1 if you have the <unistd.h> header file. */
|
32
|
+
#define HAVE_UNISTD_H 1
|
33
|
+
|
34
|
+
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
35
|
+
#define LT_OBJDIR ".libs/"
|
36
|
+
|
37
|
+
/* Name of package */
|
38
|
+
#define PACKAGE "yaml"
|
39
|
+
|
40
|
+
/* Define to the address where bug reports for this package should be sent. */
|
41
|
+
#define PACKAGE_BUGREPORT "https://github.com/yaml/libyaml/issues/new"
|
42
|
+
|
43
|
+
/* Define to the full name of this package. */
|
1
44
|
#define PACKAGE_NAME "yaml"
|
45
|
+
|
46
|
+
/* Define to the full name and version of this package. */
|
47
|
+
#define PACKAGE_STRING "yaml 0.2.5"
|
48
|
+
|
49
|
+
/* Define to the one symbol short name of this package. */
|
2
50
|
#define PACKAGE_TARNAME "yaml"
|
3
|
-
|
4
|
-
|
5
|
-
#define
|
6
|
-
|
51
|
+
|
52
|
+
/* Define to the home page for this package. */
|
53
|
+
#define PACKAGE_URL ""
|
54
|
+
|
55
|
+
/* Define to the version of this package. */
|
56
|
+
#define PACKAGE_VERSION "0.2.5"
|
57
|
+
|
58
|
+
/* Define to 1 if you have the ANSI C header files. */
|
59
|
+
#define STDC_HEADERS 1
|
60
|
+
|
61
|
+
/* Version number of package */
|
62
|
+
#define VERSION "0.2.5"
|
63
|
+
|
64
|
+
/* Define the major version number. */
|
7
65
|
#define YAML_VERSION_MAJOR 0
|
8
|
-
|
9
|
-
|
10
|
-
#define
|
66
|
+
|
67
|
+
/* Define the minor version number. */
|
68
|
+
#define YAML_VERSION_MINOR 2
|
69
|
+
|
70
|
+
/* Define the patch version number. */
|
71
|
+
#define YAML_VERSION_PATCH 5
|
72
|
+
|
73
|
+
/* Define the version string. */
|
74
|
+
#define YAML_VERSION_STRING "0.2.5"
|
75
|
+
|
76
|
+
/* Define to empty if `const' does not conform to ANSI C. */
|
77
|
+
/* #undef const */
|
78
|
+
|
79
|
+
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
80
|
+
/* #undef size_t */
|
data/ext/psych/yaml/dumper.c
CHANGED
@@ -131,7 +131,7 @@ yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)
|
|
131
131
|
|
132
132
|
assert(emitter->opened); /* Emitter should be opened. */
|
133
133
|
|
134
|
-
emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
|
134
|
+
emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors))
|
135
135
|
* (document->nodes.top - document->nodes.start));
|
136
136
|
if (!emitter->anchors) goto error;
|
137
137
|
memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
|
@@ -245,9 +245,9 @@ yaml_emitter_anchor_node(yaml_emitter_t *emitter, int index)
|
|
245
245
|
#define ANCHOR_TEMPLATE_LENGTH 16
|
246
246
|
|
247
247
|
static yaml_char_t *
|
248
|
-
yaml_emitter_generate_anchor(yaml_emitter_t *emitter, int anchor_id)
|
248
|
+
yaml_emitter_generate_anchor(SHIM(yaml_emitter_t *emitter), int anchor_id)
|
249
249
|
{
|
250
|
-
yaml_char_t *anchor =
|
250
|
+
yaml_char_t *anchor = YAML_MALLOC(ANCHOR_TEMPLATE_LENGTH);
|
251
251
|
|
252
252
|
if (!anchor) return NULL;
|
253
253
|
|
data/ext/psych/yaml/emitter.c
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
#define PUT(emitter,value) \
|
17
17
|
(FLUSH(emitter) \
|
18
18
|
&& (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \
|
19
|
-
emitter->column
|
19
|
+
emitter->column++, \
|
20
20
|
1))
|
21
21
|
|
22
22
|
/*
|
@@ -24,7 +24,7 @@
|
|
24
24
|
*/
|
25
25
|
|
26
26
|
#define PUT_BREAK(emitter) \
|
27
|
-
(FLUSH(emitter) ?
|
27
|
+
(FLUSH(emitter) ? \
|
28
28
|
((emitter->line_break == YAML_CR_BREAK ? \
|
29
29
|
(*(emitter->buffer.pointer++) = (yaml_char_t) '\r') : \
|
30
30
|
emitter->line_break == YAML_LN_BREAK ? \
|
@@ -495,6 +495,7 @@ static int
|
|
495
495
|
yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
|
496
496
|
yaml_event_t *event)
|
497
497
|
{
|
498
|
+
emitter->open_ended = 0;
|
498
499
|
if (event->type == YAML_STREAM_START_EVENT)
|
499
500
|
{
|
500
501
|
if (!emitter->encoding) {
|
@@ -597,13 +598,20 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
|
|
597
598
|
if (!yaml_emitter_write_indent(emitter))
|
598
599
|
return 0;
|
599
600
|
}
|
601
|
+
emitter->open_ended = 0;
|
600
602
|
|
601
603
|
if (event->data.document_start.version_directive) {
|
602
604
|
implicit = 0;
|
603
605
|
if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0))
|
604
606
|
return 0;
|
605
|
-
if (
|
606
|
-
|
607
|
+
if (event->data.document_start.version_directive->minor == 1) {
|
608
|
+
if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
|
609
|
+
return 0;
|
610
|
+
}
|
611
|
+
else {
|
612
|
+
if (!yaml_emitter_write_indicator(emitter, "1.2", 1, 0, 0))
|
613
|
+
return 0;
|
614
|
+
}
|
607
615
|
if (!yaml_emitter_write_indent(emitter))
|
608
616
|
return 0;
|
609
617
|
}
|
@@ -644,19 +652,25 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
|
|
644
652
|
|
645
653
|
emitter->state = YAML_EMIT_DOCUMENT_CONTENT_STATE;
|
646
654
|
|
655
|
+
emitter->open_ended = 0;
|
647
656
|
return 1;
|
648
657
|
}
|
649
658
|
|
650
659
|
else if (event->type == YAML_STREAM_END_EVENT)
|
651
660
|
{
|
652
|
-
|
661
|
+
|
662
|
+
/**
|
663
|
+
* This can happen if a block scalar with trailing empty lines
|
664
|
+
* is at the end of the stream
|
665
|
+
*/
|
666
|
+
if (emitter->open_ended == 2)
|
653
667
|
{
|
654
668
|
if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
|
655
669
|
return 0;
|
670
|
+
emitter->open_ended = 0;
|
656
671
|
if (!yaml_emitter_write_indent(emitter))
|
657
672
|
return 0;
|
658
673
|
}
|
659
|
-
|
660
674
|
if (!yaml_emitter_flush(emitter))
|
661
675
|
return 0;
|
662
676
|
|
@@ -698,9 +712,12 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter,
|
|
698
712
|
if (!event->data.document_end.implicit) {
|
699
713
|
if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
|
700
714
|
return 0;
|
715
|
+
emitter->open_ended = 0;
|
701
716
|
if (!yaml_emitter_write_indent(emitter))
|
702
717
|
return 0;
|
703
718
|
}
|
719
|
+
else if (!emitter->open_ended)
|
720
|
+
emitter->open_ended = 1;
|
704
721
|
if (!yaml_emitter_flush(emitter))
|
705
722
|
return 0;
|
706
723
|
|
@@ -1002,10 +1019,12 @@ yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event,
|
|
1002
1019
|
*/
|
1003
1020
|
|
1004
1021
|
static int
|
1005
|
-
yaml_emitter_emit_alias(yaml_emitter_t *emitter, yaml_event_t *event)
|
1022
|
+
yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event))
|
1006
1023
|
{
|
1007
1024
|
if (!yaml_emitter_process_anchor(emitter))
|
1008
1025
|
return 0;
|
1026
|
+
if (emitter->simple_key_context)
|
1027
|
+
if (!PUT(emitter, ' ')) return 0;
|
1009
1028
|
emitter->state = POP(emitter, emitter->states);
|
1010
1029
|
|
1011
1030
|
return 1;
|
@@ -1087,7 +1106,7 @@ yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter, yaml_event_t *event)
|
|
1087
1106
|
*/
|
1088
1107
|
|
1089
1108
|
static int
|
1090
|
-
yaml_emitter_check_empty_document(yaml_emitter_t *emitter)
|
1109
|
+
yaml_emitter_check_empty_document(SHIM(yaml_emitter_t *emitter))
|
1091
1110
|
{
|
1092
1111
|
return 0;
|
1093
1112
|
}
|
@@ -1234,7 +1253,7 @@ yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event)
|
|
1234
1253
|
}
|
1235
1254
|
|
1236
1255
|
/*
|
1237
|
-
* Write an
|
1256
|
+
* Write an anchor.
|
1238
1257
|
*/
|
1239
1258
|
|
1240
1259
|
static int
|
@@ -1333,7 +1352,10 @@ static int
|
|
1333
1352
|
yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter,
|
1334
1353
|
yaml_version_directive_t version_directive)
|
1335
1354
|
{
|
1336
|
-
if (version_directive.major != 1 ||
|
1355
|
+
if (version_directive.major != 1 || (
|
1356
|
+
version_directive.minor != 1
|
1357
|
+
&& version_directive.minor != 2
|
1358
|
+
)) {
|
1337
1359
|
return yaml_emitter_set_emitter_error(emitter,
|
1338
1360
|
"incompatible %YAML directive");
|
1339
1361
|
}
|
@@ -1803,7 +1825,6 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter,
|
|
1803
1825
|
|
1804
1826
|
emitter->whitespace = is_whitespace;
|
1805
1827
|
emitter->indention = (emitter->indention && is_indention);
|
1806
|
-
emitter->open_ended = 0;
|
1807
1828
|
|
1808
1829
|
return 1;
|
1809
1830
|
}
|
@@ -1904,7 +1925,17 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
|
|
1904
1925
|
|
1905
1926
|
STRING_ASSIGN(string, value, length);
|
1906
1927
|
|
1907
|
-
|
1928
|
+
/**
|
1929
|
+
* Avoid trailing spaces for empty values in block mode.
|
1930
|
+
* In flow mode, we still want the space to prevent ambiguous things
|
1931
|
+
* like {a:}.
|
1932
|
+
* Currently, the emitter forbids any plain empty scalar in flow mode
|
1933
|
+
* (e.g. it outputs {a: ''} instead), so emitter->flow_level will
|
1934
|
+
* never be true here.
|
1935
|
+
* But if the emitter is ever changed to allow emitting empty values,
|
1936
|
+
* the check for flow_level is already here.
|
1937
|
+
*/
|
1938
|
+
if (!emitter->whitespace && (length || emitter->flow_level)) {
|
1908
1939
|
if (!PUT(emitter, ' ')) return 0;
|
1909
1940
|
}
|
1910
1941
|
|
@@ -1946,10 +1977,6 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
|
|
1946
1977
|
|
1947
1978
|
emitter->whitespace = 0;
|
1948
1979
|
emitter->indention = 0;
|
1949
|
-
if (emitter->root_context)
|
1950
|
-
{
|
1951
|
-
emitter->open_ended = 1;
|
1952
|
-
}
|
1953
1980
|
|
1954
1981
|
return 1;
|
1955
1982
|
}
|
@@ -2008,6 +2035,9 @@ yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter,
|
|
2008
2035
|
}
|
2009
2036
|
}
|
2010
2037
|
|
2038
|
+
if (breaks)
|
2039
|
+
if (!yaml_emitter_write_indent(emitter)) return 0;
|
2040
|
+
|
2011
2041
|
if (!yaml_emitter_write_indicator(emitter, "'", 0, 0, 0))
|
2012
2042
|
return 0;
|
2013
2043
|
|
@@ -2207,7 +2237,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
|
|
2207
2237
|
else if (string.start == string.pointer)
|
2208
2238
|
{
|
2209
2239
|
chomp_hint = "+";
|
2210
|
-
emitter->open_ended =
|
2240
|
+
emitter->open_ended = 2;
|
2211
2241
|
}
|
2212
2242
|
else
|
2213
2243
|
{
|
@@ -2217,7 +2247,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
|
|
2217
2247
|
if (IS_BREAK(string))
|
2218
2248
|
{
|
2219
2249
|
chomp_hint = "+";
|
2220
|
-
emitter->open_ended =
|
2250
|
+
emitter->open_ended = 2;
|
2221
2251
|
}
|
2222
2252
|
}
|
2223
2253
|
}
|
@@ -2326,4 +2356,3 @@ yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter,
|
|
2326
2356
|
|
2327
2357
|
return 1;
|
2328
2358
|
}
|
2329
|
-
|
data/ext/psych/yaml/loader.c
CHANGED
@@ -37,27 +37,47 @@ yaml_parser_register_anchor(yaml_parser_t *parser,
|
|
37
37
|
static void
|
38
38
|
yaml_parser_delete_aliases(yaml_parser_t *parser);
|
39
39
|
|
40
|
+
/*
|
41
|
+
* Document loading context.
|
42
|
+
*/
|
43
|
+
struct loader_ctx {
|
44
|
+
int *start;
|
45
|
+
int *end;
|
46
|
+
int *top;
|
47
|
+
};
|
48
|
+
|
40
49
|
/*
|
41
50
|
* Composer functions.
|
42
51
|
*/
|
52
|
+
static int
|
53
|
+
yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx);
|
54
|
+
|
55
|
+
static int
|
56
|
+
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event);
|
43
57
|
|
44
58
|
static int
|
45
|
-
|
59
|
+
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
|
60
|
+
struct loader_ctx *ctx);
|
46
61
|
|
47
62
|
static int
|
48
|
-
|
63
|
+
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
|
64
|
+
struct loader_ctx *ctx);
|
49
65
|
|
50
66
|
static int
|
51
|
-
|
67
|
+
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
|
68
|
+
struct loader_ctx *ctx);
|
52
69
|
|
53
70
|
static int
|
54
|
-
|
71
|
+
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
|
72
|
+
struct loader_ctx *ctx);
|
55
73
|
|
56
74
|
static int
|
57
|
-
|
75
|
+
yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event,
|
76
|
+
struct loader_ctx *ctx);
|
58
77
|
|
59
78
|
static int
|
60
|
-
|
79
|
+
yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
|
80
|
+
struct loader_ctx *ctx);
|
61
81
|
|
62
82
|
/*
|
63
83
|
* Load the next document of the stream.
|
@@ -72,7 +92,7 @@ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
|
|
72
92
|
assert(document); /* Non-NULL document object is expected. */
|
73
93
|
|
74
94
|
memset(document, 0, sizeof(yaml_document_t));
|
75
|
-
if (!STACK_INIT(parser, document->nodes,
|
95
|
+
if (!STACK_INIT(parser, document->nodes, yaml_node_t*))
|
76
96
|
goto error;
|
77
97
|
|
78
98
|
if (!parser->stream_start_produced) {
|
@@ -90,7 +110,7 @@ yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document)
|
|
90
110
|
return 1;
|
91
111
|
}
|
92
112
|
|
93
|
-
if (!STACK_INIT(parser, parser->aliases,
|
113
|
+
if (!STACK_INIT(parser, parser->aliases, yaml_alias_data_t*))
|
94
114
|
goto error;
|
95
115
|
|
96
116
|
parser->document = document;
|
@@ -162,59 +182,78 @@ yaml_parser_delete_aliases(yaml_parser_t *parser)
|
|
162
182
|
*/
|
163
183
|
|
164
184
|
static int
|
165
|
-
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *
|
185
|
+
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event)
|
166
186
|
{
|
167
|
-
|
187
|
+
struct loader_ctx ctx = { NULL, NULL, NULL };
|
168
188
|
|
169
|
-
assert(
|
189
|
+
assert(event->type == YAML_DOCUMENT_START_EVENT);
|
170
190
|
/* DOCUMENT-START is expected. */
|
171
191
|
|
172
192
|
parser->document->version_directive
|
173
|
-
=
|
193
|
+
= event->data.document_start.version_directive;
|
174
194
|
parser->document->tag_directives.start
|
175
|
-
=
|
195
|
+
= event->data.document_start.tag_directives.start;
|
176
196
|
parser->document->tag_directives.end
|
177
|
-
=
|
197
|
+
= event->data.document_start.tag_directives.end;
|
178
198
|
parser->document->start_implicit
|
179
|
-
=
|
180
|
-
parser->document->start_mark =
|
181
|
-
|
182
|
-
if (!yaml_parser_parse(parser, &event)) return 0;
|
183
|
-
|
184
|
-
if (!yaml_parser_load_node(parser, &event)) return 0;
|
185
|
-
|
186
|
-
if (!yaml_parser_parse(parser, &event)) return 0;
|
187
|
-
assert(event.type == YAML_DOCUMENT_END_EVENT);
|
188
|
-
/* DOCUMENT-END is expected. */
|
199
|
+
= event->data.document_start.implicit;
|
200
|
+
parser->document->start_mark = event->start_mark;
|
189
201
|
|
190
|
-
parser
|
191
|
-
parser
|
202
|
+
if (!STACK_INIT(parser, ctx, int*)) return 0;
|
203
|
+
if (!yaml_parser_load_nodes(parser, &ctx)) {
|
204
|
+
STACK_DEL(parser, ctx);
|
205
|
+
return 0;
|
206
|
+
}
|
207
|
+
STACK_DEL(parser, ctx);
|
192
208
|
|
193
209
|
return 1;
|
194
210
|
}
|
195
211
|
|
196
212
|
/*
|
197
|
-
* Compose a node.
|
213
|
+
* Compose a node tree.
|
198
214
|
*/
|
199
215
|
|
200
216
|
static int
|
201
|
-
|
217
|
+
yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx)
|
202
218
|
{
|
203
|
-
|
204
|
-
case YAML_ALIAS_EVENT:
|
205
|
-
return yaml_parser_load_alias(parser, first_event);
|
206
|
-
case YAML_SCALAR_EVENT:
|
207
|
-
return yaml_parser_load_scalar(parser, first_event);
|
208
|
-
case YAML_SEQUENCE_START_EVENT:
|
209
|
-
return yaml_parser_load_sequence(parser, first_event);
|
210
|
-
case YAML_MAPPING_START_EVENT:
|
211
|
-
return yaml_parser_load_mapping(parser, first_event);
|
212
|
-
default:
|
213
|
-
assert(0); /* Could not happen. */
|
214
|
-
return 0;
|
215
|
-
}
|
219
|
+
yaml_event_t event;
|
216
220
|
|
217
|
-
|
221
|
+
do {
|
222
|
+
if (!yaml_parser_parse(parser, &event)) return 0;
|
223
|
+
|
224
|
+
switch (event.type) {
|
225
|
+
case YAML_ALIAS_EVENT:
|
226
|
+
if (!yaml_parser_load_alias(parser, &event, ctx)) return 0;
|
227
|
+
break;
|
228
|
+
case YAML_SCALAR_EVENT:
|
229
|
+
if (!yaml_parser_load_scalar(parser, &event, ctx)) return 0;
|
230
|
+
break;
|
231
|
+
case YAML_SEQUENCE_START_EVENT:
|
232
|
+
if (!yaml_parser_load_sequence(parser, &event, ctx)) return 0;
|
233
|
+
break;
|
234
|
+
case YAML_SEQUENCE_END_EVENT:
|
235
|
+
if (!yaml_parser_load_sequence_end(parser, &event, ctx))
|
236
|
+
return 0;
|
237
|
+
break;
|
238
|
+
case YAML_MAPPING_START_EVENT:
|
239
|
+
if (!yaml_parser_load_mapping(parser, &event, ctx)) return 0;
|
240
|
+
break;
|
241
|
+
case YAML_MAPPING_END_EVENT:
|
242
|
+
if (!yaml_parser_load_mapping_end(parser, &event, ctx))
|
243
|
+
return 0;
|
244
|
+
break;
|
245
|
+
default:
|
246
|
+
assert(0); /* Could not happen. */
|
247
|
+
return 0;
|
248
|
+
case YAML_DOCUMENT_END_EVENT:
|
249
|
+
break;
|
250
|
+
}
|
251
|
+
} while (event.type != YAML_DOCUMENT_END_EVENT);
|
252
|
+
|
253
|
+
parser->document->end_implicit = event.data.document_end.implicit;
|
254
|
+
parser->document->end_mark = event.end_mark;
|
255
|
+
|
256
|
+
return 1;
|
218
257
|
}
|
219
258
|
|
220
259
|
/*
|
@@ -252,27 +291,80 @@ yaml_parser_register_anchor(yaml_parser_t *parser,
|
|
252
291
|
return 1;
|
253
292
|
}
|
254
293
|
|
294
|
+
/*
|
295
|
+
* Compose node into its parent in the stree.
|
296
|
+
*/
|
297
|
+
|
298
|
+
static int
|
299
|
+
yaml_parser_load_node_add(yaml_parser_t *parser, struct loader_ctx *ctx,
|
300
|
+
int index)
|
301
|
+
{
|
302
|
+
struct yaml_node_s *parent;
|
303
|
+
int parent_index;
|
304
|
+
|
305
|
+
if (STACK_EMPTY(parser, *ctx)) {
|
306
|
+
/* This is the root node, there's no tree to add it to. */
|
307
|
+
return 1;
|
308
|
+
}
|
309
|
+
|
310
|
+
parent_index = *((*ctx).top - 1);
|
311
|
+
parent = &parser->document->nodes.start[parent_index-1];
|
312
|
+
|
313
|
+
switch (parent->type) {
|
314
|
+
case YAML_SEQUENCE_NODE:
|
315
|
+
if (!STACK_LIMIT(parser, parent->data.sequence.items, INT_MAX-1))
|
316
|
+
return 0;
|
317
|
+
if (!PUSH(parser, parent->data.sequence.items, index))
|
318
|
+
return 0;
|
319
|
+
break;
|
320
|
+
case YAML_MAPPING_NODE: {
|
321
|
+
yaml_node_pair_t pair;
|
322
|
+
if (!STACK_EMPTY(parser, parent->data.mapping.pairs)) {
|
323
|
+
yaml_node_pair_t *p = parent->data.mapping.pairs.top - 1;
|
324
|
+
if (p->key != 0 && p->value == 0) {
|
325
|
+
p->value = index;
|
326
|
+
break;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
pair.key = index;
|
331
|
+
pair.value = 0;
|
332
|
+
if (!STACK_LIMIT(parser, parent->data.mapping.pairs, INT_MAX-1))
|
333
|
+
return 0;
|
334
|
+
if (!PUSH(parser, parent->data.mapping.pairs, pair))
|
335
|
+
return 0;
|
336
|
+
|
337
|
+
break;
|
338
|
+
}
|
339
|
+
default:
|
340
|
+
assert(0); /* Could not happen. */
|
341
|
+
return 0;
|
342
|
+
}
|
343
|
+
return 1;
|
344
|
+
}
|
345
|
+
|
255
346
|
/*
|
256
347
|
* Compose a node corresponding to an alias.
|
257
348
|
*/
|
258
349
|
|
259
350
|
static int
|
260
|
-
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *
|
351
|
+
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
|
352
|
+
struct loader_ctx *ctx)
|
261
353
|
{
|
262
|
-
yaml_char_t *anchor =
|
354
|
+
yaml_char_t *anchor = event->data.alias.anchor;
|
263
355
|
yaml_alias_data_t *alias_data;
|
264
356
|
|
265
357
|
for (alias_data = parser->aliases.start;
|
266
358
|
alias_data != parser->aliases.top; alias_data ++) {
|
267
359
|
if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
|
268
360
|
yaml_free(anchor);
|
269
|
-
return alias_data->index;
|
361
|
+
return yaml_parser_load_node_add(parser, ctx, alias_data->index);
|
270
362
|
}
|
271
363
|
}
|
272
364
|
|
273
365
|
yaml_free(anchor);
|
274
366
|
return yaml_parser_set_composer_error(parser, "found undefined alias",
|
275
|
-
|
367
|
+
event->start_mark);
|
276
368
|
}
|
277
369
|
|
278
370
|
/*
|
@@ -280,11 +372,12 @@ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
|
|
280
372
|
*/
|
281
373
|
|
282
374
|
static int
|
283
|
-
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *
|
375
|
+
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
|
376
|
+
struct loader_ctx *ctx)
|
284
377
|
{
|
285
378
|
yaml_node_t node;
|
286
379
|
int index;
|
287
|
-
yaml_char_t *tag =
|
380
|
+
yaml_char_t *tag = event->data.scalar.tag;
|
288
381
|
|
289
382
|
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
|
290
383
|
|
@@ -294,23 +387,23 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
|
|
294
387
|
if (!tag) goto error;
|
295
388
|
}
|
296
389
|
|
297
|
-
SCALAR_NODE_INIT(node, tag,
|
298
|
-
|
299
|
-
|
390
|
+
SCALAR_NODE_INIT(node, tag, event->data.scalar.value,
|
391
|
+
event->data.scalar.length, event->data.scalar.style,
|
392
|
+
event->start_mark, event->end_mark);
|
300
393
|
|
301
394
|
if (!PUSH(parser, parser->document->nodes, node)) goto error;
|
302
395
|
|
303
|
-
index = parser->document->nodes.top - parser->document->nodes.start;
|
396
|
+
index = (int)(parser->document->nodes.top - parser->document->nodes.start);
|
304
397
|
|
305
398
|
if (!yaml_parser_register_anchor(parser, index,
|
306
|
-
|
399
|
+
event->data.scalar.anchor)) return 0;
|
307
400
|
|
308
|
-
return index;
|
401
|
+
return yaml_parser_load_node_add(parser, ctx, index);
|
309
402
|
|
310
403
|
error:
|
311
404
|
yaml_free(tag);
|
312
|
-
yaml_free(
|
313
|
-
yaml_free(
|
405
|
+
yaml_free(event->data.scalar.anchor);
|
406
|
+
yaml_free(event->data.scalar.value);
|
314
407
|
return 0;
|
315
408
|
}
|
316
409
|
|
@@ -319,17 +412,17 @@ error:
|
|
319
412
|
*/
|
320
413
|
|
321
414
|
static int
|
322
|
-
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *
|
415
|
+
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
|
416
|
+
struct loader_ctx *ctx)
|
323
417
|
{
|
324
|
-
yaml_event_t event;
|
325
418
|
yaml_node_t node;
|
326
419
|
struct {
|
327
420
|
yaml_node_item_t *start;
|
328
421
|
yaml_node_item_t *end;
|
329
422
|
yaml_node_item_t *top;
|
330
423
|
} items = { NULL, NULL, NULL };
|
331
|
-
int index
|
332
|
-
yaml_char_t *tag =
|
424
|
+
int index;
|
425
|
+
yaml_char_t *tag = event->data.sequence_start.tag;
|
333
426
|
|
334
427
|
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
|
335
428
|
|
@@ -339,51 +432,57 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
|
|
339
432
|
if (!tag) goto error;
|
340
433
|
}
|
341
434
|
|
342
|
-
if (!STACK_INIT(parser, items,
|
435
|
+
if (!STACK_INIT(parser, items, yaml_node_item_t*)) goto error;
|
343
436
|
|
344
437
|
SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
|
345
|
-
|
346
|
-
|
438
|
+
event->data.sequence_start.style,
|
439
|
+
event->start_mark, event->end_mark);
|
347
440
|
|
348
441
|
if (!PUSH(parser, parser->document->nodes, node)) goto error;
|
349
442
|
|
350
|
-
index = parser->document->nodes.top - parser->document->nodes.start;
|
443
|
+
index = (int)(parser->document->nodes.top - parser->document->nodes.start);
|
351
444
|
|
352
445
|
if (!yaml_parser_register_anchor(parser, index,
|
353
|
-
|
354
|
-
|
355
|
-
if (!
|
356
|
-
|
357
|
-
while (event.type != YAML_SEQUENCE_END_EVENT) {
|
358
|
-
if (!STACK_LIMIT(parser,
|
359
|
-
parser->document->nodes.start[index-1].data.sequence.items,
|
360
|
-
INT_MAX-1)) return 0;
|
361
|
-
item_index = yaml_parser_load_node(parser, &event);
|
362
|
-
if (!item_index) return 0;
|
363
|
-
if (!PUSH(parser,
|
364
|
-
parser->document->nodes.start[index-1].data.sequence.items,
|
365
|
-
item_index)) return 0;
|
366
|
-
if (!yaml_parser_parse(parser, &event)) return 0;
|
367
|
-
}
|
446
|
+
event->data.sequence_start.anchor)) return 0;
|
447
|
+
|
448
|
+
if (!yaml_parser_load_node_add(parser, ctx, index)) return 0;
|
368
449
|
|
369
|
-
parser
|
450
|
+
if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0;
|
451
|
+
if (!PUSH(parser, *ctx, index)) return 0;
|
370
452
|
|
371
|
-
return
|
453
|
+
return 1;
|
372
454
|
|
373
455
|
error:
|
374
456
|
yaml_free(tag);
|
375
|
-
yaml_free(
|
457
|
+
yaml_free(event->data.sequence_start.anchor);
|
376
458
|
return 0;
|
377
459
|
}
|
378
460
|
|
461
|
+
static int
|
462
|
+
yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event,
|
463
|
+
struct loader_ctx *ctx)
|
464
|
+
{
|
465
|
+
int index;
|
466
|
+
|
467
|
+
assert(((*ctx).top - (*ctx).start) > 0);
|
468
|
+
|
469
|
+
index = *((*ctx).top - 1);
|
470
|
+
assert(parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE);
|
471
|
+
parser->document->nodes.start[index-1].end_mark = event->end_mark;
|
472
|
+
|
473
|
+
(void)POP(parser, *ctx);
|
474
|
+
|
475
|
+
return 1;
|
476
|
+
}
|
477
|
+
|
379
478
|
/*
|
380
479
|
* Compose a mapping node.
|
381
480
|
*/
|
382
481
|
|
383
482
|
static int
|
384
|
-
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *
|
483
|
+
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
|
484
|
+
struct loader_ctx *ctx)
|
385
485
|
{
|
386
|
-
yaml_event_t event;
|
387
486
|
yaml_node_t node;
|
388
487
|
struct {
|
389
488
|
yaml_node_pair_t *start;
|
@@ -391,8 +490,7 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
|
|
391
490
|
yaml_node_pair_t *top;
|
392
491
|
} pairs = { NULL, NULL, NULL };
|
393
492
|
int index;
|
394
|
-
|
395
|
-
yaml_char_t *tag = first_event->data.mapping_start.tag;
|
493
|
+
yaml_char_t *tag = event->data.mapping_start.tag;
|
396
494
|
|
397
495
|
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
|
398
496
|
|
@@ -402,43 +500,45 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
|
|
402
500
|
if (!tag) goto error;
|
403
501
|
}
|
404
502
|
|
405
|
-
if (!STACK_INIT(parser, pairs,
|
503
|
+
if (!STACK_INIT(parser, pairs, yaml_node_pair_t*)) goto error;
|
406
504
|
|
407
505
|
MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
|
408
|
-
|
409
|
-
|
506
|
+
event->data.mapping_start.style,
|
507
|
+
event->start_mark, event->end_mark);
|
410
508
|
|
411
509
|
if (!PUSH(parser, parser->document->nodes, node)) goto error;
|
412
510
|
|
413
|
-
index = parser->document->nodes.top - parser->document->nodes.start;
|
511
|
+
index = (int)(parser->document->nodes.top - parser->document->nodes.start);
|
414
512
|
|
415
513
|
if (!yaml_parser_register_anchor(parser, index,
|
416
|
-
|
514
|
+
event->data.mapping_start.anchor)) return 0;
|
417
515
|
|
418
|
-
if (!
|
419
|
-
|
420
|
-
while (event.type != YAML_MAPPING_END_EVENT) {
|
421
|
-
if (!STACK_LIMIT(parser,
|
422
|
-
parser->document->nodes.start[index-1].data.mapping.pairs,
|
423
|
-
INT_MAX-1)) return 0;
|
424
|
-
pair.key = yaml_parser_load_node(parser, &event);
|
425
|
-
if (!pair.key) return 0;
|
426
|
-
if (!yaml_parser_parse(parser, &event)) return 0;
|
427
|
-
pair.value = yaml_parser_load_node(parser, &event);
|
428
|
-
if (!pair.value) return 0;
|
429
|
-
if (!PUSH(parser,
|
430
|
-
parser->document->nodes.start[index-1].data.mapping.pairs,
|
431
|
-
pair)) return 0;
|
432
|
-
if (!yaml_parser_parse(parser, &event)) return 0;
|
433
|
-
}
|
516
|
+
if (!yaml_parser_load_node_add(parser, ctx, index)) return 0;
|
434
517
|
|
435
|
-
parser
|
518
|
+
if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0;
|
519
|
+
if (!PUSH(parser, *ctx, index)) return 0;
|
436
520
|
|
437
|
-
return
|
521
|
+
return 1;
|
438
522
|
|
439
523
|
error:
|
440
524
|
yaml_free(tag);
|
441
|
-
yaml_free(
|
525
|
+
yaml_free(event->data.mapping_start.anchor);
|
442
526
|
return 0;
|
443
527
|
}
|
444
528
|
|
529
|
+
static int
|
530
|
+
yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
|
531
|
+
struct loader_ctx *ctx)
|
532
|
+
{
|
533
|
+
int index;
|
534
|
+
|
535
|
+
assert(((*ctx).top - (*ctx).start) > 0);
|
536
|
+
|
537
|
+
index = *((*ctx).top - 1);
|
538
|
+
assert(parser->document->nodes.start[index-1].type == YAML_MAPPING_NODE);
|
539
|
+
parser->document->nodes.start[index-1].end_mark = event->end_mark;
|
540
|
+
|
541
|
+
(void)POP(parser, *ctx);
|
542
|
+
|
543
|
+
return 1;
|
544
|
+
}
|