Skip to main content

Lexer

Struct Lexer 

Source
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: bool

unescape が直前のエスケープで立てる旗(不正な \x/\u、旧来 8 進・\8/\9)。

§esc_octal: bool

Implementations§

Source§

impl Lexer

Source

pub fn new(source: &str) -> Self

Source

pub fn from_rc_range(src: Rc<str>, start: usize, end: usize) -> Self

共有ソース src のバイト範囲 start..end を複製なしで字句解析する。

Source

pub fn from_rc_range_shared( src: Rc<str>, start: usize, end: usize, atoms: SharedAtoms, ) -> Self

from_rc_range の、インターン表を引き継ぐ版。【2026-11-04】関数本体の遅延解析は毎回新しい表を作っていたため、 外側の宣言と内側の参照で同じ名前でも別の Rc になり、変数を探すときの番地の一致(VarMap::position)が外れて 文字列の比較(memcmp)に落ちていた。

Source

pub fn token_newline_before(&self) -> bool

直前に next_token が返したトークンの手前に行終端(LF・CR・U+2028・U+2029、改行を含むブロックコメント)があったか。

Source

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 モードの範囲で呼べば構文エラーの判定になる。このレキサが既に読んだトークンだけが対象。

Source

pub fn bad_template_escape_at(&self, tok_start_byte: usize) -> bool

開始位置が tok_start_byte のテンプレートトークンが不正なエスケープ(\u12・\xZ・\u{110000}・ \1〜\9・\0 + 数字)を含むか。タグ無しテンプレートでは構文エラー、タグ付きでは許容される。

Source

pub fn ident_has_escape_at(&self, tok_start_byte: usize) -> bool

開始位置が tok_start_byte の識別子トークンがエスケープを含むか。

Source

pub fn string_has_escape_at(&self, tok_start_byte: usize) -> bool

開始位置が tok_start_byte の文字列トークンがエスケープ(\)を含むか。

Source

fn bytes(&self) -> &[u8] ⓘ

Source

pub fn errors(&self) -> &[LexError]

記録済みの字句エラー。

Source

pub fn error_count(&self) -> usize

検出した字句エラーの総数(記録上限で切り捨てた分も含む)。

Source

pub fn take_error_count(&mut self) -> usize

検出した字句エラー件数を取り出して 0 に戻す(逐次解析での増分回収用)。

Source

pub fn take_errors(&mut self) -> Vec<LexError>

記録済みの字句エラーを取り出す。

Source

pub fn src_rc(&self) -> &Rc<str>

共有ソース Rc<str> への参照を返す。

Source

pub fn intern_ident(&mut self, s: &str) -> Rc<str>

識別子をインターンして共有 Rc<str> を返す。

Source

pub fn atoms(&self) -> SharedAtoms

このソースのインターン表(後から解析する関数本体へ渡す)。

Source

pub fn intern_ident_range(&mut self, start: usize, end: usize) -> Rc<str>

ソースのバイト範囲 [start..end] をインターンして共有 Rc<str> を返す(借用競合なし)。

Source

fn record_error(&mut self, message: String)

Source

fn char_at(&self, i: usize) -> Option<(char, usize)>

バイト位置 i の 1 文字とそのバイト数(ASCII は 1 バイトでそのまま読む)。

Source

fn peek(&self) -> Option<char>

Source

fn peek_at(&self, off: usize) -> Option<char>

off 文字先の文字。

Source

fn advance(&mut self) -> Option<char>

Source

fn slice(&self, a: usize, b: usize) -> String

バイト位置 a..b のソース文字列。

Source

fn skip_trivia(&mut self)

空白とコメントをまとめてスキップ。

Source

fn read_identifier_or_keyword(&mut self) -> Token

Source

fn read_identifier_escape(&mut self) -> Option<char>

\uXXXX または \u{...} を 1 文字に読む(\ の位置で呼ぶ)。不正なら record_error して None。

Source

fn read_number(&mut self) -> Token

Source

fn read_string(&mut self, quote: char) -> Token

Source

fn read_template(&mut self) -> Token

Source

fn scan_interpolation_expr(&mut self) -> String

${ の直後から呼ばれる。対応する } の直前までの生ソースを返す(} 自体は 消費するが戻り値には含めない)。ネストした {}、文字列リテラル、コメント、 正規表現リテラル(/ が除算か正規表現かを直前のトークン種別から判定)、 および再帰的にネストしたテンプレートリテラル(`${`a${b}c`}`)を正しく扱う。

Source

pub fn next_token(&mut self) -> Token

Source

pub fn token_start(&self) -> usize

直前に返したトークンの開始位置(バイト単位)。

Source

pub fn into_rc_str(self) -> Rc<str>

字句解析を終えた共有ソースを取り出す。

Source

fn scan(&mut self) -> Token

Source

fn regex_allowed(&self) -> bool

直前トークンから / を正規表現開始とみなしてよいか判定。

Source

fn try_read_regex(&mut self) -> Option<Token>

/pattern/flags を読む。閉じ / が無い等で正規表現でなければ None(除算扱い)。

Source

fn match_str(&self, s: &str) -> bool

今の位置から s が続くか(UTF-8 のバイト列どうしで比べる。記号はすべて ASCII)。

Auto Trait Implementations§

§

impl !RefUnwindSafe for Lexer

§

impl !Send for Lexer

§

impl !Sync for Lexer

§

impl !UnwindSafe for Lexer

§

impl Freeze for Lexer

§

impl Unpin for Lexer

§

impl UnsafeUnpin for Lexer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.