Skip to main content

Parser

Struct Parser 

Source
pub struct Parser {
    toks: Vec<Token>,
    pos: usize,
    errors: Vec<ParseError>,
    error_count: usize,
}

Fields§

§toks: Vec<Token>§pos: usize§errors: Vec<ParseError>

回復して解析を続けた構文エラーの記録(上限 MAX_RECORDED_ERRORS 件)。

§error_count: usize

上限で切り捨てた分も含めた実際の検出件数。

Implementations§

Source§

impl Parser

Source

pub fn new(lexer: Lexer) -> Self

Source

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

記録済みの構文エラー(上限まで)。

Source

pub fn error_count(&self) -> usize

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

Source

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

記録済みの構文エラーを取り出す(呼び出し側へ渡してログ出力する用途)。

Source

fn record_error(&mut self, message: String)

Source

fn context_around(&self, at: usize) -> String

エラー位置の前後のトークンを短い文字列にする。

前 6 個・後 3 個。落ちた位置は »« で囲む。

Source

fn absorb_errors(&mut self, sub: Parser)

別インスタンス(テンプレート補間式などの副パーサ)が検出したエラーを 自分の記録へ取り込む。位置は副パーサ内の索引なので、由来が分かるよう 印を付ける。

Source

fn cur(&self) -> &Token

Source

fn at(&self, off: usize) -> &Token

Source

fn bump(&mut self) -> Token

Source

fn is_eof(&self) -> bool

Source

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

Source

fn sym_at(&self, off: usize, s: &str) -> bool

Source

fn ident_at(&self, off: usize, s: &str) -> bool

Source

fn kw_at(&self, off: usize, k: &str) -> bool

Source

fn is_property_key_token(&self, off: usize) -> bool

off の位置がオブジェクト/クラスのプロパティ名になり得るトークン (識別子/予約語/文字列/数値)かどうか(get/set アクセサ判定の先読み用)。

Source

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

Source

fn expect_sym(&mut self, s: &str)

記号 s を消費する。無ければ回復して継続しつつ構文エラーとして記録する (従来は let _ = で「無かった」事実ごと捨てていた)。

Source

fn is_kw(&self, k: &str) -> bool

Source

fn eat_kw(&mut self, k: &str) -> bool

Source

fn ident_name(&mut self) -> Option<String>

Source

pub fn parse_program(&mut self) -> Program

Source

pub fn parse_program_reporting(&mut self) -> (Program, Vec<ParseError>)

パースし、AST と構文エラーの両方を返す。

AST は従来どおり常に返る(ベストエフォート動作を変えない)ので、 呼び出し側は「実行はするが、壊れている事実は知っている」状態にできる。

Source

fn parse_statement(&mut self) -> Option<Statement>

Source

fn parse_block(&mut self) -> Statement

Source

fn parse_brace_body(&mut self) -> Vec<Statement>

{ ... } の中身を Vec として取り出す(関数本体用)。

Source

fn parse_var_declaration(&mut self) -> Option<Statement>

Source

fn parse_using_declaration(&mut self, is_await: bool) -> Option<Statement>

using x = expr, y = expr2; / await using x = expr;。 仕様上バインディングは単純な識別子のみ(分割代入パターンは不可)。

Source

fn parse_if(&mut self) -> Option<Statement>

Source

fn parse_while(&mut self) -> Option<Statement>

Source

fn parse_do_while(&mut self) -> Option<Statement>

Source

fn parse_for(&mut self) -> Option<Statement>

Source

fn finish_c_for(&mut self, init: Option<Box<Statement>>) -> Option<Statement>

Source

fn parse_function_declaration(&mut self, is_async: bool) -> Option<Statement>

Source

fn parse_try(&mut self) -> Option<Statement>

Source

fn parse_module_specifier(&mut self) -> String

文字列指定子(module specifier)を読む。from "mod" の “mod” 部分など。

Source

fn eat_contextual(&mut self, word: &str) -> bool

文脈依存キーワード(from/as)を ident として消費する。一致したら true。

Source

fn parse_named_specifiers(&mut self) -> Vec<(String, String)>

{ a, b as c } の中身を (元名, ローカル名) ペアの列として読む。

Source

fn parse_import(&mut self) -> Option<Statement>

import 宣言。 形態: import "mod" / import def from "mod" / import * as ns from "mod" / import { a, b as c } from "mod" / import def, { a } from "mod" / import def, * as ns from "mod"

Source

fn parse_export(&mut self) -> Option<Statement>

export 宣言。 形態: export default <expr> / export { a, b as c } / export { a } from "mod" / export * from "mod" / export var/let/const/function/class ...

Source

fn export_decl_names(&self) -> Vec<String>

export に続く宣言から公開すべき名前を先読みで収集する(カーソルは進めない)。

Source

fn parse_expression_statement(&mut self) -> Option<Statement>

Source

fn parse_switch(&mut self) -> Option<Statement>

Source

fn parse_param_list(&mut self) -> Vec<Param>

Source

fn parse_pattern(&mut self) -> Pattern

束縛パターンをパース(識別子 / {...} / [...])。

Source

fn parse_object_pattern(&mut self) -> Pattern

Source

fn parse_array_pattern(&mut self) -> Pattern

Source

pub fn parse_expression(&mut self) -> Expression

Source

fn parse_assignment(&mut self) -> Expression

Source

fn try_parse_arrow(&mut self) -> Option<Expression>

Source

fn matching_paren(&self) -> Option<usize>

現在位置の ( に対応する ) のインデックスを返す。

Source

fn parse_arrow_body(&mut self) -> Vec<Statement>

Source

fn parse_conditional(&mut self) -> Expression

Source

fn parse_binary(&mut self, min_prec: u8) -> Expression

Source

fn current_binop_str(&self) -> Option<String>

現在のトークンが二項演算子なら、その文字列を返す(instanceof/in 含む)。

Source

fn parse_unary(&mut self) -> Expression

Source

fn parse_new(&mut self) -> Expression

Source

fn parse_postfix(&mut self) -> Expression

Source

fn parse_call_member(&mut self, allow_call: bool) -> Expression

メンバ/添字/呼出のチェーン。allow_call=false で呼出を抑止(new 用)。

Source

fn parse_call_member_tail( &mut self, expr: Expression, allow_call: bool, ) -> Expression

既存の式に続くメンバ/添字/呼出チェーンを消費する。

Source

fn parse_arguments(&mut self) -> Vec<Expression>

Source

fn parse_primary(&mut self) -> Expression

Source

fn parse_function_expression(&mut self, is_async: bool) -> Expression

Source

fn parse_class(&mut self) -> Expression

Source

fn parse_array_literal(&mut self) -> Expression

Source

fn parse_object_literal(&mut self) -> Expression

Auto Trait Implementations§

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.