[][src]Struct lib_ruby_parser::ParserOptions

pub struct ParserOptions {
    pub buffer_name: String,
    pub debug: bool,
    pub decoder: CustomDecoder,
    pub token_rewriter: Option<Box<dyn TokenRewriter>>,
    pub record_tokens: bool,
}

Configuration of the parser

Fields

buffer_name: String

Name of the buffer. Used in all diagnostic messages

debug: bool

Controls whether the parser should run in debug mode

Debug mode forces parser/lexer to print additional information while running (like bison actions)

decoder: CustomDecoder

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::{InputError, CustomDecoder};
use lib_ruby_parser::{Parser, ParserOptions, ParserResult};

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

// Or
let decode_closure = |encoding: &str, input: &[u8]| -> Result<Vec<u8>, InputError> {
    if "US-ASCII" == encoding.to_uppercase() {
        // reencode and return Ok(result)
        return Ok(b"# encoding: us-ascii\ndecoded".to_vec());
    }
    Err(InputError::DecodingError(
        "only us-ascii is supported".to_owned(),
    ))
};

let decoder = CustomDecoder::new(Box::new(decode_closure));
let options = ParserOptions { decoder, debug: true, ..Default::default() };
let mut parser = Parser::new(b"# encoding: us-ascii\n3 + 3", options);
let ParserResult { ast, input, .. } = parser.do_parse();

assert_eq!(ast.unwrap().expression().source(&input).unwrap(), "decoded".to_owned())
token_rewriter: Option<Box<dyn TokenRewriter>>

Optional token rewriter, see TokenRewriter API

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

impl Default for ParserOptions[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.