summaryrefslogtreecommitdiff
path: root/src/parse/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/parser.rs')
-rw-r--r--src/parse/parser.rs20
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.