fktn-k / fkYAML

A C++ header-only YAML library
MIT License
70 stars 7 forks source link

Bug on parinsing trivial YAML #413

Open ebertolazzi opened 4 hours ago

ebertolazzi commented 4 hours ago

Description

The parse failed to parse a single item

Reproduction steps

If you parse the following YAML

b: 1e-1

I obtain the error:

Failed to convert a scalar to an integer. (at line 0, column 3)

If you use

b: 0.1e-2

all is ok.

It seems that the parser try to force an integer for number in engineering form that start with a integer.

Expected vs. actual results

nope

Minimal code example

No response

Error messages

No response

Compiler and operating system

clang MAC OS

Library version

0.3.13

Validation

ebertolazzi commented 3 hours ago

This workaround

    case node_type::INTEGER: {
        integer_type integer = 0;
        bool converted = detail::atoi(token.begin(), token.end(), integer);
        //@@@@@@@@@@@@@@@@@@ WORKAROUND @@@@@@@@@@@@@@@@@@@@@
        if ( !converted ) {
          float_number_type float_val = 0;
          bool converted = detail::atof(token.begin(), token.end(), float_val);
          if FK_YAML_UNLIKELY (!converted) {
            throw parse_error("Failed to convert a scalar to an integer or float.", m_line, m_indent);
          }
          node = basic_node_type(float_val);
        } else {
          node = basic_node_type(integer);
        }
        break;
    }

in

basic_node_type create_scalar_node(node_type type, str_view token)

permit to parse the file but it shuild be better to change

node_type decide_value_type(lexical_token_t lex_type, tag_t tag_type, str_view token) const noexcept

in order to detect the correct type.