mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-22 04:44:06 +00:00
remove context stack
This commit is contained in:
parent
864390a89a
commit
6be5f1a6b1
1 changed files with 0 additions and 49 deletions
|
@ -27,8 +27,6 @@ pub struct State<'a> {
|
||||||
// the first nonspace char on that line.
|
// the first nonspace char on that line.
|
||||||
pub is_indenting: bool,
|
pub is_indenting: bool,
|
||||||
|
|
||||||
pub context_stack: &'a ContextStack<'a>,
|
|
||||||
|
|
||||||
/// The original length of the string, before any bytes were consumed.
|
/// The original length of the string, before any bytes were consumed.
|
||||||
/// This is used internally by the State::bytes_consumed() function.
|
/// This is used internally by the State::bytes_consumed() function.
|
||||||
///
|
///
|
||||||
|
@ -50,7 +48,6 @@ impl<'a> State<'a> {
|
||||||
column: 0,
|
column: 0,
|
||||||
indent_col: 0,
|
indent_col: 0,
|
||||||
is_indenting: true,
|
is_indenting: true,
|
||||||
context_stack: arena.alloc(ContextStack::Nil),
|
|
||||||
original_len: bytes.len(),
|
original_len: bytes.len(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +116,6 @@ impl<'a> State<'a> {
|
||||||
indent_col: 0,
|
indent_col: 0,
|
||||||
is_indenting: true,
|
is_indenting: true,
|
||||||
original_len: self.original_len,
|
original_len: self.original_len,
|
||||||
context_stack: arena.alloc(self.context_stack.clone()),
|
|
||||||
}),
|
}),
|
||||||
None => Err((
|
None => Err((
|
||||||
Progress::NoProgress,
|
Progress::NoProgress,
|
||||||
|
@ -221,7 +217,6 @@ impl<'a> State<'a> {
|
||||||
column: column_usize as u16,
|
column: column_usize as u16,
|
||||||
indent_col,
|
indent_col,
|
||||||
is_indenting,
|
is_indenting,
|
||||||
context_stack: arena.alloc(self.context_stack.clone()),
|
|
||||||
original_len: self.original_len,
|
original_len: self.original_len,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -269,7 +264,6 @@ impl<'a> fmt::Debug for State<'a> {
|
||||||
write!(f, "\n\tindent_col: {}", self.indent_col)?;
|
write!(f, "\n\tindent_col: {}", self.indent_col)?;
|
||||||
write!(f, "\n\tis_indenting: {:?}", self.is_indenting)?;
|
write!(f, "\n\tis_indenting: {:?}", self.is_indenting)?;
|
||||||
write!(f, "\n\toriginal_len: {}", self.original_len)?;
|
write!(f, "\n\toriginal_len: {}", self.original_len)?;
|
||||||
write!(f, "\n\tcontext stack: {:?}", self.context_stack)?;
|
|
||||||
write!(f, "\n}}")
|
write!(f, "\n}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2199,39 +2193,6 @@ macro_rules! debug {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! attempt {
|
|
||||||
($attempting:expr, $parser:expr) => {
|
|
||||||
move |arena: &'a Bump, mut state: $crate::parser::State<'a>| {
|
|
||||||
let item = $crate::parser::ContextItem {
|
|
||||||
context: $attempting,
|
|
||||||
line: state.line,
|
|
||||||
column: state.column,
|
|
||||||
};
|
|
||||||
|
|
||||||
state.context_stack = arena.alloc($crate::parser::ContextStack::Cons(
|
|
||||||
item,
|
|
||||||
state.context_stack,
|
|
||||||
));
|
|
||||||
|
|
||||||
$parser
|
|
||||||
.parse(arena, state)
|
|
||||||
.map(|(progress, answer, mut state)| {
|
|
||||||
// If the parser suceeded, go back to what we were originally attempting.
|
|
||||||
// (If it failed, that's exactly where we care what we were attempting!)
|
|
||||||
match state.context_stack.uncons() {
|
|
||||||
Some((_item, rest)) => {
|
|
||||||
state.context_stack = rest;
|
|
||||||
}
|
|
||||||
None => unreachable!("context stack contains at least one element"),
|
|
||||||
}
|
|
||||||
|
|
||||||
(progress, answer, state)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! either {
|
macro_rules! either {
|
||||||
($p1:expr, $p2:expr) => {
|
($p1:expr, $p2:expr) => {
|
||||||
|
@ -2315,16 +2276,6 @@ where
|
||||||
map_with_arena!(parser, transform)
|
map_with_arena!(parser, transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For some reason, some usages won't compile unless they use this instead of the macro version
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn attempt<'a, P, Val, Error>(attempting: Attempting, parser: P) -> impl Parser<'a, Val, Error>
|
|
||||||
where
|
|
||||||
P: Parser<'a, Val, Error>,
|
|
||||||
Error: 'a,
|
|
||||||
{
|
|
||||||
attempt!(attempting, parser)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_utf8<'a>(bytes: &[u8]) -> Result<&str, SyntaxError<'a>> {
|
pub fn parse_utf8<'a>(bytes: &[u8]) -> Result<&str, SyntaxError<'a>> {
|
||||||
match from_utf8(bytes) {
|
match from_utf8(bytes) {
|
||||||
Ok(string) => Ok(string),
|
Ok(string) => Ok(string),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue