mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
port headers!
This commit is contained in:
parent
86ef187d1c
commit
bd61a03ae0
2 changed files with 29 additions and 2 deletions
|
@ -8,7 +8,7 @@ use crate::header::{
|
||||||
use crate::ident::{lowercase_ident, unqualified_ident, uppercase_ident};
|
use crate::ident::{lowercase_ident, unqualified_ident, uppercase_ident};
|
||||||
use crate::parser::Progress::{self, *};
|
use crate::parser::Progress::{self, *};
|
||||||
use crate::parser::{
|
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,
|
EPackages, EProvides, ERequires, ETypedIdent, Parser, Row, State, SyntaxError,
|
||||||
};
|
};
|
||||||
use crate::string_literal;
|
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 let Ok((first_letter, width)) = char::from_utf8_slice_start(&buffer[chomped..]) {
|
||||||
if first_letter.is_uppercase() {
|
if first_letter.is_uppercase() {
|
||||||
chomped += width;
|
chomped += width;
|
||||||
|
} else if first_letter == '{' {
|
||||||
|
// the .{ starting a `Foo.{ bar, baz }` importing clauses
|
||||||
|
chomped -= width;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
return Err(Progress::MadeProgress);
|
return Err(Progress::MadeProgress);
|
||||||
}
|
}
|
||||||
|
@ -246,7 +250,7 @@ fn platform_header<'a>() -> impl Parser<'a, PlatformHeader<'a>, EHeader<'a>> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, SyntaxError<'a>> {
|
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, SyntaxError<'a>> {
|
||||||
// force that we pare until the end of the input
|
// 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)]
|
#[derive(Debug)]
|
||||||
struct ProvidesTo<'a> {
|
struct ProvidesTo<'a> {
|
||||||
|
|
|
@ -2800,6 +2800,29 @@ fn to_imports_report<'a>(
|
||||||
|
|
||||||
EImports::Space(error, row, col) => to_space_report(alloc, filename, &error, row, col),
|
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),
|
_ => todo!("unhandled parse error {:?}", parse_problem),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue