mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
WIP
This commit is contained in:
parent
7b4378219e
commit
d211ca7e61
30 changed files with 679 additions and 614 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::ast::Attempting;
|
||||
use crate::keyword;
|
||||
use crate::parser::Progress::{self, *};
|
||||
use crate::parser::{peek_utf8_char, unexpected, Fail, FailReason, ParseResult, Parser, State};
|
||||
use crate::parser::{peek_utf8_char, unexpected, Bag, FailReason, ParseResult, Parser, State};
|
||||
use bumpalo::collections::string::String;
|
||||
use bumpalo::collections::vec::Vec;
|
||||
use bumpalo::Bump;
|
||||
|
@ -91,20 +91,20 @@ pub fn parse_ident<'a>(
|
|||
is_capitalized = first_ch.is_uppercase();
|
||||
is_accessor_fn = false;
|
||||
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
} else if first_ch == '.' {
|
||||
is_capitalized = false;
|
||||
is_accessor_fn = true;
|
||||
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
} else if first_ch == '@' {
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
|
||||
// '@' must always be followed by a capital letter!
|
||||
match peek_utf8_char(&state) {
|
||||
Ok((next_ch, next_bytes_parsed)) => {
|
||||
if next_ch.is_uppercase() {
|
||||
state = state.advance_without_indenting(next_bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, next_bytes_parsed)?;
|
||||
|
||||
part_buf.push('@');
|
||||
part_buf.push(next_ch);
|
||||
|
@ -114,24 +114,25 @@ pub fn parse_ident<'a>(
|
|||
is_accessor_fn = false;
|
||||
} else {
|
||||
return Err(unexpected(
|
||||
arena,
|
||||
bytes_parsed + next_bytes_parsed,
|
||||
state,
|
||||
Attempting::Identifier,
|
||||
state,
|
||||
));
|
||||
}
|
||||
}
|
||||
Err(reason) => {
|
||||
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||
return state.fail(progress, reason);
|
||||
return state.fail(arena, progress, reason);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(unexpected(0, state, Attempting::Identifier));
|
||||
return Err(unexpected(arena, 0, Attempting::Identifier, state));
|
||||
}
|
||||
}
|
||||
Err(reason) => {
|
||||
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||
return state.fail(progress, reason);
|
||||
return state.fail(arena, progress, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,11 +193,11 @@ pub fn parse_ident<'a>(
|
|||
break;
|
||||
}
|
||||
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
}
|
||||
Err(reason) => {
|
||||
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||
return state.fail(progress, reason);
|
||||
return state.fail(arena, progress, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +254,7 @@ pub fn parse_ident<'a>(
|
|||
// We had neither capitalized nor noncapitalized parts,
|
||||
// yet we made it this far. The only explanation is that this was
|
||||
// a stray '.' drifting through the cosmos.
|
||||
return Err(unexpected(1, state, Attempting::Identifier));
|
||||
return Err(unexpected(arena, 1, Attempting::Identifier, state));
|
||||
}
|
||||
}
|
||||
} else if is_private_tag {
|
||||
|
@ -307,9 +308,9 @@ fn malformed<'a>(
|
|||
break;
|
||||
}
|
||||
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
}
|
||||
Err(reason) => return state.fail(MadeProgress, reason),
|
||||
Err(reason) => return state.fail(arena, MadeProgress, reason),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,19 +339,19 @@ where
|
|||
let (first_letter, bytes_parsed) = match peek_utf8_char(&state) {
|
||||
Ok((first_letter, bytes_parsed)) => {
|
||||
if !pred(first_letter) {
|
||||
return Err(unexpected(0, state, Attempting::RecordFieldLabel));
|
||||
return Err(unexpected(arena, 0, Attempting::RecordFieldLabel, state));
|
||||
}
|
||||
|
||||
(first_letter, bytes_parsed)
|
||||
}
|
||||
Err(reason) => return state.fail(NoProgress, reason),
|
||||
Err(reason) => return state.fail(arena, NoProgress, reason),
|
||||
};
|
||||
|
||||
let mut buf = String::with_capacity_in(1, arena);
|
||||
|
||||
buf.push(first_letter);
|
||||
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
|
||||
while !state.bytes.is_empty() {
|
||||
match peek_utf8_char(&state) {
|
||||
|
@ -363,13 +364,13 @@ where
|
|||
if ch.is_alphabetic() || ch.is_ascii_digit() {
|
||||
buf.push(ch);
|
||||
|
||||
state = state.advance_without_indenting(bytes_parsed)?;
|
||||
state = state.advance_without_indenting(arena, bytes_parsed)?;
|
||||
} else {
|
||||
// This is the end of the field. We're done!
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(reason) => return state.fail(MadeProgress, reason),
|
||||
Err(reason) => return state.fail(arena, MadeProgress, reason),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -400,10 +401,7 @@ pub fn lowercase_ident<'a>() -> impl Parser<'a, &'a str> {
|
|||
let region = Region::zero();
|
||||
Err((
|
||||
MadeProgress,
|
||||
Fail {
|
||||
reason: FailReason::ReservedKeyword(region),
|
||||
attempting: Attempting::Identifier,
|
||||
},
|
||||
Bag::from_state(arena, &state, FailReason::ReservedKeyword(region)),
|
||||
state,
|
||||
))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue