Skip to content

How to get the correct col for a multiline string #402

@mariusgreuel

Description

@mariusgreuel

Thanks for rapidyaml!

I have an embedded script in a YAML file, and I want to provide users with exact line/col information of possible syntax errors. I am having trouble getting the correct column for a multiline string.

For instance, for the print() statement in

script: |
  print()

I expect location.col to be 2.

This is how I do it, not sure if I use the correct API.

TEST(rapidyaml, fails)
{
    ryml::Parser parser{ ryml::ParserOptions().locations(true) };
    auto tree = parser.parse_in_arena("file", "script: |\n  print()");
    auto script = tree["script"];
    auto val = script.val();
    EXPECT_TRUE(val == "print()\n");
    auto location = parser.val_location(val.str);
    EXPECT_EQ(location.line, 1);
    EXPECT_EQ(location.col, 2);
}

however, the test fails with col == 0:

  location.col
    Which is: 0
  2

Any help would be greatly appreciated. TIA!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions