mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Fix indentation checking some more
This commit is contained in:
parent
adb5ba7f5e
commit
4dddea0bb1
4 changed files with 81 additions and 37 deletions
|
@ -38,12 +38,26 @@ impl<'a> State<'a> {
|
|||
input,
|
||||
line: 0,
|
||||
column: 0,
|
||||
indent_col: 1,
|
||||
indent_col: 0,
|
||||
is_indenting: true,
|
||||
attempting,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_indent(self, min_indent: u16) -> Result<Self, (Fail, Self)> {
|
||||
if self.indent_col < min_indent {
|
||||
Err((
|
||||
Fail {
|
||||
attempting: self.attempting,
|
||||
reason: FailReason::OutdentedTooFar,
|
||||
},
|
||||
self,
|
||||
))
|
||||
} else {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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)> {
|
||||
|
@ -136,7 +150,7 @@ pub type ParseResult<'a, Output> = Result<(Output, State<'a>), (Fail, State<'a>)
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum FailReason {
|
||||
Unexpected(char, Region),
|
||||
DefOutdentedTooFar(u16, u16, Region),
|
||||
OutdentedTooFar,
|
||||
ConditionFailed,
|
||||
LineTooLong(u32 /* which line was too long */),
|
||||
TooManyLines,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue