diff options
| author | Martin Haug <mhaug@live.de> | 2022-02-23 20:06:48 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-02-23 20:49:47 +0100 |
| commit | 9fda623b02b2a0a9e9cdf806d9945d0759c8bf01 (patch) | |
| tree | 93a2517cdbbd59e998d2004fb7cf804dadf0f4d6 /src/parse/parser.rs | |
| parent | 4c8634c600ad0bba03ccdf884b32f234ecbff30c (diff) | |
Code Review: That's just like your struct, man.
Diffstat (limited to 'src/parse/parser.rs')
| -rw-r--r-- | src/parse/parser.rs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 8588e586..123871a5 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -2,7 +2,7 @@ use core::slice::SliceIndex; use std::fmt::{self, Display, Formatter}; use std::mem; -use super::{Scanner, TokenMode, Tokens}; +use super::{TokenMode, Tokens}; use crate::syntax::{ErrorPos, Green, GreenData, GreenNode, NodeKind}; /// A convenient token-based parser. @@ -30,11 +30,14 @@ pub struct Parser<'s> { impl<'s> Parser<'s> { /// Create a new parser for the source string. pub fn new(src: &'s str, mode: TokenMode) -> Self { - Self::with_offset(src, mode, 0) + Self::with_prefix("", src, mode) } - fn with_offset(src: &'s str, mode: TokenMode, offset: usize) -> Self { - let mut tokens = Tokens::new(src, mode, offset); + /// Create a new parser for the source string that is prefixed by some text + /// that does not need to be parsed but taken into account for column + /// calculation. + pub fn with_prefix(prefix: &str, src: &'s str, mode: TokenMode) -> Self { + let mut tokens = Tokens::with_prefix(prefix, src, mode); let current = tokens.next(); Self { tokens, @@ -49,13 +52,6 @@ impl<'s> Parser<'s> { } } - /// Create a new parser for the source string that is prefixed by some text - /// that does not need to be parsed but taken into account for column - /// calculation. - pub fn with_prefix(prefix: &str, src: &'s str, mode: TokenMode) -> Self { - Self::with_offset(src, mode, Scanner::new(prefix).column(prefix.len())) - } - /// End the parsing process and return the last child. pub fn finish(self) -> Vec<Green> { self.children @@ -218,7 +214,7 @@ impl<'s> Parser<'s> { /// Determine the column index for the given byte index. pub fn column(&self, index: usize) -> usize { - self.tokens.scanner().column(index) + self.tokens.column(index) } /// Continue parsing in a group. |
