Improve selectors' diagnostics
This commit is contained in:
parent
c58bcd4aac
commit
e29ffb2a9c
14 changed files with 1473 additions and 195 deletions
|
|
@ -16,40 +16,43 @@ use rottlib::parser::Parser;
|
|||
/// Keep these small: the goal is to inspect lexer diagnostics and delimiter
|
||||
/// recovery behavior, not full parser behavior.
|
||||
const TEST_CASES: &[(&str, &str)] = &[
|
||||
// P0027: `else` without a matching `if`
|
||||
//
|
||||
// `else` cannot start a standalone block item. The parser should report
|
||||
// P0027 at `else`, then recover by bailing out of the current block.
|
||||
// P0031 - FunctionCallArgumentMissingComma
|
||||
(
|
||||
"files/P0027_01.uc",
|
||||
"{\n local bool bReady;\n bReady = CheckReady();\n else { StartMatch(); }\n NotifyReady();\n}\n",
|
||||
"files/P0031_01.uc",
|
||||
"{\n Func(A B);\n Log(\"after\");\n}\n",
|
||||
),
|
||||
|
||||
// P0027: `case` outside of a `switch`
|
||||
//
|
||||
// `case` is a switch-arm boundary, not a valid statement or expression
|
||||
// starter in an ordinary block.
|
||||
(
|
||||
"files/P0027_02.uc",
|
||||
"{ local int Count; Count = 3; case 3: Count++; UpdateHud();}",
|
||||
"files/P0031_02.uc",
|
||||
"{\n Func\n (A 123);\n Log(\"after\");\n}\n",
|
||||
),
|
||||
|
||||
// P0027: standalone `until` without a preceding `do`
|
||||
//
|
||||
// `until` is only meaningful as the tail of `do ... until`, so it should
|
||||
// not be accepted as a normal block item.
|
||||
(
|
||||
"files/P0027_03.uc",
|
||||
"{\n local bool bDone;\n bDone = false;\n until (bDone)\n TickWork();\n}\n",
|
||||
"files/P0031_03.uc",
|
||||
"{\n Func(\n A\n new SomeClass\n );\n Log(\"after\");\n}\n",
|
||||
),
|
||||
|
||||
// P0027: preprocessor/exec directive inside a statement block
|
||||
//
|
||||
// `#exec` is declaration/top-level-like syntax, not a valid statement or
|
||||
// expression inside a braced statement block.
|
||||
// P0032 - FunctionCallMissingClosingParenthesis
|
||||
("files/P0032_01.uc", "Func("),
|
||||
("files/P0032_02.uc", "Func\n(\n A,"),
|
||||
("files/P0032_03.uc", "Func(A,\n B,"),
|
||||
(
|
||||
"files/P0027_04.uc",
|
||||
"{\n local int Count;\n Count = 0;\n #exec TEXTURE IMPORT NAME=Bad FILE=Bad.bmp\n Count++;\n}\n",
|
||||
"files/P0032_04.uc",
|
||||
"{\n Func\n (\n A,\n B,\n",
|
||||
),
|
||||
// P0033 - FunctionCallUnexpectedTokenInArgumentList
|
||||
(
|
||||
"files/P0033_01.uc",
|
||||
"{\n Func(A #, B);\n Log(\"after\");\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0033_02.uc",
|
||||
"{\n Func\n (A\n :,\n B);\n Log(\"after\");\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0033_03.uc",
|
||||
"{\n Func(\n A ?\n , B\n );\n Log(\"after\");\n}\n",
|
||||
),
|
||||
(
|
||||
"files/P0033_04.uc",
|
||||
"{\n Func\n (\n A\n #,\n B\n );\n Log(\"after\");\n}\n",
|
||||
),
|
||||
];
|
||||
|
||||
|
|
@ -135,4 +138,4 @@ fn render_diagnostic(
|
|||
_colors: bool,
|
||||
) {
|
||||
diag.render(file, file_name.unwrap_or("<default>"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue