From 3513ecb2f3a1d5dfac9c2335be732ff266267ae2 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Sat, 9 May 2026 13:45:44 +0300 Subject: Rename Parser.cursor to Parser.last_token_end `cursor` sounds like the current position, but the field stores the end of the last consumed token. --- compiler/src/ast/parser.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/src/ast/parser.rs b/compiler/src/ast/parser.rs index 171ecfe..2e6d2dd 100644 --- a/compiler/src/ast/parser.rs +++ b/compiler/src/ast/parser.rs @@ -67,7 +67,7 @@ where I: Iterator>>, { tokens: Peekable, - cursor: Pos, + last_token_end: Pos, } impl<'a, I> Parser<'a, I> @@ -77,7 +77,7 @@ where pub fn new(tokens: I) -> Self { Self { tokens: tokens.peekable(), - cursor: Pos::new(1, 0, 0), + last_token_end: Pos::new(1, 0, 0), } } @@ -86,7 +86,9 @@ where } fn consume(&mut self) -> Option>> { - self.tokens.next().inspect(|s| self.cursor = s.span.end) + self.tokens + .next() + .inspect(|s| self.last_token_end = s.span.end) } fn parse_expr(&mut self) -> Result> { @@ -105,20 +107,20 @@ where Expr::Atom(Atom::Nil) }; - Spanned::new(expr, Span::new(span.start, self.cursor)) + Spanned::new(expr, Span::new(span.start, self.last_token_end)) } Token::RightPar => todo!("unexpected par"), Token::Quote => { self.consume(); let quote = Spanned::new( Expr::Atom(Atom::Symbol("quote".into())), - Span::new(span.start, self.cursor), + Span::new(span.start, self.last_token_end), ); let expr = self.parse_expr()?; Spanned::new( Expr::List(vec![quote, expr]), - Span::new(span.start, self.cursor), + Span::new(span.start, self.last_token_end), ) } Token::Number(number) => { @@ -126,7 +128,7 @@ where Spanned::new( Expr::Atom(parse_number(number)), - Span::new(span.start, self.cursor), + Span::new(span.start, self.last_token_end), ) } Token::String(string) => { @@ -134,7 +136,7 @@ where Spanned::new( Expr::Atom(parse_string(string)), - Span::new(span.start, self.cursor), + Span::new(span.start, self.last_token_end), ) } Token::UnclosedString(string) => { @@ -146,7 +148,7 @@ where Spanned::new( Expr::Atom(parse_symbol(symbol)), - Span::new(span.start, self.cursor), + Span::new(span.start, self.last_token_end), ) } }; -- cgit v1.3