mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
work on moving ident_etc over
This commit is contained in:
parent
64eed62b69
commit
75344ece40
5 changed files with 312 additions and 33 deletions
|
@ -145,14 +145,21 @@ fn to_syntax_report<'a>(
|
|||
}
|
||||
Type(typ) => to_type_report(alloc, filename, &typ, 0, 0),
|
||||
Pattern(pat) => to_pattern_report(alloc, filename, &pat, 0, 0),
|
||||
Expr(expr) => to_expr_report(alloc, filename, Context::InDef, &expr, 0, 0),
|
||||
Expr(expr) => to_expr_report(
|
||||
alloc,
|
||||
filename,
|
||||
Context::InDef(start_row, start_col),
|
||||
&expr,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
_ => todo!("unhandled parse error: {:?}", parse_problem),
|
||||
}
|
||||
}
|
||||
|
||||
enum Context {
|
||||
InNode(Node, Row, Col, Box<Context>),
|
||||
InDef,
|
||||
InDef(Row, Col),
|
||||
}
|
||||
|
||||
enum Node {
|
||||
|
@ -169,8 +176,8 @@ fn to_expr_report<'a>(
|
|||
filename: PathBuf,
|
||||
context: Context,
|
||||
parse_problem: &roc_parse::parser::EExpr<'a>,
|
||||
_start_row: Row,
|
||||
_start_col: Col,
|
||||
start_row: Row,
|
||||
start_col: Col,
|
||||
) -> Report<'a> {
|
||||
use roc_parse::parser::EExpr;
|
||||
|
||||
|
@ -184,6 +191,86 @@ fn to_expr_report<'a>(
|
|||
EExpr::Str(string, row, col) => {
|
||||
to_str_report(alloc, filename, context, &string, *row, *col)
|
||||
}
|
||||
EExpr::Type(tipe, row, col) => to_type_report(alloc, filename, &tipe, *row, *col),
|
||||
EExpr::Def(syntax, row, col) => to_syntax_report(alloc, filename, syntax, *row, *col),
|
||||
|
||||
EExpr::ElmStyleFunction(region, row, col) => {
|
||||
let surroundings = Region::from_rows_cols(start_row, start_col, *row, *col);
|
||||
let region = *region;
|
||||
// let region = Region::from_row_col(*row, *col);
|
||||
|
||||
let doc = alloc.stack(vec![
|
||||
alloc.reflow(r"I am in the middle of parsing a definition, but I got stuck here:"),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("Looks like you are trying to define a function. "),
|
||||
alloc.reflow("In roc, functions are always written as a lambda, like "),
|
||||
alloc.parser_suggestion("increment = \\n -> n + 1"),
|
||||
alloc.reflow("."),
|
||||
]),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "ARGUMENTS BEFORE EQUALS".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
EExpr::Ident(_row, _col) => unreachable!("another branch would have been chosen"),
|
||||
|
||||
EExpr::Start(row, col) => {
|
||||
let (context_row, context_col, a_thing) = match context {
|
||||
Context::InNode(node, r, c, _) => match node {
|
||||
Node::WhenCondition | Node::WhenBranch => (
|
||||
r,
|
||||
c,
|
||||
alloc.concat(vec![
|
||||
alloc.text("an "),
|
||||
alloc.keyword("when"),
|
||||
alloc.text(" expression"),
|
||||
]),
|
||||
),
|
||||
Node::IfCondition | Node::IfThenBranch | Node::IfElseBranch => (
|
||||
r,
|
||||
c,
|
||||
alloc.concat(vec![
|
||||
alloc.text("an "),
|
||||
alloc.keyword("if"),
|
||||
alloc.text(" expression"),
|
||||
]),
|
||||
),
|
||||
Node::ListElement => (r, c, alloc.text("a list")),
|
||||
},
|
||||
Context::InDef(r, c) => (r, c, alloc.text("a definition")),
|
||||
};
|
||||
|
||||
let surroundings = Region::from_rows_cols(context_row, context_col, *row, *col);
|
||||
let region = Region::from_row_col(*row, *col);
|
||||
|
||||
let doc = alloc.stack(vec![
|
||||
alloc.concat(vec![
|
||||
alloc.reflow(r"I am partway through parsing "),
|
||||
a_thing,
|
||||
alloc.reflow(", but I got stuck here:"),
|
||||
]),
|
||||
alloc.region_with_subregion(surroundings, region),
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("I was expecting to see an expression like "),
|
||||
alloc.parser_suggestion("42"),
|
||||
alloc.reflow(" or "),
|
||||
alloc.parser_suggestion("\"hello\""),
|
||||
alloc.text("."),
|
||||
]),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "MISSING EXPRESSION".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
_ => todo!("unhandled parse error: {:?}", parse_problem),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue