improve messages for tag names

This commit is contained in:
Folkert 2021-02-12 15:22:11 +01:00
parent 19d3e43f09
commit b204154fec
4 changed files with 172 additions and 85 deletions

View file

@ -31,7 +31,7 @@ fn note_for_tag_union_type_indent<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocB
fn hint_for_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> {
alloc.concat(vec![
alloc.hint("Tag names "),
alloc.reflow("Tag names start with an uppercase letter, like "),
alloc.reflow("start with an uppercase letter, like "),
alloc.parser_suggestion("Err"),
alloc.text(" or "),
alloc.parser_suggestion("Green"),
@ -39,6 +39,17 @@ fn hint_for_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> {
])
}
fn hint_for_private_tag_name<'a>(alloc: &'a RocDocAllocator<'a>) -> RocDocBuilder<'a> {
alloc.concat(vec![
alloc.hint("Private tag names "),
alloc.reflow("start with a `@` symbol followed by an uppercase letter, like "),
alloc.parser_suggestion("@UID"),
alloc.text(" or "),
alloc.parser_suggestion("@SecretKey"),
alloc.text("."),
])
}
fn to_syntax_report<'a>(
alloc: &'a RocDocAllocator<'a>,
filename: PathBuf,
@ -372,8 +383,6 @@ fn to_trecord_report<'a>(
TRecord::Type(tipe, row, col) => to_type_report(alloc, filename, tipe, row, col),
TRecord::Syntax(error, row, col) => to_syntax_report(alloc, filename, error, row, col),
TRecord::IndentOpen(row, col) => {
let surroundings = Region::from_rows_cols(start_row, start_col, row, col);
let region = Region::from_row_col(row, col);
@ -555,6 +564,22 @@ fn to_ttag_union_report<'a>(
title: "WEIRD TAG NAME".to_string(),
}
}
Next::Other(Some('@')) => {
let doc = alloc.stack(vec![
alloc.reflow(
r"I am partway through parsing a tag union type, but I got stuck here:",
),
alloc.region_with_subregion(surroundings, region),
alloc.reflow(r"I was expecting to see a private tag name."),
hint_for_private_tag_name(alloc),
]);
Report {
filename,
doc,
title: "WEIRD TAG NAME".to_string(),
}
}
_ => {
let doc = alloc.stack(vec![
alloc.reflow(r"I am partway through parsing a tag union type, but I got stuck here:"),
@ -579,8 +604,6 @@ fn to_ttag_union_report<'a>(
TTagUnion::Type(tipe, row, col) => to_type_report(alloc, filename, tipe, row, col),
TTagUnion::Syntax(error, row, col) => to_syntax_report(alloc, filename, error, row, col),
TTagUnion::IndentOpen(row, col) => {
let surroundings = Region::from_rows_cols(start_row, start_col, row, col);
let region = Region::from_row_col(row, col);