gpp

Struct Context

source
pub struct Context {
    pub macros: HashMap<String, String>,
    pub inactive_stack: u32,
    pub used_if: bool,
    pub allow_exec: bool,
    pub in_stack: Vec<Child>,
}
Expand description

Context of the current processing.

Contains a set of currently defined macros, as well as the number of nested if statements that are being ignored; this is so that if the parser failed an if statement, and it is currently ignoring data, it knows how many endifs it needs to encounter before resuming reading data again. Only if this value is 0 then the parser will read data. It also stores whether the current if group has been accepted; this is for if groups with over three parts.

There are no limits on what variable names can be; by directly altering Context::macros, you can set variable names not possible with #defines. However, when replacing variable names in text the variable name must be surrounded by two characters that are not alphanumeric or an underscore.

Fields§

§macros: HashMap<String, String>

Map of all currently defined macros.

§inactive_stack: u32

Number of layers of inactive if statements.

§used_if: bool

Whether the current if statement has been accepted.

§allow_exec: bool

Whether #exec and #in commands are allowed.

§in_stack: Vec<Child>

The stack of processes that #in is piping to.

Implementations§

source§

impl Context

source

pub fn new() -> Self

Create a new empty context with no macros or inactive stack and exec commands disallowed.

source

pub fn new_exec() -> Self

Create a new empty context with no macros or inactive stack and exec commands allowed.

source

pub fn from_macros(macros: impl Into<HashMap<String, String>>) -> Self

Create a context from a map of macros.

source

pub fn from_macros_iter( macros: impl IntoIterator<Item = (String, String)>, ) -> Self

Create a context from an iterator over tuples.

source

pub fn exec(self, allow_exec: bool) -> Self

Set whther exec commands are allowed.

Trait Implementations§

source§

impl Debug for Context

source§

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

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

impl Default for Context

source§

fn default() -> Context

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

source§

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

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.