psych 3.1.0 → 4.0.4
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 +2 -5
- data/Rakefile +8 -15
- data/ext/psych/depend +2 -0
- data/ext/psych/extconf.rb +6 -2
- data/ext/psych/psych.c +6 -3
- data/ext/psych/psych_parser.c +20 -33
- data/ext/psych/psych_yaml_tree.c +0 -12
- data/ext/psych/yaml/api.c +22 -22
- data/ext/psych/yaml/config.h +76 -6
- data/ext/psych/yaml/dumper.c +1 -1
- data/ext/psych/yaml/emitter.c +44 -10
- data/ext/psych/yaml/loader.c +206 -106
- data/ext/psych/yaml/parser.c +6 -1
- data/ext/psych/yaml/scanner.c +45 -25
- data/ext/psych/yaml/yaml.h +43 -29
- data/ext/psych/yaml/yaml_private.h +4 -4
- data/lib/psych/class_loader.rb +10 -8
- data/lib/psych/core_ext.rb +1 -1
- data/lib/psych/exception.rb +2 -2
- data/lib/psych/handler.rb +1 -1
- data/lib/psych/handlers/document_stream.rb +1 -1
- data/lib/psych/handlers/recorder.rb +1 -1
- data/lib/psych/json/stream.rb +2 -2
- data/lib/psych/json/tree_builder.rb +1 -1
- data/lib/psych/nodes/node.rb +4 -4
- data/lib/psych/nodes/scalar.rb +1 -1
- data/lib/psych/nodes.rb +7 -7
- data/lib/psych/scalar_scanner.rb +36 -43
- data/lib/psych/syntax_error.rb +1 -1
- data/lib/psych/tree_builder.rb +1 -1
- data/lib/psych/versions.rb +3 -3
- data/lib/psych/visitors/json_tree.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +54 -21
- data/lib/psych/visitors/visitor.rb +17 -3
- data/lib/psych/visitors/yaml_tree.rb +83 -47
- data/lib/psych/visitors.rb +6 -6
- data/lib/psych.rb +223 -123
- data/psych.gemspec +10 -16
- metadata +12 -43
- data/.travis.yml +0 -22
- data/CHANGELOG.rdoc +0 -583
data/ext/psych/yaml/scanner.c
CHANGED
@@ -38,8 +38,8 @@
|
|
38
38
|
* BLOCK-END # Indentation decrease.
|
39
39
|
* FLOW-SEQUENCE-START # '['
|
40
40
|
* FLOW-SEQUENCE-END # ']'
|
41
|
-
*
|
42
|
-
*
|
41
|
+
* FLOW-MAPPING-START # '{'
|
42
|
+
* FLOW-MAPPING-END # '}'
|
43
43
|
* BLOCK-ENTRY # '-'
|
44
44
|
* FLOW-ENTRY # ','
|
45
45
|
* KEY # '?' or nothing (simple keys).
|
@@ -273,7 +273,7 @@
|
|
273
273
|
* The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation
|
274
274
|
* increase that precedes a block collection (cf. the INDENT token in Python).
|
275
275
|
* The token BLOCK-END denote indentation decrease that ends a block collection
|
276
|
-
* (cf. the DEDENT token in Python). However YAML has some syntax
|
276
|
+
* (cf. the DEDENT token in Python). However YAML has some syntax peculiarities
|
277
277
|
* that makes detections of these tokens more complex.
|
278
278
|
*
|
279
279
|
* The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators
|
@@ -348,6 +348,7 @@
|
|
348
348
|
* SCALAR("another value",plain)
|
349
349
|
* KEY
|
350
350
|
* SCALAR("a mapping",plain)
|
351
|
+
* VALUE
|
351
352
|
* BLOCK-MAPPING-START
|
352
353
|
* KEY
|
353
354
|
* SCALAR("key 1",plain)
|
@@ -711,7 +712,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive,
|
|
711
712
|
yaml_mark_t start_mark, yaml_char_t **handle);
|
712
713
|
|
713
714
|
static int
|
714
|
-
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
|
715
|
+
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
|
715
716
|
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri);
|
716
717
|
|
717
718
|
static int
|
@@ -1227,7 +1228,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
|
|
1227
1228
|
return 0;
|
1228
1229
|
}
|
1229
1230
|
|
1230
|
-
parser->indent = column;
|
1231
|
+
parser->indent = (int)column;
|
1231
1232
|
|
1232
1233
|
/* Create a token and insert it into the queue. */
|
1233
1234
|
|
@@ -2292,7 +2293,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
|
|
2292
2293
|
|
2293
2294
|
/* Scan a prefix. */
|
2294
2295
|
|
2295
|
-
if (!yaml_parser_scan_tag_uri(parser, 1, NULL, start_mark, &prefix_value))
|
2296
|
+
if (!yaml_parser_scan_tag_uri(parser, 1, 1, NULL, start_mark, &prefix_value))
|
2296
2297
|
goto error;
|
2297
2298
|
|
2298
2299
|
/* Expect a whitespace or line break. */
|
@@ -2410,7 +2411,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
|
|
2410
2411
|
|
2411
2412
|
/* Consume the tag value. */
|
2412
2413
|
|
2413
|
-
if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
|
2414
|
+
if (!yaml_parser_scan_tag_uri(parser, 1, 0, NULL, start_mark, &suffix))
|
2414
2415
|
goto error;
|
2415
2416
|
|
2416
2417
|
/* Check for '>' and eat it. */
|
@@ -2438,14 +2439,14 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
|
|
2438
2439
|
{
|
2439
2440
|
/* Scan the suffix now. */
|
2440
2441
|
|
2441
|
-
if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
|
2442
|
+
if (!yaml_parser_scan_tag_uri(parser, 0, 0, NULL, start_mark, &suffix))
|
2442
2443
|
goto error;
|
2443
2444
|
}
|
2444
2445
|
else
|
2445
2446
|
{
|
2446
2447
|
/* It wasn't a handle after all. Scan the rest of the tag. */
|
2447
2448
|
|
2448
|
-
if (!yaml_parser_scan_tag_uri(parser, 0, handle, start_mark, &suffix))
|
2449
|
+
if (!yaml_parser_scan_tag_uri(parser, 0, 0, handle, start_mark, &suffix))
|
2449
2450
|
goto error;
|
2450
2451
|
|
2451
2452
|
/* Set the handle to '!'. */
|
@@ -2474,9 +2475,11 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
|
|
2474
2475
|
if (!CACHE(parser, 1)) goto error;
|
2475
2476
|
|
2476
2477
|
if (!IS_BLANKZ(parser->buffer)) {
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2478
|
+
if (!parser->flow_level || !CHECK(parser->buffer, ',') ) {
|
2479
|
+
yaml_parser_set_scanner_error(parser, "while scanning a tag",
|
2480
|
+
start_mark, "did not find expected whitespace or line break");
|
2481
|
+
goto error;
|
2482
|
+
}
|
2480
2483
|
}
|
2481
2484
|
|
2482
2485
|
end_mark = parser->mark;
|
@@ -2565,7 +2568,7 @@ error:
|
|
2565
2568
|
*/
|
2566
2569
|
|
2567
2570
|
static int
|
2568
|
-
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
|
2571
|
+
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
|
2569
2572
|
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri)
|
2570
2573
|
{
|
2571
2574
|
size_t length = head ? strlen((char *)head) : 0;
|
@@ -2601,8 +2604,11 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
|
|
2601
2604
|
* The set of characters that may appear in URI is as follows:
|
2602
2605
|
*
|
2603
2606
|
* '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&',
|
2604
|
-
* '=', '+', '$', '
|
2605
|
-
*
|
2607
|
+
* '=', '+', '$', '.', '!', '~', '*', '\'', '(', ')', '%'.
|
2608
|
+
*
|
2609
|
+
* If we are inside a verbatim tag <...> (parameter uri_char is true)
|
2610
|
+
* then also the following flow indicators are allowed:
|
2611
|
+
* ',', '[', ']'
|
2606
2612
|
*/
|
2607
2613
|
|
2608
2614
|
while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';')
|
@@ -2610,12 +2616,15 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
|
|
2610
2616
|
|| CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@')
|
2611
2617
|
|| CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=')
|
2612
2618
|
|| CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$')
|
2613
|
-
|| CHECK(parser->buffer, '
|
2619
|
+
|| CHECK(parser->buffer, '.') || CHECK(parser->buffer, '%')
|
2614
2620
|
|| CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~')
|
2615
2621
|
|| CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'')
|
2616
2622
|
|| CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')')
|
2617
|
-
||
|
2618
|
-
|
2623
|
+
|| (uri_char && (
|
2624
|
+
CHECK(parser->buffer, ',')
|
2625
|
+
|| CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
|
2626
|
+
)
|
2627
|
+
))
|
2619
2628
|
{
|
2620
2629
|
/* Check if it is a URI-escape sequence. */
|
2621
2630
|
|
@@ -2860,7 +2869,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token,
|
|
2860
2869
|
|
2861
2870
|
if (!CACHE(parser, 1)) goto error;
|
2862
2871
|
|
2863
|
-
while ((int)parser->mark.column == indent && !IS_Z(parser->buffer))
|
2872
|
+
while ((int)parser->mark.column == indent && !(IS_Z(parser->buffer)))
|
2864
2873
|
{
|
2865
2874
|
/*
|
2866
2875
|
* We are at the beginning of a non-empty line.
|
@@ -3278,7 +3287,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
|
|
3278
3287
|
|
3279
3288
|
/* Check if we are at the end of the scalar. */
|
3280
3289
|
|
3281
|
-
/* Fix for crash
|
3290
|
+
/* Fix for crash uninitialized value crash
|
3282
3291
|
* Credit for the bug and input is to OSS Fuzz
|
3283
3292
|
* Credit for the fix to Alex Gaynor
|
3284
3293
|
*/
|
@@ -3430,11 +3439,22 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
|
|
3430
3439
|
|
3431
3440
|
while (!IS_BLANKZ(parser->buffer))
|
3432
3441
|
{
|
3433
|
-
/* Check for
|
3442
|
+
/* Check for "x:" + one of ',?[]{}' in the flow context. TODO: Fix the test "spec-08-13".
|
3443
|
+
* This is not completely according to the spec
|
3444
|
+
* See http://yaml.org/spec/1.1/#id907281 9.1.3. Plain
|
3445
|
+
*/
|
3434
3446
|
|
3435
3447
|
if (parser->flow_level
|
3436
3448
|
&& CHECK(parser->buffer, ':')
|
3437
|
-
&&
|
3449
|
+
&& (
|
3450
|
+
CHECK_AT(parser->buffer, ',', 1)
|
3451
|
+
|| CHECK_AT(parser->buffer, '?', 1)
|
3452
|
+
|| CHECK_AT(parser->buffer, '[', 1)
|
3453
|
+
|| CHECK_AT(parser->buffer, ']', 1)
|
3454
|
+
|| CHECK_AT(parser->buffer, '{', 1)
|
3455
|
+
|| CHECK_AT(parser->buffer, '}', 1)
|
3456
|
+
)
|
3457
|
+
) {
|
3438
3458
|
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
|
3439
3459
|
start_mark, "found unexpected ':'");
|
3440
3460
|
goto error;
|
@@ -3444,8 +3464,8 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
|
|
3444
3464
|
|
3445
3465
|
if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))
|
3446
3466
|
|| (parser->flow_level &&
|
3447
|
-
(CHECK(parser->buffer, ',')
|
3448
|
-
|| CHECK(parser->buffer, '
|
3467
|
+
(CHECK(parser->buffer, ',')
|
3468
|
+
|| CHECK(parser->buffer, '[')
|
3449
3469
|
|| CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{')
|
3450
3470
|
|| CHECK(parser->buffer, '}'))))
|
3451
3471
|
break;
|
@@ -3512,7 +3532,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
|
|
3512
3532
|
if (leading_blanks && (int)parser->mark.column < indent
|
3513
3533
|
&& IS_TAB(parser->buffer)) {
|
3514
3534
|
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
|
3515
|
-
start_mark, "found a tab character that
|
3535
|
+
start_mark, "found a tab character that violates indentation");
|
3516
3536
|
goto error;
|
3517
3537
|
}
|
3518
3538
|
|
data/ext/psych/yaml/yaml.h
CHANGED
@@ -26,7 +26,9 @@ extern "C" {
|
|
26
26
|
|
27
27
|
/** The public API declaration. */
|
28
28
|
|
29
|
-
#
|
29
|
+
#if defined(__MINGW32__)
|
30
|
+
# define YAML_DECLARE(type) type
|
31
|
+
#elif defined(_WIN32)
|
30
32
|
# if defined(YAML_DECLARE_STATIC)
|
31
33
|
# define YAML_DECLARE(type) type
|
32
34
|
# elif defined(YAML_DECLARE_EXPORT)
|
@@ -230,7 +232,7 @@ typedef enum yaml_token_type_e {
|
|
230
232
|
|
231
233
|
/** A BLOCK-SEQUENCE-START token. */
|
232
234
|
YAML_BLOCK_SEQUENCE_START_TOKEN,
|
233
|
-
/** A BLOCK-
|
235
|
+
/** A BLOCK-MAPPING-START token. */
|
234
236
|
YAML_BLOCK_MAPPING_START_TOKEN,
|
235
237
|
/** A BLOCK-END token. */
|
236
238
|
YAML_BLOCK_END_TOKEN,
|
@@ -550,7 +552,7 @@ yaml_document_end_event_initialize(yaml_event_t *event, int implicit);
|
|
550
552
|
*/
|
551
553
|
|
552
554
|
YAML_DECLARE(int)
|
553
|
-
yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
|
555
|
+
yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor);
|
554
556
|
|
555
557
|
/**
|
556
558
|
* Create a SCALAR event.
|
@@ -576,8 +578,8 @@ yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
|
|
576
578
|
|
577
579
|
YAML_DECLARE(int)
|
578
580
|
yaml_scalar_event_initialize(yaml_event_t *event,
|
579
|
-
yaml_char_t *anchor, yaml_char_t *tag,
|
580
|
-
yaml_char_t *value, int length,
|
581
|
+
const yaml_char_t *anchor, const yaml_char_t *tag,
|
582
|
+
const yaml_char_t *value, int length,
|
581
583
|
int plain_implicit, int quoted_implicit,
|
582
584
|
yaml_scalar_style_t style);
|
583
585
|
|
@@ -599,7 +601,7 @@ yaml_scalar_event_initialize(yaml_event_t *event,
|
|
599
601
|
|
600
602
|
YAML_DECLARE(int)
|
601
603
|
yaml_sequence_start_event_initialize(yaml_event_t *event,
|
602
|
-
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
|
604
|
+
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
|
603
605
|
yaml_sequence_style_t style);
|
604
606
|
|
605
607
|
/**
|
@@ -631,7 +633,7 @@ yaml_sequence_end_event_initialize(yaml_event_t *event);
|
|
631
633
|
|
632
634
|
YAML_DECLARE(int)
|
633
635
|
yaml_mapping_start_event_initialize(yaml_event_t *event,
|
634
|
-
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
|
636
|
+
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
|
635
637
|
yaml_mapping_style_t style);
|
636
638
|
|
637
639
|
/**
|
@@ -663,7 +665,7 @@ yaml_event_delete(yaml_event_t *event);
|
|
663
665
|
|
664
666
|
/** The tag @c !!null with the only possible value: @c null. */
|
665
667
|
#define YAML_NULL_TAG "tag:yaml.org,2002:null"
|
666
|
-
/** The tag @c !!bool with the values: @c true and @c
|
668
|
+
/** The tag @c !!bool with the values: @c true and @c false. */
|
667
669
|
#define YAML_BOOL_TAG "tag:yaml.org,2002:bool"
|
668
670
|
/** The tag @c !!str for string values. */
|
669
671
|
#define YAML_STR_TAG "tag:yaml.org,2002:str"
|
@@ -894,7 +896,7 @@ yaml_document_get_root_node(yaml_document_t *document);
|
|
894
896
|
|
895
897
|
YAML_DECLARE(int)
|
896
898
|
yaml_document_add_scalar(yaml_document_t *document,
|
897
|
-
yaml_char_t *tag, yaml_char_t *value, int length,
|
899
|
+
const yaml_char_t *tag, const yaml_char_t *value, int length,
|
898
900
|
yaml_scalar_style_t style);
|
899
901
|
|
900
902
|
/**
|
@@ -911,7 +913,7 @@ yaml_document_add_scalar(yaml_document_t *document,
|
|
911
913
|
|
912
914
|
YAML_DECLARE(int)
|
913
915
|
yaml_document_add_sequence(yaml_document_t *document,
|
914
|
-
yaml_char_t *tag, yaml_sequence_style_t style);
|
916
|
+
const yaml_char_t *tag, yaml_sequence_style_t style);
|
915
917
|
|
916
918
|
/**
|
917
919
|
* Create a MAPPING node and attach it to the document.
|
@@ -927,7 +929,7 @@ yaml_document_add_sequence(yaml_document_t *document,
|
|
927
929
|
|
928
930
|
YAML_DECLARE(int)
|
929
931
|
yaml_document_add_mapping(yaml_document_t *document,
|
930
|
-
yaml_char_t *tag, yaml_mapping_style_t style);
|
932
|
+
const yaml_char_t *tag, yaml_mapping_style_t style);
|
931
933
|
|
932
934
|
/**
|
933
935
|
* Add an item to a SEQUENCE node.
|
@@ -935,7 +937,7 @@ yaml_document_add_mapping(yaml_document_t *document,
|
|
935
937
|
* @param[in,out] document A document object.
|
936
938
|
* @param[in] sequence The sequence node id.
|
937
939
|
* @param[in] item The item node id.
|
938
|
-
*
|
940
|
+
*
|
939
941
|
* @returns @c 1 if the function succeeded, @c 0 on error.
|
940
942
|
*/
|
941
943
|
|
@@ -950,7 +952,7 @@ yaml_document_append_sequence_item(yaml_document_t *document,
|
|
950
952
|
* @param[in] mapping The mapping node id.
|
951
953
|
* @param[in] key The key node id.
|
952
954
|
* @param[in] value The value node id.
|
953
|
-
*
|
955
|
+
*
|
954
956
|
* @returns @c 1 if the function succeeded, @c 0 on error.
|
955
957
|
*/
|
956
958
|
|
@@ -1018,6 +1020,7 @@ typedef enum yaml_parser_state_e {
|
|
1018
1020
|
YAML_PARSE_DOCUMENT_CONTENT_STATE,
|
1019
1021
|
/** Expect DOCUMENT-END. */
|
1020
1022
|
YAML_PARSE_DOCUMENT_END_STATE,
|
1023
|
+
|
1021
1024
|
/** Expect a block node. */
|
1022
1025
|
YAML_PARSE_BLOCK_NODE_STATE,
|
1023
1026
|
/** Expect a block node or indentless sequence. */
|
@@ -1028,6 +1031,7 @@ typedef enum yaml_parser_state_e {
|
|
1028
1031
|
YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
|
1029
1032
|
/** Expect an entry of a block sequence. */
|
1030
1033
|
YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
|
1034
|
+
|
1031
1035
|
/** Expect an entry of an indentless sequence. */
|
1032
1036
|
YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
|
1033
1037
|
/** Expect the first key of a block mapping. */
|
@@ -1038,6 +1042,7 @@ typedef enum yaml_parser_state_e {
|
|
1038
1042
|
YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
|
1039
1043
|
/** Expect the first entry of a flow sequence. */
|
1040
1044
|
YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
|
1045
|
+
|
1041
1046
|
/** Expect an entry of a flow sequence. */
|
1042
1047
|
YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
|
1043
1048
|
/** Expect a key of an ordered mapping. */
|
@@ -1049,6 +1054,7 @@ typedef enum yaml_parser_state_e {
|
|
1049
1054
|
/** Expect the first key of a flow mapping. */
|
1050
1055
|
YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
|
1051
1056
|
/** Expect a key of a flow mapping. */
|
1057
|
+
|
1052
1058
|
YAML_PARSE_FLOW_MAPPING_KEY_STATE,
|
1053
1059
|
/** Expect a value of a flow mapping. */
|
1054
1060
|
YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
|
@@ -1203,7 +1209,7 @@ typedef struct yaml_parser_s {
|
|
1203
1209
|
/** The number of tokens fetched from the queue. */
|
1204
1210
|
size_t tokens_parsed;
|
1205
1211
|
|
1206
|
-
|
1212
|
+
/** Does the tokens queue contain a token ready for dequeueing. */
|
1207
1213
|
int token_available;
|
1208
1214
|
|
1209
1215
|
/** The indentation levels stack. */
|
@@ -1329,7 +1335,7 @@ yaml_parser_delete(yaml_parser_t *parser);
|
|
1329
1335
|
* Set a string input.
|
1330
1336
|
*
|
1331
1337
|
* Note that the @a input pointer must be valid while the @a parser object
|
1332
|
-
* exists. The application is responsible for
|
1338
|
+
* exists. The application is responsible for destroying @a input after
|
1333
1339
|
* destroying the @a parser.
|
1334
1340
|
*
|
1335
1341
|
* @param[in,out] parser A parser object.
|
@@ -1444,7 +1450,7 @@ yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
|
|
1444
1450
|
* @param[in,out] parser A parser object.
|
1445
1451
|
* @param[out] document An empty document object.
|
1446
1452
|
*
|
1447
|
-
* @
|
1453
|
+
* @returns @c 1 if the function succeeded, @c 0 on error.
|
1448
1454
|
*/
|
1449
1455
|
|
1450
1456
|
YAML_DECLARE(int)
|
@@ -1487,6 +1493,7 @@ typedef enum yaml_emitter_state_e {
|
|
1487
1493
|
YAML_EMIT_DOCUMENT_CONTENT_STATE,
|
1488
1494
|
/** Expect DOCUMENT-END. */
|
1489
1495
|
YAML_EMIT_DOCUMENT_END_STATE,
|
1496
|
+
|
1490
1497
|
/** Expect the first item of a flow sequence. */
|
1491
1498
|
YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
|
1492
1499
|
/** Expect an item of a flow sequence. */
|
@@ -1497,6 +1504,7 @@ typedef enum yaml_emitter_state_e {
|
|
1497
1504
|
YAML_EMIT_FLOW_MAPPING_KEY_STATE,
|
1498
1505
|
/** Expect a value for a simple key of a flow mapping. */
|
1499
1506
|
YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
|
1507
|
+
|
1500
1508
|
/** Expect a value of a flow mapping. */
|
1501
1509
|
YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
|
1502
1510
|
/** Expect the first item of a block sequence. */
|
@@ -1507,6 +1515,7 @@ typedef enum yaml_emitter_state_e {
|
|
1507
1515
|
YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
|
1508
1516
|
/** Expect the key of a block mapping. */
|
1509
1517
|
YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
|
1518
|
+
|
1510
1519
|
/** Expect a value for a simple key of a block mapping. */
|
1511
1520
|
YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
|
1512
1521
|
/** Expect a value of a block mapping. */
|
@@ -1515,6 +1524,18 @@ typedef enum yaml_emitter_state_e {
|
|
1515
1524
|
YAML_EMIT_END_STATE
|
1516
1525
|
} yaml_emitter_state_t;
|
1517
1526
|
|
1527
|
+
|
1528
|
+
/* This is needed for C++ */
|
1529
|
+
|
1530
|
+
typedef struct yaml_anchors_s {
|
1531
|
+
/** The number of references. */
|
1532
|
+
int references;
|
1533
|
+
/** The anchor id. */
|
1534
|
+
int anchor;
|
1535
|
+
/** If the node has been emitted? */
|
1536
|
+
int serialized;
|
1537
|
+
} yaml_anchors_t;
|
1538
|
+
|
1518
1539
|
/**
|
1519
1540
|
* The emitter structure.
|
1520
1541
|
*
|
@@ -1546,7 +1567,7 @@ typedef struct yaml_emitter_s {
|
|
1546
1567
|
/** Write handler. */
|
1547
1568
|
yaml_write_handler_t *write_handler;
|
1548
1569
|
|
1549
|
-
/** A pointer for passing to the
|
1570
|
+
/** A pointer for passing to the write handler. */
|
1550
1571
|
void *write_handler_data;
|
1551
1572
|
|
1552
1573
|
/** Standard (string or file) output data. */
|
@@ -1713,7 +1734,7 @@ typedef struct yaml_emitter_s {
|
|
1713
1734
|
size_t length;
|
1714
1735
|
/** Does the scalar contain line breaks? */
|
1715
1736
|
int multiline;
|
1716
|
-
/** Can the scalar be
|
1737
|
+
/** Can the scalar be expressed in the flow plain style? */
|
1717
1738
|
int flow_plain_allowed;
|
1718
1739
|
/** Can the scalar be expressed in the block plain style? */
|
1719
1740
|
int block_plain_allowed;
|
@@ -1740,14 +1761,7 @@ typedef struct yaml_emitter_s {
|
|
1740
1761
|
int closed;
|
1741
1762
|
|
1742
1763
|
/** The information associated with the document nodes. */
|
1743
|
-
|
1744
|
-
/** The number of references. */
|
1745
|
-
int references;
|
1746
|
-
/** The anchor id. */
|
1747
|
-
int anchor;
|
1748
|
-
/** If the node has been emitted? */
|
1749
|
-
int serialized;
|
1750
|
-
} *anchors;
|
1764
|
+
yaml_anchors_t *anchors;
|
1751
1765
|
|
1752
1766
|
/** The last assigned anchor id. */
|
1753
1767
|
int last_anchor_id;
|
@@ -1936,10 +1950,10 @@ yaml_emitter_close(yaml_emitter_t *emitter);
|
|
1936
1950
|
/**
|
1937
1951
|
* Emit a YAML document.
|
1938
1952
|
*
|
1939
|
-
* The
|
1953
|
+
* The document object may be generated using the yaml_parser_load() function
|
1940
1954
|
* or the yaml_document_initialize() function. The emitter takes the
|
1941
|
-
* responsibility for the document object and
|
1942
|
-
* it is emitted. The document object is
|
1955
|
+
* responsibility for the document object and destroys its content after
|
1956
|
+
* it is emitted. The document object is destroyed even if the function fails.
|
1943
1957
|
*
|
1944
1958
|
* @param[in,out] emitter An emitter object.
|
1945
1959
|
* @param[in,out] document A document object.
|
@@ -2,8 +2,8 @@
|
|
2
2
|
#include RUBY_EXTCONF_H
|
3
3
|
#endif
|
4
4
|
|
5
|
-
#
|
6
|
-
#include
|
5
|
+
#ifdef HAVE_CONFIG_H
|
6
|
+
#include "config.h"
|
7
7
|
#endif
|
8
8
|
|
9
9
|
#include <yaml.h>
|
@@ -175,14 +175,14 @@ yaml_string_join(
|
|
175
175
|
* Check the octet at the specified position.
|
176
176
|
*/
|
177
177
|
|
178
|
-
#define CHECK_AT(string,octet,offset)
|
178
|
+
#define CHECK_AT(string,octet,offset) \
|
179
179
|
((string).pointer[offset] == (yaml_char_t)(octet))
|
180
180
|
|
181
181
|
/*
|
182
182
|
* Check the current octet in the buffer.
|
183
183
|
*/
|
184
184
|
|
185
|
-
#define CHECK(string,octet) CHECK_AT((string),(octet),0)
|
185
|
+
#define CHECK(string,octet) (CHECK_AT((string),(octet),0))
|
186
186
|
|
187
187
|
/*
|
188
188
|
* Check if the character at the specified position is an alphabetical
|
data/lib/psych/class_loader.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
2
|
+
require_relative 'omap'
|
3
|
+
require_relative 'set'
|
4
4
|
|
5
5
|
module Psych
|
6
6
|
class ClassLoader # :nodoc:
|
@@ -35,9 +35,11 @@ module Psych
|
|
35
35
|
|
36
36
|
constants.each do |const|
|
37
37
|
konst = const_get const
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
class_eval <<~RUBY
|
39
|
+
def #{const.to_s.downcase}
|
40
|
+
load #{konst.inspect}
|
41
|
+
end
|
42
|
+
RUBY
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
@@ -69,7 +71,7 @@ module Psych
|
|
69
71
|
rescue
|
70
72
|
nil
|
71
73
|
end
|
72
|
-
}.compact]
|
74
|
+
}.compact].freeze
|
73
75
|
|
74
76
|
class Restricted < ClassLoader
|
75
77
|
def initialize classes, symbols
|
@@ -84,7 +86,7 @@ module Psych
|
|
84
86
|
if @symbols.include? sym
|
85
87
|
super
|
86
88
|
else
|
87
|
-
raise DisallowedClass, 'Symbol'
|
89
|
+
raise DisallowedClass.new('load', 'Symbol')
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
@@ -94,7 +96,7 @@ module Psych
|
|
94
96
|
if @classes.include? klassname
|
95
97
|
super
|
96
98
|
else
|
97
|
-
raise DisallowedClass, klassname
|
99
|
+
raise DisallowedClass.new('load', klassname)
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
data/lib/psych/core_ext.rb
CHANGED
data/lib/psych/exception.rb
CHANGED
@@ -7,8 +7,8 @@ module Psych
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class DisallowedClass < Exception
|
10
|
-
def initialize klass_name
|
11
|
-
super "Tried to
|
10
|
+
def initialize action, klass_name
|
11
|
+
super "Tried to #{action} unspecified class: #{klass_name}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/psych/handler.rb
CHANGED
@@ -119,7 +119,7 @@ module Psych
|
|
119
119
|
# +tag+ is an associated tag or nil
|
120
120
|
# +plain+ is a boolean value
|
121
121
|
# +quoted+ is a boolean value
|
122
|
-
# +style+ is an integer
|
122
|
+
# +style+ is an integer indicating the string style
|
123
123
|
#
|
124
124
|
# See the constants in Psych::Nodes::Scalar for the possible values of
|
125
125
|
# +style+
|
data/lib/psych/json/stream.rb
CHANGED
data/lib/psych/nodes/node.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'stringio'
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../class_loader'
|
4
|
+
require_relative '../scalar_scanner'
|
5
5
|
|
6
6
|
module Psych
|
7
7
|
module Nodes
|
@@ -46,8 +46,8 @@ module Psych
|
|
46
46
|
# Convert this node to Ruby.
|
47
47
|
#
|
48
48
|
# See also Psych::Visitors::ToRuby
|
49
|
-
def to_ruby
|
50
|
-
Visitors::ToRuby.create.accept(self)
|
49
|
+
def to_ruby(symbolize_names: false, freeze: false, strict_integer: false)
|
50
|
+
Visitors::ToRuby.create(symbolize_names: symbolize_names, freeze: freeze, strict_integer: strict_integer).accept(self)
|
51
51
|
end
|
52
52
|
alias :transform :to_ruby
|
53
53
|
|
data/lib/psych/nodes/scalar.rb
CHANGED
data/lib/psych/nodes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
require_relative 'nodes/node'
|
3
|
+
require_relative 'nodes/stream'
|
4
|
+
require_relative 'nodes/document'
|
5
|
+
require_relative 'nodes/sequence'
|
6
|
+
require_relative 'nodes/scalar'
|
7
|
+
require_relative 'nodes/mapping'
|
8
|
+
require_relative 'nodes/alias'
|
9
9
|
|
10
10
|
module Psych
|
11
11
|
###
|