Report import ending syntax error

This commit is contained in:
Agus Zubiaga 2024-05-06 22:22:00 -03:00
parent 8418610dd9
commit bfb77b78cb
No known key found for this signature in database
3 changed files with 53 additions and 4 deletions

View file

@ -4943,6 +4943,31 @@ mod test_reporting {
"###
);
test_report!(
unfinished_import_as_or_exposing,
indoc!(
r"
import svg.Path a
"
),
@r###"
UNFINISHED IMPORT in tmp/unfinished_import_as_or_exposing/Test.roc
I was partway through parsing an `import`, but I got stuck here:
4 import svg.Path a
^
I was expecting to see the `as` keyword, like:
import svg.Path as SvgPath
Or the `exposing` keyword, like:
import svg.Path exposing [arc, rx]
"###
);
test_report!(
ingested_file_import_ann_syntax_err,
indoc!(

View file

@ -548,6 +548,7 @@ pub enum EImport<'a> {
IndentAnnotation(Position),
Annotation(EType<'a>, Position),
Space(BadInputError, Position),
EndNewline(Position),
}
#[derive(Debug, Clone, PartialEq, Eq)]

View file

@ -1475,14 +1475,37 @@ fn to_import_report<'a>(
.indent(4),
]),
),
IndentAs(pos) | As(pos) | IndentExposing(pos) | Exposing(pos) | EndNewline(pos) => {
to_unfinished_import_report(
alloc,
lines,
filename,
*pos,
start,
alloc.stack([
alloc.concat([
alloc.reflow("I was expecting to see the "),
alloc.keyword("as"),
alloc.reflow(" keyword, like:"),
]),
alloc
.parser_suggestion("import svg.Path as SvgPath")
.indent(4),
alloc.concat([
alloc.reflow("Or the "),
alloc.keyword("exposing"),
alloc.reflow(" keyword, like:"),
]),
alloc
.parser_suggestion("import svg.Path exposing [arc, rx]")
.indent(4),
]),
)
}
Annotation(problem, pos) => to_type_report(alloc, lines, filename, problem, *pos),
Space(problem, pos) => to_space_report(alloc, lines, filename, problem, *pos),
IndentAs(_) => todo!(),
As(_) => todo!(),
IndentAlias(_) => todo!(),
Alias(_) => todo!(),
IndentExposing(_) => todo!(),
Exposing(_) => todo!(),
ExposingListStart(_) => todo!(),
ExposedName(_) => todo!(),
ExposingListEnd(_) => todo!(),