pub struct Lexer {Show 17 fields
src: Rc<str>,
pos: usize,
end: usize,
tok_start: usize,
prev_regex_ok: bool,
errors: Vec<LexError>,
error_count: usize,
ident_table: SharedAtoms,
pub skim: bool,
skim_ident: Option<Rc<str>>,
nl_before: bool,
legacy_octal: Vec<usize>,
bad_template: Vec<usize>,
escaped_strings: Vec<usize>,
escaped_idents: Vec<usize>,
esc_invalid: bool,
esc_octal: bool,
}Fields§
§src: Rc<str>ソースの共有 UTF-8 文字列。位置(pos など)はバイト単位で、常に文字の境目を指す。
【2026-11-03】FnBody の遅延解析でスクリプト全体の Rc<str> 1 本と範囲 (start..end) を
共有するため、Vec<u8> の複製をやめて Rc<str> と終端位置 end を保持する。
pos: usize§end: usize§tok_start: usize直前に返したトークンの開始位置(バイト単位)。関数本体の遅延解析で範囲を切り出すのに使う。
prev_regex_ok: bool直前のトークンの後で / が正規表現の始まりになれるか(判定に要るのはこれだけなので、トークンを写さない。2026-11-04)。
errors: Vec<LexError>回復して継続した字句エラー(上限 MAX_LEX_ERRORS 件)。
error_count: usize上限で切り捨てた分も含む総数。
ident_table: SharedAtoms識別子のインターン表。同じ名前の識別子で共有する Rc<str> を保持する。
skim: bool読み飛ばすだけの走査(遅延解析の本体の {〜} を探す間)。識別子はインターンせず、文字列は中身を作らない。
トークンの種類は変わらないので、括弧の対応と / の判定(直前のトークンで決まる)は通常どおり。
skim_ident: Option<Rc<str>>§nl_before: bool直前の next_token の手前に行終端があったか(ASI 判定用)。
legacy_octal: Vec<usize>旧来の 8 進数値(01・08)と、文字列内の旧来 8 進エスケープ(\1・\8 等)を含むトークンの開始バイト位置(昇順)。
strict モードでは構文エラーなので、パーサが範囲を指定して照会する(legacy_octal_between)。
bad_template: Vec<usize>不正エスケープ(\u12・\xZ・\1 等)を含むテンプレートトークンの開始バイト位置(昇順)。
タグ無しテンプレートでは構文エラー、タグ付きでは許容される(bad_template_escape_at)。
escaped_strings: Vec<usize>エスケープ(\)を含む文字列トークンの開始バイト位置(昇順)。Directive Prologue ではエスケープされた文字列は指令と見なされない。
escaped_idents: Vec<usize>\u0067et のようにエスケープを含む識別子の開始位置(文脈キーワード get/set/static として働かせないため)。
esc_invalid: boolunescape が直前のエスケープで立てる旗(不正な \x/\u、旧来 8 進・\8/\9)。
esc_octal: boolImplementations§
Source§impl Lexer
impl Lexer
pub fn new(source: &str) -> Self
Sourcepub fn from_rc_range(src: Rc<str>, start: usize, end: usize) -> Self
pub fn from_rc_range(src: Rc<str>, start: usize, end: usize) -> Self
共有ソース src のバイト範囲 start..end を複製なしで字句解析する。
from_rc_range の、インターン表を引き継ぐ版。【2026-11-04】関数本体の遅延解析は毎回新しい表を作っていたため、
外側の宣言と内側の参照で同じ名前でも別の Rc になり、変数を探すときの番地の一致(VarMap::position)が外れて
文字列の比較(memcmp)に落ちていた。
Sourcepub fn token_newline_before(&self) -> bool
pub fn token_newline_before(&self) -> bool
直前に next_token が返したトークンの手前に行終端(LF・CR・U+2028・U+2029、改行を含むブロックコメント)があったか。
Sourcepub fn legacy_octal_between(&self, from_byte: usize, to_byte: usize) -> bool
pub fn legacy_octal_between(&self, from_byte: usize, to_byte: usize) -> bool
開始位置がバイト範囲 [from_byte, to_byte) にあるトークンの中に、旧来 8 進の数値リテラル
(01・07・08・019 等)または文字列内の旧来 8 進エスケープ(\1〜\7・\0 + 数字・\8・\9)があるか。
strict モードの範囲で呼べば構文エラーの判定になる。このレキサが既に読んだトークンだけが対象。
Sourcepub fn bad_template_escape_at(&self, tok_start_byte: usize) -> bool
pub fn bad_template_escape_at(&self, tok_start_byte: usize) -> bool
開始位置が tok_start_byte のテンプレートトークンが不正なエスケープ(\u12・\xZ・\u{110000}・
\1〜\9・\0 + 数字)を含むか。タグ無しテンプレートでは構文エラー、タグ付きでは許容される。
Sourcepub fn ident_has_escape_at(&self, tok_start_byte: usize) -> bool
pub fn ident_has_escape_at(&self, tok_start_byte: usize) -> bool
開始位置が tok_start_byte の識別子トークンがエスケープを含むか。
Sourcepub fn string_has_escape_at(&self, tok_start_byte: usize) -> bool
pub fn string_has_escape_at(&self, tok_start_byte: usize) -> bool
開始位置が tok_start_byte の文字列トークンがエスケープ(\)を含むか。
fn bytes(&self) -> &[u8] ⓘ
Sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
検出した字句エラーの総数(記録上限で切り捨てた分も含む)。
Sourcepub fn take_error_count(&mut self) -> usize
pub fn take_error_count(&mut self) -> usize
検出した字句エラー件数を取り出して 0 に戻す(逐次解析での増分回収用)。
Sourcepub fn take_errors(&mut self) -> Vec<LexError>
pub fn take_errors(&mut self) -> Vec<LexError>
記録済みの字句エラーを取り出す。
Sourcepub fn intern_ident(&mut self, s: &str) -> Rc<str>
pub fn intern_ident(&mut self, s: &str) -> Rc<str>
識別子をインターンして共有 Rc<str> を返す。
Sourcepub fn atoms(&self) -> SharedAtoms
pub fn atoms(&self) -> SharedAtoms
このソースのインターン表(後から解析する関数本体へ渡す)。
Sourcepub fn intern_ident_range(&mut self, start: usize, end: usize) -> Rc<str>
pub fn intern_ident_range(&mut self, start: usize, end: usize) -> Rc<str>
ソースのバイト範囲 [start..end] をインターンして共有 Rc<str> を返す(借用競合なし)。
fn record_error(&mut self, message: String)
Sourcefn char_at(&self, i: usize) -> Option<(char, usize)>
fn char_at(&self, i: usize) -> Option<(char, usize)>
バイト位置 i の 1 文字とそのバイト数(ASCII は 1 バイトでそのまま読む)。
fn peek(&self) -> 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
Sourcefn read_identifier_escape(&mut self) -> Option<char>
fn read_identifier_escape(&mut self) -> Option<char>
\uXXXX または \u{...} を 1 文字に読む(\ の位置で呼ぶ)。不正なら record_error して None。
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
Sourcepub fn token_start(&self) -> usize
pub fn token_start(&self) -> usize
直前に返したトークンの開始位置(バイト単位)。
Sourcepub fn into_rc_str(self) -> Rc<str>
pub fn into_rc_str(self) -> Rc<str>
字句解析を終えた共有ソースを取り出す。
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(除算扱い)。