Files
hakorune/src/tokenizer/cursor.rs

33 lines
824 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use super::NyashTokenizer;
impl NyashTokenizer {
/// 現在の文字を取得
pub(crate) fn current_char(&self) -> Option<char> {
self.input.get(self.position).copied()
}
/// 次の文字を先読み
pub(crate) fn peek_char(&self) -> Option<char> {
self.input.get(self.position + 1).copied()
}
/// 1文字進める行/列も更新)
pub(crate) fn advance(&mut self) {
if let Some(c) = self.current_char() {
self.position += 1;
if c == '\n' {
self.line += 1;
self.column = 1;
} else {
self.column += 1;
}
}
}
/// 入力の終端に到達しているか
pub(crate) fn is_at_end(&self) -> bool {
self.position >= self.input.len()
}
}