Struct netsblox_ast::Parser

source ·
pub struct Parser {
    pub optimize: bool,
    pub omit_nonhat_scripts: bool,
    pub adjust_to_zero_index: bool,
    pub name_transformer: Rc<dyn Fn(&str) -> Result<String, ()>>,
    pub autofill_generator: Rc<dyn Fn(usize) -> Result<String, ()>>,
}

Fields§

§optimize: bool

If true, the emitted syntax tree will be processed by static optimizations. Defaults to false.

§omit_nonhat_scripts: bool

If true, the parser will skip script blocks that lack a hat block. This is typically desirable since free floating blocks are never automatically executed, and thus are typically not needed for translation efforts. Defaults to true.

§adjust_to_zero_index: bool

If true, the emitted syntax tree will be automatically adjusted to support convenient translation into languages with zero-based indexing. For instance, with this enabled, an item X of _ block will emit X-1 as the index rather than X, and similar for other list-based blocks. Defaults to false.

§name_transformer: Rc<dyn Fn(&str) -> Result<String, ()>>

All symbol names in the program will be passed through this function, allowing easy conversion of Snap! names to, e.g., valid C-like identifiers. The default operation performs no conversion. Note that non-default transform strategies may also require a custom Parser::autofill_generator.

§autofill_generator: Rc<dyn Fn(usize) -> Result<String, ()>>

A generator used to produce symbol names for auto-fill closure arguments. The function receives a number that can be used to differentiate different generated arguments. It is expected that multiple calls to this function with the same input will produce the same output symbol name. The default is to produce a string of format %n where n is the input number. Note that, after generation, symbol names are still passed through Parser::name_transformer as usual.

Implementations§

source§

impl Parser

source

pub fn parse(&self, xml: &str) -> Result<Project, Box<Error>>

Trait Implementations§

source§

impl Default for Parser

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Parser

§

impl !Send for Parser

§

impl !Sync for Parser

§

impl Unpin for Parser

§

impl !UnwindSafe for Parser

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.