mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
fail when end of input is not reached by parser
This commit is contained in:
parent
37f17da27e
commit
8f5df8b7b8
4 changed files with 45 additions and 7 deletions
|
@ -75,6 +75,11 @@ impl<'a> State<'a> {
|
|||
self.original_len - self.bytes.len()
|
||||
}
|
||||
|
||||
/// Returns whether the parser has reached the end of the input
|
||||
pub fn has_reached_end(&self) -> bool {
|
||||
self.bytes.len() == 0
|
||||
}
|
||||
|
||||
/// Increments the line, then resets column, indent_col, and is_indenting.
|
||||
/// Advances the input by 1, to consume the newline character.
|
||||
pub fn newline(&self) -> Result<Self, (Fail, Self)> {
|
||||
|
@ -1278,3 +1283,18 @@ pub fn parse_utf8(bytes: &[u8]) -> Result<&str, FailReason> {
|
|||
Err(_) => Err(FailReason::BadUtf8),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end_of_file<'a>() -> impl Parser<'a, ()> {
|
||||
|_arena: &'a Bump, state: State<'a>| {
|
||||
if state.has_reached_end() {
|
||||
Ok(((), state))
|
||||
} else {
|
||||
let fail = Fail {
|
||||
attempting: state.attempting,
|
||||
reason: FailReason::ConditionFailed,
|
||||
};
|
||||
|
||||
Err((fail, state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue