#[repr(C)]
pub struct ParserOptions { pub buffer_name: String, pub decoder: Option<Decoder>, pub record_tokens: bool, }
Expand description

Configuration of the parser

Fields§

§buffer_name: String

Name of the buffer. Used in all diagnostic messages

§decoder: Option<Decoder>

Custom decoder that can be used if the source is encoded in unknown encoding. Only UTF-8 and ASCII-8BIT/BINARY are supported out of the box.

§Example

use lib_ruby_parser::source::{Decoder, DecoderResult, InputError};
use lib_ruby_parser::{Parser, ParserOptions, ParserResult, LocExt};

fn decode(encoding: String, input: Vec<u8>) -> DecoderResult {
    if "US-ASCII" == encoding.to_uppercase() {
        // reencode and return Ok(result)
        return DecoderResult::Ok(b"# encoding: us-ascii\ndecoded".to_vec().into());
    }
    DecoderResult::Err(InputError::DecodingError(
        "only us-ascii is supported".into(),
    ))
}

let decoder = Decoder::new(Box::new(decode));
let options = ParserOptions {
    decoder: Some(decoder),
    ..Default::default()
};
let parser = Parser::new(b"# encoding: us-ascii\n3 + 3".to_vec(), options);
let ParserResult { ast, input, .. } = parser.do_parse();

assert_eq!(
    ast.unwrap().expression().source(&input).unwrap(),
    "decoded".to_string()
)
§record_tokens: bool

When set to true Parser records tokens. When set to false ParserResult.tokens is guaranteed to be empty. If you don’t need tokens better set it to false to speed up parsing.

Trait Implementations§

source§

impl Debug for ParserOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ParserOptions

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.