mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
improved malformed patterns
This commit is contained in:
parent
2ae993d695
commit
a87dfac7da
10 changed files with 316 additions and 126 deletions
|
@ -356,6 +356,7 @@ pub enum Pattern<'a> {
|
|||
|
||||
// Malformed
|
||||
Malformed(&'a str),
|
||||
MalformedIdent(&'a str, crate::ident::BadIdent),
|
||||
QualifiedIdentifier {
|
||||
module_name: &'a str,
|
||||
ident: &'a str,
|
||||
|
|
|
@ -1028,6 +1028,9 @@ fn annotation_or_alias<'a>(
|
|||
Malformed(_) => {
|
||||
Def::NotYetImplemented("TODO translate a malformed pattern into a malformed annotation")
|
||||
}
|
||||
MalformedIdent(_, _) => {
|
||||
Def::NotYetImplemented("TODO translate a malformed pattern into a malformed annotation")
|
||||
}
|
||||
Identifier(ident) => {
|
||||
// This is a regular Annotation
|
||||
Def::Annotation(
|
||||
|
|
|
@ -229,7 +229,7 @@ fn malformed_identifier<'a>(
|
|||
Ok((ch, bytes_parsed)) => {
|
||||
// We can't use ch.is_alphanumeric() here because that passes for
|
||||
// things that are "numeric" but not ASCII digits, like `¾`
|
||||
if ch == '.' || ch.is_alphabetic() || ch.is_ascii_digit() {
|
||||
if ch == '.' || ch == '_' || ch.is_alphabetic() || ch.is_ascii_digit() {
|
||||
state = state.advance_without_indenting_ee(bytes_parsed, |r, c| {
|
||||
EExpr::Space(crate::parser::BadInputError::LineTooLong, r, c)
|
||||
})?;
|
||||
|
@ -255,6 +255,7 @@ fn malformed_identifier<'a>(
|
|||
pub enum BadIdent {
|
||||
Start(Row, Col),
|
||||
Space(BadInputError, Row, Col),
|
||||
Underscore(Row, Col),
|
||||
QualifiedTag(Row, Col),
|
||||
PrivateTagNotUppercase(Row, Col),
|
||||
PartStartsWithNumber(Row, Col),
|
||||
|
@ -393,6 +394,16 @@ pub fn parse_ident_help_help<'a>(
|
|||
|
||||
// Now that we've recorded the contents of the current buffer, reset it.
|
||||
part_buf = String::new_in(arena);
|
||||
} else if ch == '_' {
|
||||
// we don't allow underscores in the middle of an identifier
|
||||
// but still parse them (and generate a malformed identifier)
|
||||
// to give good error messages for this case
|
||||
state = advance_state!(state, bytes_parsed)?;
|
||||
return Err((
|
||||
MadeProgress,
|
||||
BadIdent::Underscore(state.line, state.column),
|
||||
state,
|
||||
));
|
||||
} else {
|
||||
// This must be the end of the identifier. We're done!
|
||||
|
||||
|
|
|
@ -267,12 +267,15 @@ fn loc_ident_pattern_help<'a>(
|
|||
},
|
||||
state,
|
||||
)),
|
||||
Ident::Malformed(malformed, _problem) => {
|
||||
Ident::Malformed(malformed, problem) => {
|
||||
debug_assert!(!malformed.is_empty());
|
||||
|
||||
Err((
|
||||
Ok((
|
||||
MadeProgress,
|
||||
EPattern::Start(state.line, state.column),
|
||||
Located {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::MalformedIdent(malformed, problem),
|
||||
},
|
||||
state,
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue