pub struct Lexer {
chars: Vec<char>,
pos: usize,
prev: Option<Token>,
errors: Vec<LexError>,
error_count: usize,
}Fields§
§chars: Vec<char>§pos: usize§prev: Option<Token>直前に発行したトークン(/ を正規表現か除算か判定するため)。
errors: Vec<LexError>回復して継続した字句エラー(上限 MAX_LEX_ERRORS 件)。
error_count: usize上限で切り捨てた分も含む総数。
Implementations§
Source§impl Lexer
impl Lexer
pub fn new(source: &str) -> Self
Sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
検出した字句エラーの総数(記録上限で切り捨てた分も含む)。
Sourcepub fn take_errors(&mut self) -> Vec<LexError>
pub fn take_errors(&mut self) -> Vec<LexError>
記録済みの字句エラーを取り出す。
fn record_error(&mut self, message: String)
fn peek(&self) -> Option<char>
fn peek_at(&self, off: usize) -> Option<char>
fn advance(&mut self) -> Option<char>
Sourcefn skip_trivia(&mut self)
fn skip_trivia(&mut self)
空白とコメントをまとめてスキップ。
fn read_identifier_or_keyword(&mut self) -> Token
fn read_number(&mut self) -> Token
fn read_string(&mut self, quote: char) -> Token
fn read_template(&mut self) -> Token
Sourcefn scan_interpolation_expr(&mut self) -> String
fn scan_interpolation_expr(&mut self) -> String
${ の直後から呼ばれる。対応する } の直前までの生ソースを返す(} 自体は
消費するが戻り値には含めない)。ネストした {}(オブジェクトリテラル等)の
深さを追跡しつつ、文字列リテラル('...'/"..."、バックスラッシュエスケープ
考慮)とネストしたテンプレートリテラル(`...`)の中身はそのまま素通しして
深さ計算を乱さないようにする。ネストしたテンプレート内部の ${} へは再帰せず
対応するバッククォートまで丸ごと取り込む簡略実装(`${`a${b}c`}` のような
二重ネストは非対応、この処理系のテンプレート補間の主用途である単純な値の
埋め込みでは問題にならない)。
pub fn next_token(&mut self) -> Token
fn scan(&mut self) -> Token
Sourcefn regex_allowed(&self) -> bool
fn regex_allowed(&self) -> bool
直前トークンから / を正規表現開始とみなしてよいか判定。
Sourcefn try_read_regex(&mut self) -> Option<Token>
fn try_read_regex(&mut self) -> Option<Token>
/pattern/flags を読む。閉じ / が無い等で正規表現でなければ None(除算扱い)。
fn match_str(&self, s: &str) -> bool
Auto Trait Implementations§
impl Freeze for Lexer
impl RefUnwindSafe for Lexer
impl Send for Lexer
impl Sync for Lexer
impl Unpin for Lexer
impl UnsafeUnpin for Lexer
impl UnwindSafe for Lexer
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