diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2023-03-01 12:37:40 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2023-03-01 12:37:40 +0300 |
commit | 4da2793202f677b52427b48c3f6d9ab9da23d2fc (patch) | |
tree | 9c9aa1b9def0d9d157da3b4b19db602d1cc5615d /contrib | |
parent | 1b6baf206fce75465d8130c2a0aa15f30cf52625 (diff) | |
download | ydb-4da2793202f677b52427b48c3f6d9ab9da23d2fc.tar.gz |
Update contrib/libs/libfyaml to 0.8
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/libs/libfyaml/config.h | 9 | ||||
-rw-r--r-- | contrib/libs/libfyaml/include/libfyaml.h | 18 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-atom.h | 7 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-ctype.h | 12 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-doc.c | 2 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-emit.c | 90 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-emit.h | 1 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-parse.c | 166 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-parse.h | 3 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-token.c | 25 | ||||
-rw-r--r-- | contrib/libs/libfyaml/src/lib/fy-token.h | 1 |
11 files changed, 257 insertions, 77 deletions
diff --git a/contrib/libs/libfyaml/config.h b/contrib/libs/libfyaml/config.h index 283720047d..aee29e664d 100644 --- a/contrib/libs/libfyaml/config.h +++ b/contrib/libs/libfyaml/config.h @@ -4,6 +4,9 @@ /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ +/* Define to 1 if ASAN is enabled */ +#define HAVE_ASAN 0 + /* Define to 1 if you have check available */ #define HAVE_CHECK 0 @@ -96,7 +99,7 @@ #define PACKAGE_NAME "libfyaml" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libfyaml 0.7.12" +#define PACKAGE_STRING "libfyaml 0.8" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "libfyaml" @@ -105,7 +108,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.7.12" +#define PACKAGE_VERSION "0.8" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ @@ -208,7 +211,7 @@ /* Version number of package */ -#define VERSION "0.7.12" +#define VERSION "0.8" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ diff --git a/contrib/libs/libfyaml/include/libfyaml.h b/contrib/libs/libfyaml/include/libfyaml.h index 0d68ff8257..28abdd668f 100644 --- a/contrib/libs/libfyaml/include/libfyaml.h +++ b/contrib/libs/libfyaml/include/libfyaml.h @@ -1011,6 +1011,22 @@ fy_token_scalar_style(struct fy_token *fyt) FY_EXPORT; /** + * fy_token_scalar_is_null() - Test whether the scalar is null (content) + * + * @fyt: The scalar token to check for NULLity. + * + * Note that this is different than null of the YAML type system. + * It is null as in null content. It is also different than an + * empty scalar. + * + * Returns: + * true if is a null scalar, false otherwise + */ +bool +fy_token_scalar_is_null(struct fy_token *fyt) + FY_EXPORT; + +/** * fy_token_get_text() - Get text (and length of it) of a token * * This method will return a pointer to the text of a token @@ -1586,6 +1602,7 @@ enum fy_emitter_write_type { * @FYECF_MODE_JSON_ONELINE: Emit using JSON mode (non type preserving, one line) * @FYECF_MODE_DEJSON: Emit YAML trying to pretify JSON * @FYECF_MODE_PRETTY: Emit YAML that tries to look good + * @FYECF_MODE_MANUAL: Emit YAML respecting all manual style hints (reformats if needed) * @FYECF_DOC_START_MARK_AUTO: Automatically generate document start markers if required * @FYECF_DOC_START_MARK_OFF: Do not generate document start markers * @FYECF_DOC_START_MARK_ON: Always generate document start markers @@ -1631,6 +1648,7 @@ enum fy_emitter_cfg_flags { FYECF_MODE_JSON_ONELINE = FYECF_MODE(6), FYECF_MODE_DEJSON = FYECF_MODE(7), FYECF_MODE_PRETTY = FYECF_MODE(8), + FYECF_MODE_MANUAL = FYECF_MODE(9), FYECF_DOC_START_MARK_AUTO = FYECF_DOC_START_MARK(0), FYECF_DOC_START_MARK_OFF = FYECF_DOC_START_MARK(1), FYECF_DOC_START_MARK_ON = FYECF_DOC_START_MARK(2), diff --git a/contrib/libs/libfyaml/src/lib/fy-atom.h b/contrib/libs/libfyaml/src/lib/fy-atom.h index 2a8b563323..0367173287 100644 --- a/contrib/libs/libfyaml/src/lib/fy-atom.h +++ b/contrib/libs/libfyaml/src/lib/fy-atom.h @@ -180,6 +180,13 @@ fy_reader_fill_atom_end(struct fy_reader *fyr, struct fy_atom *handle) fy_reader_fill_atom_end_at(fyr, handle, NULL); } +static inline void +fy_atom_reset_storage_hints(struct fy_atom *handle) +{ + handle->storage_hint = 0; + handle->storage_hint_valid = false; +} + struct fy_atom *fy_reader_fill_atom(struct fy_reader *fyr, int advance, struct fy_atom *handle); struct fy_atom *fy_reader_fill_atom_mark(struct fy_reader *fyr, const struct fy_mark *start_mark, const struct fy_mark *end_mark, struct fy_atom *handle); diff --git a/contrib/libs/libfyaml/src/lib/fy-ctype.h b/contrib/libs/libfyaml/src/lib/fy-ctype.h index 8a8e7fb907..2d8bdb692a 100644 --- a/contrib/libs/libfyaml/src/lib/fy-ctype.h +++ b/contrib/libs/libfyaml/src/lib/fy-ctype.h @@ -149,9 +149,14 @@ static inline bool fy_is_ns_char(int c) return fy_is_nb_char(c) && !fy_is_ws(c); } -static inline bool fy_is_indicator(int c) +static inline bool fy_is_start_indicator(int c) { - return !!fy_utf8_strchr("-?:,[]{}#&*!|>'\"%%@`", c); + return !!fy_utf8_strchr(",[]{}#&*!|>'\"%%@`", c); +} + +static inline bool fy_is_indicator_before_space(int c) +{ + return !!fy_utf8_strchr("-:?`", c); } static inline bool fy_is_flow_indicator(int c) @@ -282,7 +287,8 @@ FY_CTYPE_AT_BUILDER(print); FY_CTYPE_AT_BUILDER(printq); FY_CTYPE_AT_BUILDER(nb_char); FY_CTYPE_AT_BUILDER(ns_char); -FY_CTYPE_AT_BUILDER(indicator); +FY_CTYPE_AT_BUILDER(start_indicator); +FY_CTYPE_AT_BUILDER(indicator_before_space); FY_CTYPE_AT_BUILDER(flow_indicator); FY_CTYPE_AT_BUILDER(path_flow_key_start); FY_CTYPE_AT_BUILDER(path_flow_key_end); diff --git a/contrib/libs/libfyaml/src/lib/fy-doc.c b/contrib/libs/libfyaml/src/lib/fy-doc.c index 8cb6a39b86..eb76ac4ff6 100644 --- a/contrib/libs/libfyaml/src/lib/fy-doc.c +++ b/contrib/libs/libfyaml/src/lib/fy-doc.c @@ -3357,7 +3357,7 @@ bool fy_node_is_null(struct fy_node *fyn) if (fyn->type != FYNT_SCALAR) return false; - return fyn->scalar == NULL; + return fyn->scalar == NULL || fyn->scalar->scalar.is_null; } bool fy_node_is_attached(struct fy_node *fyn) diff --git a/contrib/libs/libfyaml/src/lib/fy-emit.c b/contrib/libs/libfyaml/src/lib/fy-emit.c index ad0a18dd57..9408ccd2e2 100644 --- a/contrib/libs/libfyaml/src/lib/fy-emit.c +++ b/contrib/libs/libfyaml/src/lib/fy-emit.c @@ -78,6 +78,13 @@ static inline bool fy_emit_is_pretty_mode(const struct fy_emitter *emit) return flags == FYECF_MODE_PRETTY; } +static inline bool fy_emit_is_manual(const struct fy_emitter *emit) +{ + enum fy_emitter_cfg_flags flags = emit->cfg.flags & FYECF_MODE(FYECF_MODE_MASK); + + return flags == FYECF_MODE_MANUAL; +} + static inline int fy_emit_indent(struct fy_emitter *emit) { int indent; @@ -704,7 +711,7 @@ void fy_emit_token_write_plain(struct fy_emitter *emit, struct fy_token *fyt, in atom = fy_token_atom(fyt); /* null and json mode */ - if (fy_emit_is_json_mode(emit) && (!fyt || !atom || atom->size0)) { + if (fy_emit_is_json_mode(emit) && (/* (!fyt || !atom || atom->size0) || */ fyt->scalar.is_null)) { fy_emit_puts(emit, wtype, "null"); goto out; } @@ -1244,7 +1251,7 @@ fy_emit_token_scalar_style(struct fy_emitter *emit, struct fy_token *fyt, { const char *value = NULL; size_t len = 0; - bool json, flow, is_json_plain; + bool json, flow, is_null_scalar, is_json_plain; struct fy_atom *atom; int aflags = -1; const char *tag; @@ -1260,34 +1267,38 @@ fy_emit_token_scalar_style(struct fy_emitter *emit, struct fy_token *fyt, json = fy_emit_is_json_mode(emit); - /* literal in JSON mode is output as quoted */ - if (json && (style == FYNS_LITERAL || style == FYNS_FOLDED)) - return FYNS_DOUBLE_QUOTED; + is_null_scalar = !atom || fyt->scalar.is_null; /* is this a plain json atom? */ is_json_plain = (json || emit->source_json || fy_emit_is_dejson_mode(emit)) && - (!atom || atom->size0 || + (is_null_scalar || !fy_atom_strcmp(atom, "false") || !fy_atom_strcmp(atom, "true") || !fy_atom_strcmp(atom, "null") || fy_atom_is_number(atom)); - if (is_json_plain) { - tag = fy_token_get_text(fyt_tag, &tag_len); - - /* XXX hardcoded string tag resultion */ - if (tag && tag_len && - ((tag_len == 1 && *tag == '!') || - (tag_len == 21 && !memcmp(tag, "tag:yaml.org,2002:str", 21)))) + if (json) { + /* literal in JSON mode is output as quoted */ + if (style == FYNS_LITERAL || style == FYNS_FOLDED) return FYNS_DOUBLE_QUOTED; - } - /* JSON NULL, but with plain style */ - if (json && (style == FYNS_PLAIN || style == FYNS_ANY) && (!atom || (is_json_plain && !atom->size0))) - return FYNS_PLAIN; + if (is_json_plain) { + tag = fy_token_get_text(fyt_tag, &tag_len); + + /* XXX hardcoded string tag resultion */ + if (tag && tag_len && + ((tag_len == 1 && *tag == '!') || + (tag_len == 21 && !memcmp(tag, "tag:yaml.org,2002:str", 21)))) + return FYNS_DOUBLE_QUOTED; + } + + /* JSON NULL, but with plain style */ + if ((style == FYNS_PLAIN || style == FYNS_ANY) && + (is_null_scalar || (is_json_plain && !atom->size0))) + return FYNS_PLAIN; - if (json) return FYNS_DOUBLE_QUOTED; + } aflags = fy_token_text_analyze(fyt); @@ -1346,9 +1357,15 @@ out: FYNS_PLAIN : FYNS_DOUBLE_QUOTED; } - /* special handling for plains on start of line */ - if ((aflags & FYTTAF_QUOTE_AT_0) && indent == 0 && style == FYNS_PLAIN) - style = FYNS_DOUBLE_QUOTED; + if (style == FYNS_PLAIN) { + /* plains in flow mode not being able to be plains + * - plain in block mode that can't be plain in flow mode + * - special handling for plains on start of line + */ + if ((flow && !(aflags & FYTTAF_CAN_BE_PLAIN_FLOW) && !is_null_scalar) || + ((aflags & FYTTAF_QUOTE_AT_0) && indent == 0)) + style = FYNS_DOUBLE_QUOTED; + } return style; } @@ -1414,7 +1431,9 @@ static void fy_emit_sequence_prolog(struct fy_emitter *emit, struct fy_emit_save sc->old_indent = sc->indent; if (!json) { - if (fy_emit_is_block_mode(emit)) + if (fy_emit_is_manual(emit)) + sc->flow = (sc->xstyle == FYNS_BLOCK && was_flow) || sc->xstyle == FYNS_FLOW; + else if (fy_emit_is_block_mode(emit)) sc->flow = sc->empty; else sc->flow = fy_emit_is_flow_mode(emit) || emit->flow_level || sc->flow_token || sc->empty; @@ -1501,6 +1520,7 @@ void fy_emit_sequence(struct fy_emitter *emit, struct fy_node *fyn, int flags, i sc->empty = fy_node_list_empty(&fyn->sequence); sc->flow_token = fyn->style == FYNS_FLOW; sc->flow = !!(flags & DDNF_FLOW); + sc->xstyle = fyn->style; sc->old_indent = sc->indent; fy_emit_sequence_prolog(emit, sc); @@ -1523,10 +1543,13 @@ static void fy_emit_mapping_prolog(struct fy_emitter *emit, struct fy_emit_save_ { bool json = fy_emit_is_json_mode(emit); bool oneline = fy_emit_is_oneline(emit); + bool was_flow = sc->flow; sc->old_indent = sc->indent; if (!json) { - if (fy_emit_is_block_mode(emit)) + if (fy_emit_is_manual(emit)) + sc->flow = (sc->xstyle == FYNS_BLOCK && was_flow) || sc->xstyle == FYNS_FLOW; + else if (fy_emit_is_block_mode(emit)) sc->flow = sc->empty; else sc->flow = fy_emit_is_flow_mode(emit) || emit->flow_level || sc->flow_token || sc->empty; @@ -1646,6 +1669,7 @@ void fy_emit_mapping(struct fy_emitter *emit, struct fy_node *fyn, int flags, in sc->empty = fy_node_pair_list_empty(&fyn->mapping); sc->flow_token = fyn->style == FYNS_FLOW; sc->flow = !!(flags & DDNF_FLOW); + sc->xstyle = fyn->style; sc->old_indent = sc->indent; fy_emit_mapping_prolog(emit, sc); @@ -2791,9 +2815,13 @@ fy_emit_peek_next_event(struct fy_emitter *emit) bool fy_emit_streaming_sequence_empty(struct fy_emitter *emit) { + enum fy_emitter_cfg_flags flags = emit->cfg.flags & FYECF_MODE(FYECF_MODE_MASK); struct fy_eventp *fyepn; struct fy_event *fyen; + if (flags == FYECF_MODE_BLOCK || flags == FYECF_MODE_DEJSON) + return false; + fyepn = fy_emit_peek_next_event(emit); fyen = fyepn ? &fyepn->e : NULL; @@ -2881,7 +2909,7 @@ static int fy_emit_streaming_node(struct fy_emitter *emit, struct fy_eventp *fye { struct fy_event *fye = &fyep->e; struct fy_emit_save_ctx *sc = &emit->s_sc; - enum fy_node_style style; + enum fy_node_style style, xstyle; int ret, s_flags, s_indent; if (fye->type != FYET_ALIAS && fye->type != FYET_SCALAR && @@ -2921,6 +2949,9 @@ static int fy_emit_streaming_node(struct fy_emitter *emit, struct fy_eventp *fye s_flags = emit->s_flags; s_indent = emit->s_indent; + xstyle = fye->sequence_start.sequence_start->type == FYTT_BLOCK_SEQUENCE_START ? + FYNS_BLOCK : FYNS_FLOW; + fy_emit_common_node_preamble(emit, fye->sequence_start.anchor, fye->sequence_start.tag, emit->s_flags, emit->s_indent); /* create new context */ @@ -2928,9 +2959,9 @@ static int fy_emit_streaming_node(struct fy_emitter *emit, struct fy_eventp *fye sc->flags = emit->s_flags & (DDNF_ROOT | DDNF_SEQ | DDNF_MAP); sc->indent = emit->s_indent; sc->empty = fy_emit_streaming_sequence_empty(emit); - sc->flow_token = fye->sequence_start.sequence_start && - fye->sequence_start.sequence_start->type == FYTT_FLOW_SEQUENCE_START; + sc->flow_token = xstyle == FYNS_FLOW; sc->flow = !!(s_flags & DDNF_FLOW); + sc->xstyle = xstyle; sc->old_indent = sc->indent; sc->s_flags = s_flags; sc->s_indent = s_indent; @@ -2956,6 +2987,9 @@ static int fy_emit_streaming_node(struct fy_emitter *emit, struct fy_eventp *fye s_flags = emit->s_flags; s_indent = emit->s_indent; + xstyle = fye->mapping_start.mapping_start->type == FYTT_BLOCK_MAPPING_START ? + FYNS_BLOCK : FYNS_FLOW; + fy_emit_common_node_preamble(emit, fye->mapping_start.anchor, fye->mapping_start.tag, emit->s_flags, emit->s_indent); /* create new context */ @@ -2963,9 +2997,9 @@ static int fy_emit_streaming_node(struct fy_emitter *emit, struct fy_eventp *fye sc->flags = emit->s_flags & (DDNF_ROOT | DDNF_SEQ | DDNF_MAP); sc->indent = emit->s_indent; sc->empty = fy_emit_streaming_mapping_empty(emit); - sc->flow_token = fye->mapping_start.mapping_start && - fye->mapping_start.mapping_start->type == FYTT_FLOW_MAPPING_START; + sc->flow_token = xstyle == FYNS_FLOW; sc->flow = !!(s_flags & DDNF_FLOW); + sc->xstyle = xstyle; sc->old_indent = sc->indent; sc->s_flags = s_flags; sc->s_indent = s_indent; diff --git a/contrib/libs/libfyaml/src/lib/fy-emit.h b/contrib/libs/libfyaml/src/lib/fy-emit.h index 3bbd8b5f1c..6afe3997e5 100644 --- a/contrib/libs/libfyaml/src/lib/fy-emit.h +++ b/contrib/libs/libfyaml/src/lib/fy-emit.h @@ -53,6 +53,7 @@ struct fy_emit_save_ctx { bool flow_token : 1; bool flow : 1; bool empty : 1; + enum fy_node_style xstyle; int old_indent; int flags; int indent; diff --git a/contrib/libs/libfyaml/src/lib/fy-parse.c b/contrib/libs/libfyaml/src/lib/fy-parse.c index 07b5045efc..c895002f03 100644 --- a/contrib/libs/libfyaml/src/lib/fy-parse.c +++ b/contrib/libs/libfyaml/src/lib/fy-parse.c @@ -820,6 +820,9 @@ void fy_parse_cleanup(struct fy_parser *fyp) struct fy_eventp *fyep; struct fy_token *fyt; + fy_input_unref(fyp->last_event_handle.fyi); + fy_atom_reset(&fyp->last_event_handle); + fy_composer_destroy(fyp->fyc); fy_document_builder_destroy(fyp->fydb); @@ -5261,6 +5264,7 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) size_t handle_size; struct fy_token *fyt_td; struct fy_token *fytn; + struct fy_atom *ev_handle = NULL; fyds = fyp->current_document_state; assert(fyds); @@ -5280,6 +5284,7 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->type = FYET_ALIAS; fye->alias.anchor = fy_scan_remove(fyp, fyt); + ev_handle = &fye->alias.anchor->handle; goto return_ok; } @@ -5338,6 +5343,8 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->sequence_start.sequence_start = fytn; fy_parse_state_set(fyp, FYPS_INDENTLESS_SEQUENCE_ENTRY); + + ev_handle = &fye->sequence_start.sequence_start->handle; goto return_ok; } @@ -5353,6 +5360,8 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->scalar.anchor = anchor; fye->scalar.tag = tag; fye->scalar.value = fy_scan_remove(fyp, fyt); + + ev_handle = &fye->scalar.value->handle; goto return_ok; } @@ -5368,6 +5377,8 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->sequence_start.tag = tag; fye->sequence_start.sequence_start = fy_scan_remove(fyp, fyt); fy_parse_state_set(fyp, FYPS_FLOW_SEQUENCE_FIRST_ENTRY); + + ev_handle = &fye->sequence_start.sequence_start->handle; goto return_ok; } @@ -5383,6 +5394,8 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->mapping_start.tag = tag; fye->mapping_start.mapping_start = fy_scan_remove(fyp, fyt); fy_parse_state_set(fyp, FYPS_FLOW_MAPPING_FIRST_KEY); + + ev_handle = &fye->mapping_start.mapping_start->handle; goto return_ok; } @@ -5398,6 +5411,8 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->sequence_start.tag = tag; fye->sequence_start.sequence_start = fy_scan_remove(fyp, fyt); fy_parse_state_set(fyp, FYPS_BLOCK_SEQUENCE_FIRST_ENTRY); + + ev_handle = &fye->sequence_start.sequence_start->handle; goto return_ok; } @@ -5413,6 +5428,8 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->mapping_start.tag = tag; fye->mapping_start.mapping_start = fy_scan_remove(fyp, fyt); fy_parse_state_set(fyp, FYPS_BLOCK_MAPPING_FIRST_KEY); + + ev_handle = &fye->mapping_start.mapping_start->handle; goto return_ok; } @@ -5455,9 +5472,24 @@ fy_parse_node(struct fy_parser *fyp, struct fy_token *fyt, bool is_block) fye->type = FYET_SCALAR; fye->scalar.anchor = anchor; fye->scalar.tag = tag; - fye->scalar.value = NULL; + + /* copy atom from the token and set to zero size at start */ + fye->scalar.value = fy_token_create_rl( + fyp->recycled_token_list, FYTT_SCALAR, &fyp->last_event_handle, FYSS_PLAIN); + fyp_error_check(fyp, fye->scalar.value, err_out, + "failed to allocate SCALAR token()"); + /* mark it as a special value */ + fye->scalar.value->scalar.is_null = true; return_ok: + if (ev_handle) { + fy_input_unref(fyp->last_event_handle.fyi); + fyp->last_event_handle = *ev_handle; + fyp->last_event_handle.start_mark = fyp->last_event_handle.end_mark; + fy_atom_reset_storage_hints(&fyp->last_event_handle); + fy_input_ref(fyp->last_event_handle.fyi); + } + fyp_parse_debug(fyp, "parse_node: > %s", fy_event_type_txt[fye->type]); @@ -5485,8 +5517,16 @@ fy_parse_empty_scalar(struct fy_parser *fyp) fye->type = FYET_SCALAR; fye->scalar.anchor = NULL; fye->scalar.tag = NULL; - fye->scalar.value = NULL; + + /* for empty scalar the last event handle does not change, only */ + fye->scalar.value = fy_token_create_rl( + fyp->recycled_token_list, FYTT_SCALAR, &fyp->last_event_handle, FYSS_PLAIN); + fyp_error_check(fyp, fye->scalar.value, err_out, + "failed to allocate SCALAR token()"); + /* mark it as a special value */ + fye->scalar.value->scalar.is_null = true; return fyep; + err_out: return NULL; } @@ -5530,6 +5570,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) struct fy_token *version_directive; struct fy_token_list tag_directives; const struct fy_mark *fym; + struct fy_atom handle, *ev_handle; struct fy_token *fytn; char tbuf[16] __FY_DEBUG_UNUSED__; int rc; @@ -5574,6 +5615,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = NULL; fye = NULL; + ev_handle = NULL; orig_state = fyp->state; switch (fyp->state) { @@ -5603,7 +5645,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyp->stream_has_content = false; - return fyep; + ev_handle = &fye->stream_start.stream_start->handle; + break; case FYPS_IMPLICIT_DOCUMENT_START: @@ -5707,7 +5750,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fy_parse_state_set(fyp, fy_parse_have_more_inputs(fyp) ? FYPS_NONE : FYPS_END); - return fyep; + ev_handle = &fye->stream_end.stream_end->handle; + break; } fyep = fy_parse_eventp_alloc(fyp); @@ -5745,7 +5789,16 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) memset(&fyds->start_mark, 0, sizeof(fyds->start_mark)); if (fyt->type != FYTT_DOCUMENT_START) { - fye->document_start.document_start = NULL; + + /* copy atom from the token and set to zero size at start */ + handle = fyt->handle; + handle.end_mark = handle.start_mark; + fy_atom_reset_storage_hints(&handle); + + fye->document_start.document_start = fy_token_create_rl( + fyp->recycled_token_list, FYTT_DOCUMENT_START, &handle); + fyp_error_check(fyp, fye->document_start.document_start, err_out, + "failed to allocate DOCUMENT_START token()"); fyds->start_implicit = true; fyp_parse_debug(fyp, "document_start_implicit=true"); @@ -5773,7 +5826,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fye->document_start.document_state = fy_document_state_ref(fyds); fye->document_start.implicit = fyds->start_implicit; - return fyep; + ev_handle = &fye->document_start.document_start->handle; + break; case FYPS_DOCUMENT_END: @@ -5811,8 +5865,14 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) /* document end */ fye->type = FYET_DOCUMENT_END; if (fyt->type == FYTT_DOCUMENT_END) { - /* TODO pull the document end token and deliver */ - fye->document_end.document_end = NULL; + + handle = fyt->handle; + fy_atom_reset_storage_hints(&handle); + + fye->document_end.document_end = fy_token_create_rl( + fyp->recycled_token_list, FYTT_DOCUMENT_END, &handle); + fyp_error_check(fyp, fye->document_end.document_end, err_out, + "failed to allocate DOCUMENT_END token()"); fyds->end_implicit = false; /* reset document has content flag */ @@ -5823,7 +5883,15 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyp->had_directives = false; } else { - fye->document_end.document_end = NULL; + + handle = fyt->handle; + handle.end_mark = handle.start_mark; + fy_atom_reset_storage_hints(&handle); + + fye->document_end.document_end = fy_token_create_rl( + fyp->recycled_token_list, FYTT_DOCUMENT_END, &handle); + fyp_error_check(fyp, fye->document_end.document_end, err_out, + "failed to allocate DOCUMENT_END token()"); fyds->end_implicit = true; } @@ -5845,7 +5913,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fy_parse_state_set(fyp, FYPS_SINGLE_DOCUMENT_END); } - return fyep; + ev_handle = &fye->document_end.document_end->handle; + break; case FYPS_DOCUMENT_CONTENT: @@ -5867,7 +5936,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; } fyp->document_has_content = true; @@ -5881,7 +5950,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyp->state == FYPS_DOCUMENT_CONTENT); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; case FYPS_BLOCK_SEQUENCE_FIRST_ENTRY: is_first = true; @@ -5932,14 +6001,14 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, true); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } fy_parse_state_set(fyp, FYPS_BLOCK_SEQUENCE_ENTRY); fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; } /* FYTT_BLOCK_END */ @@ -5966,7 +6035,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) } else fye->sequence_end.sequence_end = fy_scan_remove(fyp, fyt); - return fyep; + ev_handle = &fye->sequence_end.sequence_end->handle; + break; case FYPS_BLOCK_MAPPING_FIRST_KEY: is_first = true; @@ -6025,14 +6095,14 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, true); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } fy_parse_state_set(fyp, FYPS_BLOCK_MAPPING_VALUE); fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; } fyep = fy_parse_eventp_alloc(fyp); @@ -6044,7 +6114,9 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fy_parse_state_set(fyp, fy_parse_state_pop(fyp)); fye->type = FYET_MAPPING_END; fye->mapping_end.mapping_end = fy_scan_remove(fyp, fyt); - return fyep; + + ev_handle = &fye->mapping_end.mapping_end->handle; + break; case FYPS_BLOCK_MAPPING_VALUE: @@ -6070,7 +6142,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, true); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } } @@ -6079,7 +6151,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; case FYPS_FLOW_SEQUENCE_FIRST_ENTRY: is_first = true; @@ -6123,7 +6195,9 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fye->mapping_start.anchor = NULL; fye->mapping_start.tag = NULL; fye->mapping_start.mapping_start = fy_scan_remove(fyp, fyt); - return fyep; + + ev_handle = &fye->mapping_start.mapping_start->handle; + break; } if (fyt->type != FYTT_FLOW_SEQUENCE_END) { @@ -6134,7 +6208,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, false); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } } @@ -6154,7 +6228,9 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fye->type = FYET_SEQUENCE_END; fye->sequence_end.sequence_end = fy_scan_remove(fyp, fyt); - return fyep; + + ev_handle = &fye->sequence_end.sequence_end->handle; + break; case FYPS_FLOW_SEQUENCE_ENTRY_MAPPING_KEY: if (fyt->type != FYTT_VALUE && fyt->type != FYTT_FLOW_ENTRY && @@ -6166,7 +6242,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, false); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } /* empty keys are not allowed in JSON mode */ @@ -6179,7 +6255,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; case FYPS_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE: if (fyt->type == FYTT_VALUE) { @@ -6198,7 +6274,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, false); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } } @@ -6212,7 +6288,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; case FYPS_FLOW_SEQUENCE_ENTRY_MAPPING_END: fy_parse_state_set(fyp, FYPS_FLOW_SEQUENCE_ENTRY); @@ -6235,7 +6311,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fye->mapping_end.mapping_end = fytn; - return fyep; + ev_handle = &fye->mapping_end.mapping_end->handle; + break; case FYPS_FLOW_MAPPING_FIRST_KEY: is_first = true; @@ -6289,7 +6366,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, false); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } fy_parse_state_set(fyp, FYPS_FLOW_MAPPING_VALUE); @@ -6297,7 +6374,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; } if (fyt->type != FYTT_FLOW_MAPPING_END) { @@ -6314,7 +6391,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, false); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } } @@ -6328,7 +6405,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fye->type = FYET_MAPPING_END; fye->mapping_end.mapping_end = fy_scan_remove(fyp, fyt); - return fyep; + ev_handle = &fye->mapping_end.mapping_end->handle; + break; case FYPS_FLOW_MAPPING_VALUE: if (fyt->type == FYTT_VALUE) { @@ -6350,7 +6428,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_node(fyp, fyt, false); fyp_error_check(fyp, fyep, err_out, "fy_parse_node() failed"); - return fyep; + break; } } @@ -6364,7 +6442,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; case FYPS_FLOW_MAPPING_EMPTY_VALUE: fy_parse_state_set(fyp, FYPS_FLOW_MAPPING_KEY); @@ -6372,7 +6450,7 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fyep = fy_parse_empty_scalar(fyp); fyp_error_check(fyp, fyep, err_out, "fy_parse_empty_scalar() failed"); - return fyep; + break; case FYPS_SINGLE_DOCUMENT_END: @@ -6395,7 +6473,8 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) fy_parse_state_set(fyp, fy_parse_have_more_inputs(fyp) ? FYPS_NONE : FYPS_END); - return fyep; + ev_handle = &fye->stream_end.stream_end->handle; + break; case FYPS_END: /* should never happen */ @@ -6403,6 +6482,18 @@ static struct fy_eventp *fy_parse_internal(struct fy_parser *fyp) break; } + assert(fyep); + + if (ev_handle) { + fy_input_unref(fyp->last_event_handle.fyi); + fyp->last_event_handle = *ev_handle; + fyp->last_event_handle.start_mark = fyp->last_event_handle.end_mark; + fy_atom_reset_storage_hints(&handle); + fy_input_ref(fyp->last_event_handle.fyi); + } + + return fyep; + err_out: fy_token_unref_rl(fyp->recycled_token_list, version_directive); fy_token_list_unref_all_rl(fyp->recycled_token_list, &tag_directives); @@ -6526,6 +6617,9 @@ static void fy_parse_input_reset(struct fy_parser *fyp) fyp->pending_complex_key_column = -1; fyp->last_block_mapping_key_line = -1; + + fy_input_unref(fyp->last_event_handle.fyi); + fy_atom_reset(&fyp->last_event_handle); } int fy_parser_set_input_file(struct fy_parser *fyp, const char *file) diff --git a/contrib/libs/libfyaml/src/lib/fy-parse.h b/contrib/libs/libfyaml/src/lib/fy-parse.h index 8ffae8c93d..6a6a98e72e 100644 --- a/contrib/libs/libfyaml/src/lib/fy-parse.h +++ b/contrib/libs/libfyaml/src/lib/fy-parse.h @@ -223,6 +223,9 @@ struct fy_parser { struct fy_composer *fyc; fy_parse_composer_cb fyc_cb; void *fyc_userdata; + + /* last generated event atom */ + struct fy_atom last_event_handle; }; static inline struct fy_input * diff --git a/contrib/libs/libfyaml/src/lib/fy-token.c b/contrib/libs/libfyaml/src/lib/fy-token.c index 91efa89f33..47a2fdfb7e 100644 --- a/contrib/libs/libfyaml/src/lib/fy-token.c +++ b/contrib/libs/libfyaml/src/lib/fy-token.c @@ -426,6 +426,7 @@ struct fy_token *fy_token_vcreate_rl(struct fy_token_list *fytl, enum fy_token_t fyt->scalar.path_key = NULL; fyt->scalar.path_key_len = 0; fyt->scalar.path_key_storage = NULL; + fyt->scalar.is_null = false; /* by default the scalar is not NULL */ break; case FYTT_TAG: fyt->tag.skip = va_arg(ap, unsigned int); @@ -640,7 +641,7 @@ int fy_token_text_analyze(struct fy_token *fyt) const char *s, *e; const char *value = NULL; enum fy_atom_style style; - int c, w, cn, cp, col; + int c, w, cn, cnn, cp, col; size_t len; int flags; @@ -708,16 +709,22 @@ int fy_token_text_analyze(struct fy_token *fyt) flags &= ~FYTTAF_CAN_BE_FOLDED; /* plain scalars can't start with any indicator (or space/lb) */ - if ((flags & (FYTTAF_CAN_BE_PLAIN | FYTTAF_CAN_BE_PLAIN_FLOW)) && - (fy_is_indicator(cn) || fy_token_is_lb(fyt, cn) || fy_is_ws(cn))) - flags &= ~(FYTTAF_CAN_BE_PLAIN | - FYTTAF_CAN_BE_PLAIN_FLOW); + if ((flags & (FYTTAF_CAN_BE_PLAIN | FYTTAF_CAN_BE_PLAIN_FLOW))) { + if (fy_is_start_indicator(cn) || fy_token_is_lb(fyt, cn) || fy_is_ws(cn)) + flags &= ~(FYTTAF_CAN_BE_PLAIN | FYTTAF_CAN_BE_PLAIN_FLOW); + } /* plain scalars in flow mode can't start with a flow indicator */ if ((flags & FYTTAF_CAN_BE_PLAIN_FLOW) && fy_is_flow_indicator(cn)) flags &= ~FYTTAF_CAN_BE_PLAIN_FLOW; + if ((flags & (FYTTAF_CAN_BE_PLAIN | FYTTAF_CAN_BE_PLAIN_FLOW))) { + cnn = fy_utf8_get(s, e - s, &w); + if (fy_is_ws(cnn) && fy_is_indicator_before_space(cn)) + flags &= ~(FYTTAF_CAN_BE_PLAIN | FYTTAF_CAN_BE_PLAIN_FLOW); + } + /* plain unquoted path keys can only start with [a-zA-Z_] */ if ((flags & FYTTAF_CAN_BE_UNQUOTED_PATH_KEY) && !fy_is_first_alpha(cn)) @@ -1408,7 +1415,7 @@ unsigned int fy_analyze_scalar_content(const char *data, size_t size, /* comment indicator can't be present after a space or lb */ /* : followed by blank can't be any plain */ - if (flags & (FYACF_BLOCK_PLAIN | FYACF_FLOW_PLAIN) && + if ((flags & (FYACF_BLOCK_PLAIN | FYACF_FLOW_PLAIN)) && (((fy_is_blank(c) || fy_is_generic_lb_m(c, lb_mode)) && nextc == '#') || (c == ':' && fy_is_blankz_m(nextc, lb_mode)))) flags &= ~(FYACF_BLOCK_PLAIN | FYACF_FLOW_PLAIN); @@ -1867,3 +1874,9 @@ bool fy_token_has_any_comment(struct fy_token *fyt) } return false; } + +bool +fy_token_scalar_is_null(struct fy_token *fyt) +{ + return !fyt || fyt->type != FYTT_SCALAR || fyt->scalar.is_null; +} diff --git a/contrib/libs/libfyaml/src/lib/fy-token.h b/contrib/libs/libfyaml/src/lib/fy-token.h index 8f904095f5..b35d5fc923 100644 --- a/contrib/libs/libfyaml/src/lib/fy-token.h +++ b/contrib/libs/libfyaml/src/lib/fy-token.h @@ -105,6 +105,7 @@ struct fy_token { const char *path_key; size_t path_key_len; char *path_key_storage; /* if this is not null, it's \0 terminated */ + bool is_null; /* special case; the scalar was NULL */ } scalar; struct { unsigned int skip; |