Skip to main content

Lexer

Struct Lexer 

Source
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

Source

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

Source

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

記録済みの字句エラー。

Source

pub fn error_count(&self) -> usize

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

Source

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

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

Source

fn record_error(&mut self, message: String)

Source

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

Source

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

Source

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

Source

fn skip_trivia(&mut self)

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

Source

fn read_identifier_or_keyword(&mut self) -> Token

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

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

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.