Skip to main content

ParserReturn

Struct ParserReturn 

Source
#[non_exhaustive]
pub struct ParserReturn<'a> { pub program: Program<'a>, pub module_record: ModuleRecord<'a>, pub diagnostics: Diagnostics, pub irregular_whitespaces: Box<[Span]>, pub tokens: ArenaVec<'a, Token>, pub fatal_error: bool, pub is_flow_language: bool, }
Expand description

Return value of Parser::parse consisting of AST, errors and comments

§AST Validity

program will always contain a structurally valid AST, even if there are syntax errors. However, the AST may be semantically invalid. To ensure a valid AST,

  1. Check that diagnostics is empty
  2. Run semantic analysis with syntax error checking enabled

§Errors

Oxc’s Parser is able to recover from some syntax errors and continue parsing. When this happens:

  1. diagnostics will be non-empty
  2. program will contain a full AST
  3. fatal_error will be false

When the parser cannot recover, it will abort and terminate parsing early. program will be empty and fatal_error will be true.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§program: Program<'a>

The parsed AST.

Will be empty (e.g. no statements, directives, etc) if the parser encountered a fatal error.

Every node has a unique node ID within this AST. Program has ID zero; other IDs follow construction order and may have gaps from discarded nodes. Semantic analysis replaces these with its own dense node IDs.

§Validity

It is possible for the AST to be present and semantically invalid. This will happen if

  1. The Parser encounters a recoverable syntax error
  2. The logic for checking the violation is in the semantic analyzer

To ensure a valid AST, check that diagnostics is empty. Then, run semantic analysis with syntax error checking enabled.

§module_record: ModuleRecord<'a>§diagnostics: Diagnostics

Syntax errors encountered while parsing.

This list is not comprehensive. Oxc offloads more-expensive checks to semantic analysis, which can be enabled using SemanticBuilder::with_check_syntax_error.

§irregular_whitespaces: Box<[Span]>

Irregular whitespaces for Oxlint

§tokens: ArenaVec<'a, Token>

Lexed tokens in source order.

Tokens are only collected when tokens are enabled in ParserConfig.

§fatal_error: bool

Whether the parser encountered a fatal error and terminated early.

If false, either parsing was successful, or parsing was able to recover from a syntax error. diagnostics may still contain errors, indicating that the program is not syntactically valid, but parser was able to recover enough to produce an AST.

If true, parser was unable to parse the source. program will be empty and diagnostics will contain at least one error.

§is_flow_language: bool

Whether the file is flow.

Auto Trait Implementations§

§

impl<'a> !Freeze for ParserReturn<'a>

§

impl<'a> !RefUnwindSafe for ParserReturn<'a>

§

impl<'a> !Send for ParserReturn<'a>

§

impl<'a> !Sync for ParserReturn<'a>

§

impl<'a> !UnwindSafe for ParserReturn<'a>

§

impl<'a> Unpin for ParserReturn<'a>

§

impl<'a> UnsafeUnpin for ParserReturn<'a>

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<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
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<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
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.