pest-parser / pest

The Elegant Parser
https://pest.rs
Apache License 2.0
4.63k stars 259 forks source link

the error position isn't accurate #870

Open taodongl opened 1 year ago

taodongl commented 1 year ago

Describe the bug I want to use pest to analyze syntax issue of files (I used to deal with it using Antlr in Java lang), but I can't get right position.

To Reproduce

use pest::Parser;
use pest_grammars::json::*;

const DATA: &str = r#"{"name": "hello, the\' world"}"#;

fn main() {
    let ret = JsonParser::parse(Rule::json, DATA);
    println!("{:?}", ret);
}

Expected behavior

{"name": "hello, the\' world"}
                    ^--- issue position

Current behavior

{"name": "hello, the\' world"}
         ^--- issue position
tomtau commented 1 year ago

I guess it's because it points to the beginning of the rule where the issue occurred?

taodongl commented 1 year ago

@tomtau oh yes, my example isn't good (pest and antlr report the same position). I use a new json example:

{"name": "hello, the" world"}

For pest: location: Pos(0), line_col: Pos((1, 1)) For antlr: line 1:22 token recognition error at: 'w'

tomtau commented 10 months ago

BTW a similar issue: https://github.com/pest-parser/pest/discussions/955 which was resolved by correcting the grammar.