rhaiscript / rhaiscript/rhai

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

Open
#1,172 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
5.7k
Forks
249
Avg merge
1d 14h
Merged PRs (30d)
23

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Rust example from the issue and inspect the parser path that reports MissingToken for the omitted semicolon. Trace how whitespace and the following statement determine the reported position, then run the relevant parser tests or add a regression case. Done means the diagnostic points to the missing terminator or clearly identifies that it was expected before the next statement.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.