tripon[github]

diagnostic codes / Parser

E0101 unexpected-token

The token here cannot start what the grammar expects.

E0101unexpected-tokensee spec/grammar.ebnf for what is legal here
severityerror
bandParser
in the v0 bootstrapemitted
explainralt explain E0101

This is the parser's general refusal. The message names the production it was in the middle of and the token it found instead. The grammar is published as `spec/grammar.ebnf`, so the message always has a page to point at.

What it looks like

e0101.tp
use tier core;

fn main() -> i32 {
    for i in 0..3 {
    }
    return 0;
}
ralt check e0101.tp
e0101.tp:4:9: error: expected ';' to end the statement, got identifier
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here
e0101.tp:4:11: error: expected ';' to end the statement, got identifier
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here
e0101.tp:4:14: error: expected ';' to end the statement, got number
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here
e0101.tp:4:16: error: expected a field name after '.', got '.'
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here
e0101.tp:4:17: error: expected a field name after '.', got number
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here
e0101.tp:4:17: error: expected ';' to end the statement, got number
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here
e0101.tp:4:19: error: expected ';' to end the statement, got '{'
  [E0101 unexpected-token] see spec/grammar.ebnf for what is legal here

`for` is not a keyword, so `for` lexes as an identifier, `i` as another, `in` as another, and the parser tries to read the whole line as a statement. One unsupported construct can therefore produce a wall of errors on one line. The earliest span is the one to read; the rest is the parser recovering statement by statement.

What to do

  • Replace the construct with a form the grammar has: `while` plus a counter, not `for`.
  • Read the message as a pair — what was expected, what arrived. `expected ';' ... got identifier` means the previous statement was not terminated.
  • When the first error is on a construct the language does not have, check the unsupported list in the reference before repairing the syntax.

Why the code exists

Recovery keeps going so one run reports every line that is wrong, not just the first. That is worth the cost of cascade diagnostics, which are always downstream of an earlier span.

What ralt explain says

ralt explain E0101
E0101
severity: error
name: unexpected-token
hint: see spec/grammar.ebnf for what is legal here

Related