diff options
| author | Tolmachev Igor <me@igorek.dev> | 2026-05-08 17:05:01 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2026-05-08 18:22:09 +0300 |
| commit | 323ddffe325a4bffec89447c75cc27a81315abc1 (patch) | |
| tree | 1391ea326e73a6bfff2f244cddb967593b382ee9 /compiler/src/lexer | |
| parent | 58b937521f3e459089c0d475551bf9a49f930657 (diff) | |
| download | crisp-323ddffe325a4bffec89447c75cc27a81315abc1.tar.gz crisp-323ddffe325a4bffec89447c75cc27a81315abc1.zip | |
Split Spanned<T> from Span and expose fields
Spanned<T> wraps a value with a Span.
Public fields enable destructuring in pattern matches.
Diffstat (limited to 'compiler/src/lexer')
| -rw-r--r-- | compiler/src/lexer/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/src/lexer/tests.rs | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/src/lexer/mod.rs b/compiler/src/lexer/mod.rs index ff7d51d..464d88e 100644 --- a/compiler/src/lexer/mod.rs +++ b/compiler/src/lexer/mod.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::span::{Pos, Span}; | 1 | use crate::span::{Pos, Span, Spanned}; |
| 2 | 2 | ||
| 3 | #[cfg(test)] | 3 | #[cfg(test)] |
| 4 | mod tests; | 4 | mod tests; |
| @@ -113,7 +113,7 @@ impl<'a> Lexer<'a> { | |||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | impl<'a> Iterator for Lexer<'a> { | 115 | impl<'a> Iterator for Lexer<'a> { |
| 116 | type Item = Span<Token<'a>>; | 116 | type Item = Spanned<Token<'a>>; |
| 117 | 117 | ||
| 118 | fn next(&mut self) -> Option<Self::Item> { | 118 | fn next(&mut self) -> Option<Self::Item> { |
| 119 | loop { | 119 | loop { |
| @@ -163,6 +163,6 @@ impl<'a> Iterator for Lexer<'a> { | |||
| 163 | }; | 163 | }; |
| 164 | 164 | ||
| 165 | let end = Pos::new(self.line, self.column, self.cursor); | 165 | let end = Pos::new(self.line, self.column, self.cursor); |
| 166 | Some(Span::new(token, start, end)) | 166 | Some(Spanned::new(token, Span::new(start, end))) |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
diff --git a/compiler/src/lexer/tests.rs b/compiler/src/lexer/tests.rs index 30be85a..2dce2e3 100644 --- a/compiler/src/lexer/tests.rs +++ b/compiler/src/lexer/tests.rs | |||
| @@ -4,7 +4,7 @@ use super::Token::*; | |||
| 4 | use super::*; | 4 | use super::*; |
| 5 | 5 | ||
| 6 | fn tokenize<'a>(input: &'a str) -> Vec<Token<'a>> { | 6 | fn tokenize<'a>(input: &'a str) -> Vec<Token<'a>> { |
| 7 | Lexer::new(input).map(|s| s.into_inner()).collect() | 7 | Lexer::new(input).map(|s| s.inner).collect() |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | #[test] | 10 | #[test] |
| @@ -289,7 +289,9 @@ fn test_comments() { | |||
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | fn spans(input: &str) -> Vec<(Pos, Pos)> { | 291 | fn spans(input: &str) -> Vec<(Pos, Pos)> { |
| 292 | Lexer::new(input).map(|s| (s.start(), s.end())).collect() | 292 | Lexer::new(input) |
| 293 | .map(|s| (s.span.start, s.span.end)) | ||
| 294 | .collect() | ||
| 293 | } | 295 | } |
| 294 | 296 | ||
| 295 | #[test] | 297 | #[test] |
