diff --git a/compiler/parse/src/module.rs b/compiler/parse/src/module.rs index 7c270bcd67..5e7a8e5535 100644 --- a/compiler/parse/src/module.rs +++ b/compiler/parse/src/module.rs @@ -8,7 +8,7 @@ use crate::header::{ use crate::ident::{lowercase_ident, unqualified_ident, uppercase_ident}; use crate::parser::Progress::{self, *}; use crate::parser::{ - backtrackable, end_of_file, loc, specialize, word1, Col, EEffects, EExposes, EHeader, EImports, + backtrackable, end_of_file, specialize, word1, Col, EEffects, EExposes, EHeader, EImports, EPackages, EProvides, ERequires, ETypedIdent, Parser, Row, State, SyntaxError, }; use crate::string_literal; @@ -95,6 +95,10 @@ fn chomp_module_name<'a>(buffer: &'a [u8]) -> Result<&'a str, Progress> { if let Ok((first_letter, width)) = char::from_utf8_slice_start(&buffer[chomped..]) { if first_letter.is_uppercase() { chomped += width; + } else if first_letter == '{' { + // the .{ starting a `Foo.{ bar, baz }` importing clauses + chomped -= width; + break; } else { return Err(Progress::MadeProgress); } @@ -246,7 +250,7 @@ fn platform_header<'a>() -> impl Parser<'a, PlatformHeader<'a>, EHeader<'a>> { #[inline(always)] pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located>>, SyntaxError<'a>> { // force that we pare until the end of the input - skip_second!(zero_or_more!(space0_around(loc(def(0)), 0)), end_of_file()) + skip_second!(zero_or_more!(space0_around(loc!(def(0)), 0)), end_of_file()) } #[derive(Debug)] struct ProvidesTo<'a> { diff --git a/compiler/reporting/src/error/parse.rs b/compiler/reporting/src/error/parse.rs index d485467733..cfa73606b7 100644 --- a/compiler/reporting/src/error/parse.rs +++ b/compiler/reporting/src/error/parse.rs @@ -2800,6 +2800,29 @@ fn to_imports_report<'a>( EImports::Space(error, row, col) => to_space_report(alloc, filename, &error, row, col), + EImports::ModuleName(row, col) => { + let surroundings = Region::from_rows_cols(start_row, start_col, row, col); + let region = Region::from_row_col(row, col); + + let doc = alloc.stack(vec![ + alloc.reflow(r"I am partway through parsing a header, but got stuck here:"), + alloc.region_with_subregion(surroundings, region), + alloc.concat(vec![ + alloc.reflow("I am expecting a module name next, like "), + alloc.parser_suggestion("BigNum"), + alloc.reflow(" or "), + alloc.parser_suggestion("Main"), + alloc.reflow(". Module names must start with an uppercase letter."), + ]), + ]); + + Report { + filename, + doc, + title: "WEIRD MODULE NAME".to_string(), + } + } + _ => todo!("unhandled parse error {:?}", parse_problem), } }