mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Merge branch 'main' into repl-no-color-no-header-flags
This commit is contained in:
commit
aadc74a37b
186 changed files with 5322 additions and 3927 deletions
|
@ -29,7 +29,6 @@ const WILDCARD_NOT_ALLOWED: &str = "WILDCARD NOT ALLOWED HERE";
|
|||
const UNDERSCORE_NOT_ALLOWED: &str = "UNDERSCORE NOT ALLOWED HERE";
|
||||
const UNUSED_ARG: &str = "UNUSED ARGUMENT";
|
||||
const MISSING_DEFINITION: &str = "MISSING DEFINITION";
|
||||
const UNKNOWN_GENERATES_WITH: &str = "UNKNOWN GENERATES FUNCTION";
|
||||
const DUPLICATE_FIELD_NAME: &str = "DUPLICATE FIELD NAME";
|
||||
const DUPLICATE_TAG_NAME: &str = "DUPLICATE TAG NAME";
|
||||
const INVALID_UNICODE: &str = "INVALID UNICODE";
|
||||
|
@ -308,20 +307,6 @@ pub fn can_problem<'b>(
|
|||
|
||||
title = MISSING_DEFINITION.to_string();
|
||||
}
|
||||
Problem::UnknownGeneratesWith(loc_ident) => {
|
||||
doc = alloc.stack([
|
||||
alloc
|
||||
.reflow("I don't know how to generate the ")
|
||||
.append(alloc.ident(loc_ident.value))
|
||||
.append(alloc.reflow(" function.")),
|
||||
alloc.region(lines.convert_region(loc_ident.region), severity),
|
||||
alloc
|
||||
.reflow("Only specific functions like `after` and `map` can be generated.")
|
||||
.append(alloc.reflow("Learn more about hosted modules at TODO.")),
|
||||
]);
|
||||
|
||||
title = UNKNOWN_GENERATES_WITH.to_string();
|
||||
}
|
||||
Problem::UnusedArgument(closure_symbol, is_anonymous, argument_symbol, region) => {
|
||||
let line = "\". Adding an underscore at the start of a variable name is a way of saying that the variable is not used.";
|
||||
|
||||
|
@ -1328,6 +1313,34 @@ pub fn can_problem<'b>(
|
|||
]);
|
||||
title = "OVERAPPLIED CRASH".to_string();
|
||||
}
|
||||
Problem::UnappliedDbg { region } => {
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.reflow("This "), alloc.keyword("dbg"), alloc.reflow(" doesn't have a value given to it:")
|
||||
]),
|
||||
alloc.region(lines.convert_region(region), severity),
|
||||
alloc.concat([
|
||||
alloc.keyword("dbg"), alloc.reflow(" must be passed a value to print at the exact place it's used. "),
|
||||
alloc.keyword("dbg"), alloc.reflow(" can't be used as a value that's passed around, like functions can be - it must be applied immediately!"),
|
||||
])
|
||||
]);
|
||||
title = "UNAPPLIED DBG".to_string();
|
||||
}
|
||||
Problem::OverAppliedDbg { region } => {
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.reflow("This "),
|
||||
alloc.keyword("dbg"),
|
||||
alloc.reflow(" has too many values given to it:"),
|
||||
]),
|
||||
alloc.region(lines.convert_region(region), severity),
|
||||
alloc.concat([
|
||||
alloc.keyword("dbg"),
|
||||
alloc.reflow(" must be given exactly one value to print."),
|
||||
]),
|
||||
]);
|
||||
title = "OVERAPPLIED DBG".to_string();
|
||||
}
|
||||
Problem::FileProblem { filename, error } => {
|
||||
let report = to_file_problem_report(alloc, filename, error);
|
||||
doc = report.doc;
|
||||
|
|
|
@ -601,19 +601,6 @@ fn to_expr_report<'a>(
|
|||
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity);
|
||||
|
||||
let doc = match context {
|
||||
Context::InNode(Node::Dbg, _) => alloc.stack([
|
||||
alloc.reflow(
|
||||
r"I am partway through parsing a dbg statement, but I got stuck here:",
|
||||
),
|
||||
snippet,
|
||||
alloc.stack([
|
||||
alloc.reflow(r"I was expecting a final expression, like so"),
|
||||
alloc.vcat([
|
||||
alloc.parser_suggestion("dbg 42").indent(4),
|
||||
alloc.parser_suggestion("\"done\"").indent(4),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
Context::InNode(Node::Expect, _) => alloc.stack([
|
||||
alloc.reflow(
|
||||
r"I am partway through parsing an expect statement, but I got stuck here:",
|
||||
|
@ -3770,98 +3757,6 @@ fn to_header_report<'a>(
|
|||
}
|
||||
|
||||
EHeader::Space(error, pos) => to_space_report(alloc, lines, filename, error, *pos),
|
||||
EHeader::Generates(_, pos) => {
|
||||
let surroundings = Region::new(start, *pos);
|
||||
let region = LineColumnRegion::from_pos(lines.convert_pos(*pos));
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I am partway through parsing a header, but got stuck here:"),
|
||||
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
|
||||
alloc.concat([
|
||||
alloc.reflow("I am expecting a type name next, like "),
|
||||
alloc.parser_suggestion("Effect"),
|
||||
alloc.reflow(". Type names must start with an uppercase letter."),
|
||||
]),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "WEIRD GENERATED TYPE NAME".to_string(),
|
||||
severity,
|
||||
}
|
||||
}
|
||||
EHeader::GeneratesWith(generates_with, pos) => {
|
||||
to_generates_with_report(alloc, lines, filename, generates_with, *pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn to_generates_with_report<'a>(
|
||||
alloc: &'a RocDocAllocator<'a>,
|
||||
lines: &LineInfo,
|
||||
filename: PathBuf,
|
||||
parse_problem: &roc_parse::parser::EGeneratesWith,
|
||||
start: Position,
|
||||
) -> Report<'a> {
|
||||
use roc_parse::parser::EGeneratesWith;
|
||||
|
||||
let severity = Severity::RuntimeError;
|
||||
|
||||
match *parse_problem {
|
||||
EGeneratesWith::ListEnd(pos) | // TODO: give this its own error message
|
||||
EGeneratesWith::Identifier(pos) => {
|
||||
let surroundings = Region::new(start, pos);
|
||||
let region = LineColumnRegion::from_pos(lines.convert_pos(pos));
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc
|
||||
.reflow(r"I am partway through parsing a provides list, but I got stuck here:"),
|
||||
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
|
||||
alloc.concat([alloc.reflow(
|
||||
"I was expecting a type name, value name or function name next, like",
|
||||
)]),
|
||||
alloc
|
||||
.parser_suggestion("provides [Animal, default, tame]")
|
||||
.indent(4),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "WEIRD GENERATES".to_string(),
|
||||
severity,
|
||||
}
|
||||
}
|
||||
|
||||
EGeneratesWith::With(pos) => {
|
||||
let surroundings = Region::new(start, pos);
|
||||
let region = LineColumnRegion::from_pos(lines.convert_pos(pos));
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I am partway through parsing a header, but I got stuck here:"),
|
||||
alloc.region_with_subregion(lines.convert_region(surroundings), region, severity),
|
||||
alloc.concat([
|
||||
alloc.reflow("I am expecting the "),
|
||||
alloc.keyword("with"),
|
||||
alloc.reflow(" keyword next, like"),
|
||||
]),
|
||||
alloc
|
||||
.parser_suggestion("with [after, map]")
|
||||
.indent(4),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "WEIRD GENERATES".to_string(),
|
||||
severity,
|
||||
}
|
||||
}
|
||||
|
||||
EGeneratesWith::Space(error, pos) => to_space_report(alloc, lines, filename, &error, pos),
|
||||
|
||||
_ => todo!("unhandled parse error {:?}", parse_problem),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4280,7 +4175,7 @@ fn to_requires_report<'a>(
|
|||
alloc.reflow(" definition looks like"),
|
||||
]),
|
||||
alloc
|
||||
.parser_suggestion("requires {model=>Model, msg=>Msg} {main : Effect {}}")
|
||||
.parser_suggestion("requires {model=>Model, msg=>Msg} {main : Task {} []}")
|
||||
.indent(4),
|
||||
]);
|
||||
|
||||
|
@ -4309,7 +4204,7 @@ fn to_requires_report<'a>(
|
|||
alloc.reflow(" definition looks like"),
|
||||
]),
|
||||
alloc
|
||||
.parser_suggestion("requires { Model, Msg } {main : Effect {}}")
|
||||
.parser_suggestion("requires { Model, Msg } {main : Task {} []}")
|
||||
.indent(4),
|
||||
]);
|
||||
|
||||
|
|
|
@ -1796,6 +1796,9 @@ fn format_category<'b>(
|
|||
let t = if capitalize_start { "T" } else { "t" };
|
||||
|
||||
match category {
|
||||
Lookup(name) if name.is_generated(alloc.interns) => {
|
||||
(text!(alloc, "{}his value", t), alloc.text(" is a:"))
|
||||
}
|
||||
Lookup(name) => (
|
||||
alloc.concat([
|
||||
text!(alloc, "{}his ", t),
|
||||
|
@ -1804,7 +1807,6 @@ fn format_category<'b>(
|
|||
]),
|
||||
alloc.text(" is a:"),
|
||||
),
|
||||
|
||||
If => (
|
||||
alloc.concat([
|
||||
text!(alloc, "{}his ", t),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue