pub struct Cursor<'a> {
pub source: &'a str,
pub pos: usize,
pub line: usize,
pub column: usize,
pub base_offset: usize,
}Expand description
源代码解析游标
Fields§
§source: &'a str源代码字符串
pos: usize当前字节偏移位置
line: usize当前行号
column: usize当前列号
base_offset: usize基础偏移量
Implementations§
Source§impl<'a> Cursor<'a>
impl<'a> Cursor<'a>
Sourcepub fn with_position(source: &'a str, pos: Position) -> Cursor<'a>
pub fn with_position(source: &'a str, pos: Position) -> Cursor<'a>
从指定位置创建游标
Sourcepub fn with_sliced_source(source: &'a str, pos: Position) -> Cursor<'a>
pub fn with_sliced_source(source: &'a str, pos: Position) -> Cursor<'a>
从切片源创建游标
Sourcepub fn consume_str(&mut self, s: &str) -> bool
pub fn consume_str(&mut self, s: &str) -> bool
如果匹配则消费字符串
Sourcepub fn skip_whitespace(&mut self)
pub fn skip_whitespace(&mut self)
跳过空白字符
Sourcepub fn consume_whitespace(&mut self) -> String
pub fn consume_whitespace(&mut self) -> String
消费并返回空白字符
Sourcepub fn skip_spaces(&mut self)
pub fn skip_spaces(&mut self)
跳过空格和制表符
Sourcepub fn current_str(&self, start: usize) -> &str
pub fn current_str(&self, start: usize) -> &str
获取从起始位置到当前位置的字符串
Sourcepub fn span_at_current(&self) -> Span
pub fn span_at_current(&self) -> Span
获取当前字符的位置范围
Sourcepub fn consume_ident(&mut self) -> Result<String, Error>
pub fn consume_ident(&mut self) -> Result<String, Error>
消费一个标识符
Sourcepub fn consume_string(&mut self) -> Result<String, Error>
pub fn consume_string(&mut self) -> Result<String, Error>
消费一个字符串字面量
Sourcepub fn span_at_pos(&self, pos: Position) -> Span
pub fn span_at_pos(&self, pos: Position) -> Span
在指定位置创建一个零宽度的 Span
Auto Trait Implementations§
impl<'a> Freeze for Cursor<'a>
impl<'a> RefUnwindSafe for Cursor<'a>
impl<'a> Send for Cursor<'a>
impl<'a> Sync for Cursor<'a>
impl<'a> Unpin for Cursor<'a>
impl<'a> UnsafeUnpin for Cursor<'a>
impl<'a> UnwindSafe for Cursor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more