Struct lib_ruby_parser::ParserOptions
source · #[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
impl Debug for ParserOptions
Auto Trait Implementations§
impl Freeze for ParserOptions
impl !RefUnwindSafe for ParserOptions
impl !Send for ParserOptions
impl !Sync for ParserOptions
impl Unpin for ParserOptions
impl !UnwindSafe for ParserOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more