Skip to content

Syntax error position for terminating ';' points to next statement #1172

Description

@ksjdragon

For an example script like this:

use rhai::Engine;

fn main() {
    let engine = Engine::new();

    let main_script = r#"
let x = 1+2

let y = x;
y
"#
    .trim();

    let err = engine.eval::<i32>(main_script);
    println!("{err:?}");
}

The resulting error will be
Err(ErrorParsing(MissingToken(";", "to terminate this statement"), 3:1))
where 3:1 becomes "let y = x", that is, the statement after the missing statement.

I would assume this occurs because the parser will ignore whitespace until it scans a terminator, but
I think this makes the error message unclear, since it makes it look like the next statement is the one
that is missing the terminator.

If the parser doesn't keep track of spans, perhaps at least changing the message to be "expected terminator ; before this statement" or something of that nature.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions