mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
bunch of stuff
This commit is contained in:
parent
43550bf18e
commit
e395d18e16
13 changed files with 776 additions and 343 deletions
|
@ -482,15 +482,127 @@ fn pretty_runtime_error<'b>(
|
|||
// do nothing, reported with PrecedenceProblem
|
||||
unreachable!()
|
||||
}
|
||||
RuntimeError::MalformedIdentifier(box_str, region) => {
|
||||
alloc.stack(vec![
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("The ")
|
||||
.append(format!("`{}`", box_str))
|
||||
.append(alloc.reflow(" identifier is malformed:")),
|
||||
]),
|
||||
alloc.region(region),
|
||||
])
|
||||
RuntimeError::MalformedIdentifier(_box_str, bad_ident, surroundings) => {
|
||||
// we re-parse the identifier, to learn exactly what is going on
|
||||
use roc_parse::ident::BadIdent::*;
|
||||
|
||||
|
||||
|
||||
match bad_ident {
|
||||
Start(_,_) | Space(_,_,_) => unreachable!("these are handled in the parser"),
|
||||
WeirdDotAccess(row, col) | StrayDot(row, col) => {
|
||||
let region = Region::from_row_col(row, col);
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I trying to parse a record field accessor here:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("Something like "),
|
||||
alloc.parser_suggestion(".name"),
|
||||
alloc.reflow(" or "),
|
||||
alloc.parser_suggestion(".height"),
|
||||
alloc.reflow(" that accesses a value from a record."),
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
PartStartsWithNumber(row, col) => {
|
||||
let region = Region::from_row_col(row, col);
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I trying to parse a record field access here:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("So I expect to see a lowercase letter next, like "),
|
||||
alloc.parser_suggestion(".name"),
|
||||
alloc.reflow(" or "),
|
||||
alloc.parser_suggestion(".height"),
|
||||
alloc.reflow("."),
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
WeirdAccessor(_row, _col) => {
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I am very confused by this field access"),
|
||||
alloc.region(surroundings),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("It looks like a field access on an accessor. I parse"),
|
||||
alloc.parser_suggestion(".client.name"),
|
||||
alloc.reflow(" as "),
|
||||
alloc.parser_suggestion("(.client).name"),
|
||||
alloc.reflow(". Maybe use an anonymous function like "),
|
||||
alloc.parser_suggestion("(\\r -> r.client.name)"),
|
||||
alloc.reflow(" instead"),
|
||||
alloc.reflow("?"),
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
WeirdDotQualified(row, col) => {
|
||||
let region = Region::from_row_col(row, col);
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I am trying to parse a qualified name here:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("I was expecting to see an identifier next, like "),
|
||||
alloc.parser_suggestion("height"),
|
||||
alloc.reflow(". A complete qualified name looks something like "),
|
||||
alloc.parser_suggestion("Json.Decode.string"),
|
||||
alloc.text(".")
|
||||
])
|
||||
])
|
||||
}
|
||||
QualifiedTag(row, col) => {
|
||||
let region = Region::from_row_col(row, col);
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I am trying to parse a qualified name here:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("This looks like a qualified tag name to me, but tags cannot be qualified! "),
|
||||
alloc.reflow("Maybe you wanted a qualified name, something like "),
|
||||
alloc.parser_suggestion("Json.Decode.string"),
|
||||
alloc.text("?")
|
||||
])
|
||||
])
|
||||
}
|
||||
PrivateTagNotUppercase(row, col) => {
|
||||
let region = Region::from_row_col(row, col);
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I am trying to parse a private tag here:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow(r"But after the "),
|
||||
alloc.keyword("@"),
|
||||
alloc.reflow(r" symbol I found a lowercase letter. "),
|
||||
alloc.reflow(r"All tag names (global and private) must start with an uppercase letter, like "),
|
||||
alloc.parser_suggestion("@UUID"),
|
||||
alloc.reflow(" or "),
|
||||
alloc.parser_suggestion("@Secrets"),
|
||||
alloc.reflow("."),
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
PrivateTagFieldAccess(_row, _col) => {
|
||||
|
||||
alloc.stack(vec![
|
||||
alloc.reflow("I am very confused by this field access:"),
|
||||
alloc.region(surroundings),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow(r"It looks like a record field access on a private tag."),
|
||||
])
|
||||
])
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
RuntimeError::MalformedClosure(_) => todo!(""),
|
||||
RuntimeError::InvalidFloat(sign @ FloatErrorKind::PositiveInfinity, region, _raw_str)
|
||||
|
|
|
@ -221,7 +221,30 @@ fn to_expr_report<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
EExpr::Ident(_row, _col) => unreachable!("another branch would have been chosen"),
|
||||
EExpr::Ident(_row, _col) => unreachable!("another branch would be taken"),
|
||||
|
||||
EExpr::QualifiedTag(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 very confused by this identifier:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("Are you trying to qualify a name? I am execting something like "),
|
||||
alloc.parser_suggestion("Json.Decode.string"),
|
||||
alloc.reflow(". Maybe you are trying to qualify a tag? Tags like "),
|
||||
alloc.parser_suggestion("Err"),
|
||||
alloc.reflow(" are globally scoped in roc, and cannot be qualified."),
|
||||
]),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "WEIRD IDENTIFIER".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
EExpr::Start(row, col) => {
|
||||
let (context_row, context_col, a_thing) = match context {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue