E0xxx: Lexical and syntax analysis errors
This page is generated by scripts/docs/gen-error-code-docs.py from the define_codes! registry in src/util/diagnostic/codes/ and locales/en.json. Do not edit it by hand. Change the wording in locales/*.json, change the code table in define_codes!, then rerun python scripts/docs/gen-error-code-docs.py.
Errors produced by the lexer and the parser.
This family holds 12 codes, all registered in the define_codes! registry, with the category Lexer / Parser. See the error code index for the complete inventory.
Code Overview
| Code | Name | Category | span exempt | Template | Emission sites |
|---|---|---|---|---|---|
E0001 | Invalid character | Lexer | No | Invalid character: '{char}' | ✅ 1 site |
E0002 | Invalid number literal | Lexer | No | Invalid number literal: '{literal}' | ✅ 1 site |
E0003 | Unterminated string | Lexer | No | string started at line {line} is unterminated | ⚠ Not yet emitted |
E0004 | Invalid character literal | Lexer | No | invalid character literal: '{literal}' | ⚠ Not yet emitted |
E0010 | Expected token | Parser | No | expected {expected}, found {found} | ✅ 6 sites |
E0011 | Unexpected token | Parser | No | Unexpected token: '{token}' | ✅ 19 sites |
E0012 | Invalid syntax | Parser | No | Invalid syntax: {reason} | ✅ 14 sites |
E0013 | Mismatched brackets | Parser | No | Mismatched {bracket_type}: opened at line {open_line}, column {open_col}, not closed | ⚠ Not yet emitted |
E0014 | Missing semicolon | Parser | No | Missing semicolon after {statement} | ⚠ Not yet emitted |
E0016 | Expected expression | Parser | No | Expected expression: {context} | ✅ 4 sites |
E0018 | Keyword used as name | Parser | No | '{keyword}' is a keyword and cannot be used as a name | ✅ 1 site |
E0019 | Expression nesting too deep | Parser | No | expression nesting exceeds the maximum recursion depth ({limit}) | ✅ 1 site |
Code Details
E0001: Invalid character
- Category:
Lexer - span exempt: No
- Constructor:
ErrorCodeDefinition::invalid_character(char) - Template:
Invalid character: '{char}' - Message: Source code contains illegal characters
- Help: Remove the illegal character or use a valid encoding
- Emission sites:
src/frontend/core/lexer/tokens.rs:63 - Source comment name:
无效字符
E0002: Invalid number literal
- Category:
Lexer - span exempt: No
- Constructor:
ErrorCodeDefinition::invalid_number_literal(literal) - Template:
Invalid number literal: '{literal}' - Message: Number literal has incorrect format
- Help: Check the format of the number literal
- Emission sites:
src/frontend/core/lexer/tokens.rs:58 - Source comment name:
无效数字字面量
E0003: Unterminated string
- Category:
Lexer - span exempt: No
- Constructor:
ErrorCodeDefinition::unterminated_string(line) - Template:
string started at line {line} is unterminated - Message: string literal is missing a closing quote
- Help: add a closing quote to the string
- Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
- Source comment name:
未终止的字符串
E0004: Invalid character literal
- Category:
Lexer - span exempt: No
- Constructor:
ErrorCodeDefinition::invalid_char_literal(literal) - Template:
invalid character literal: '{literal}' - Message: character literal is incorrect
- Help: character literal can only contain a single character
- Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
- Source comment name:
无效字符字面量
E0010: Expected token
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::expected_token(expected, found) - Template:
expected {expected}, found {found} - Message: parser expected a specific token
- Help: check the syntax and add the expected token
- Emission sites:
src/frontend/core/parser/parser_state.rs:295,src/frontend/core/parser/pratt/nud.rs:1052,src/frontend/core/parser/pratt/nud.rs:1072and 6 more sites - Source comment name:
期望的令牌
E0011: Unexpected token
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::unexpected_token(token) - Template:
Unexpected token: '{token}' - Message: Unexpected token encountered
- Help: Remove or replace the unexpected token
- Emission sites:
src/driver/arms.rs:94,src/frontend/compiler.rs:178,src/frontend/core/parser/mod.rs:65and 19 more sites - Source comment name:
意外的令牌
E0012: Invalid syntax
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::invalid_syntax(reason) - Template:
Invalid syntax: {reason} - Message: Syntax error in expression or statement
- Help: Check the syntax of the expression or statement
- Emission sites:
src/frontend/core/lexer/tokens.rs:44,src/frontend/core/lexer/tokens.rs:48,src/frontend/core/lexer/tokens.rs:53and 14 more sites - Source comment name:
无效语法
E0013: Mismatched brackets
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::mismatched_brackets(bracket_type, open_line, open_col) - Template:
Mismatched {bracket_type}: opened at line {open_line}, column {open_col}, not closed - Message: Parentheses, square brackets, or curly braces are mismatched
- Help: Ensure all brackets are properly closed
- Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
- Source comment name:
不匹配的括号
E0014: Missing semicolon
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::missing_semicolon(statement) - Template:
Missing semicolon after {statement} - Message: Statement is missing a semicolon
- Help: Add a semicolon at the end of the statement
- Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
- Source comment name:
缺少分号
E0016: Expected expression
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::expected_expression(context) - Template:
Expected expression: {context} - Message: The parser expected an expression
- Help: provide a valid expression at this position
- Emission sites:
src/frontend/core/parser/pratt/nud.rs:136,src/frontend/core/parser/pratt/nud.rs:176,src/frontend/core/parser/pratt/nud.rs:193and 4 more sites - Source comment name:
期望表达式
E0018: Keyword used as name
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::keyword_as_name(keyword) - Template:
'{keyword}' is a keyword and cannot be used as a name - Message: keywords cannot be used as variable or expression names
- Help: use a different identifier in place of the keyword
- Emission sites:
src/frontend/core/parser/parser_state.rs:549 - Source comment name:
关键字作变量名
E0019: Expression nesting too deep
- Category:
Parser - span exempt: No
- Constructor:
ErrorCodeDefinition::expression_too_deep(limit) - Template:
expression nesting exceeds the maximum recursion depth ({limit}) - Message: expressions nested deeper than {limit} levels exceed the parser recursion limit
- Help: simplify the expression or split deeply nested parts into intermediate variables or helper functions
- Emission sites:
src/frontend/core/parser/parser_state.rs:111 - Source comment name:
解析递归深度超限(issue #540:深嵌套表达式此前让编译器栈溢出
