summaryrefslogtreecommitdiff
path: root/src/syntax/parsing.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-30 21:13:12 +0100
committerLaurenz <laurmaedje@gmail.com>2019-10-30 21:13:12 +0100
commitb5d8b8f4a5425ec7bcaa50d8394e76cffe4baadc (patch)
tree23b26258ac200b9150b7485ef95b51d6cf9b7412 /src/syntax/parsing.rs
parentccc4639c7d4dfe039d469d16236ac5ad121f4a07 (diff)
Token spans 🔜🔙
Diffstat (limited to 'src/syntax/parsing.rs')
-rw-r--r--src/syntax/parsing.rs21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index 1e949729..f4013f2b 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -217,12 +217,9 @@ impl<'s> Parser<'s> {
// Do the parsing dependent on whether the function has a body.
Ok(if has_body {
// Find out the string which makes the body of this function.
- let (start, end) = self
- .tokens
- .string_index()
- .and_then(|index| {
- find_closing_bracket(&self.src[index..]).map(|end| (index, index + end))
- })
+ let start = self.tokens.string_index();
+ let end = find_closing_bracket(&self.src[start..])
+ .map(|end| start + end)
.ok_or_else(|| ParseError::new("expected closing bracket"))?;
// Parse the body.
@@ -370,17 +367,15 @@ impl<'s> PeekableTokens<'s> {
/// Peek at the next element.
fn peek(&mut self) -> Option<Token<'s>> {
let iter = &mut self.tokens;
- *self.peeked.get_or_insert_with(|| iter.next())
+ *self.peeked.get_or_insert_with(|| iter.next().map(|token| token.val))
}
- /// The index of the first character of the next token in the source string.
- fn string_index(&mut self) -> Option<usize> {
- self.tokens.chars.string_index()
+ fn string_index(&mut self) -> usize {
+ self.tokens.string_index()
}
- /// Go to a new position in the underlying string.
fn set_string_index(&mut self, index: usize) {
- self.tokens.chars.set_string_index(index);
+ self.tokens.set_string_index(index);
self.peeked = None;
}
}
@@ -391,7 +386,7 @@ impl<'s> Iterator for PeekableTokens<'s> {
fn next(&mut self) -> Option<Token<'s>> {
match self.peeked.take() {
Some(value) => value,
- None => self.tokens.next(),
+ None => self.tokens.next().map(|token| token.val),
}
}
}