Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mariusgreuel opened this issue Feb 9, 2024 · 0 comments
Open

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

mariusgreuel opened this issue Feb 9, 2024 · 0 comments

Comments

@mariusgreuel
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant