Skip to content

handle line advancement when parsing AnchorPrefix and TagPrefix #368

@alienczf

Description

@alienczf

Description

when parsing anchor_prefix and tag prefix, the code currently doesn't advance line if we happend to consume newline character.

this results in the subsequent tokens being labelled with wrong line number

            case lexical_token_t::ANCHOR_PREFIX:
            case lexical_token_t::TAG_PREFIX:
                deserialize_node_properties(lexer, type, line, indent);

                // Skip updating the current indent to avoid stacking a wrong indentation.
                //
                //   &foo bar: baz
                //   ^
                //   the correct indent width for the "bar" node key.

+               line = lexer.get_lines_processed();
                continue;

Reproduction steps

sample.yaml

values:
- &id070 !XXX
  source: !YYY
    name: fv
  include: false
#include "fkYAML/node.hpp"
int main(int argc, char* argv[]) {
  std::ifstream ifs("/tmp/sample.yaml");
  fkyaml::node root = fkyaml::node::deserialize(ifs);
  return 0;
}

Expected vs. actual results

wrongly throws indentation error

Minimal code example

No response

Error messages

No response

Compiler and operating system

clang17 ubuntu22

Library version

develop

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions