Scope

Struct Scope 

Source
pub struct Scope {
    pub import_stack: Vec<String>,
    pub env: Rc<Val>,
    pub curr_val: Option<Rc<Val>>,
    pub build_output: ValueMap,
    pub search_curr_val: bool,
    pub strict: bool,
}
Expand description

Defines a scope for execution in ucg.

Scopes in ucg are defined by the currently executing file and the complex data types in that file. (Tuple, List, Modules, and the left operands for dot selectors).

UCG Scopes do not descend up into their parent scopes so we do not maintain a stack for those.

Fields§

§import_stack: Vec<String>§env: Rc<Val>§curr_val: Option<Rc<Val>>§build_output: ValueMap§search_curr_val: bool§strict: bool

Implementations§

Source§

impl Scope

Source

pub fn new(env: Rc<Val>) -> Self

Source

pub fn use_strict(self) -> Self

Source

pub fn use_curr_val(self) -> Self

Source

pub fn spawn_child(&self) -> Self

Spawn a child scope based on the current scope but without the current val set.

Source

pub fn spawn_clean(&self) -> Self

Source

pub fn push_import<S: Into<String>>(&mut self, path: S)

Push an import onto the import stack.

Source

pub fn prepend_import_stack(&mut self, imports: &Vec<String>)

Source

pub fn set_curr_val(self, val: Rc<Val>) -> Self

Set the current value for our execution context.

Source

pub fn lookup_idx( &self, pos: &Position, idx: &Val, ) -> Result<Rc<Val>, Box<dyn Error>>

Lookup up a list index in the current value

Source

pub fn lookup_sym( &self, sym: &PositionedItem<String>, is_symbol: bool, ) -> Option<Rc<Val>>

Lookup a symbol in the current execution context.

The lookup rules are simple.

  • env is always an environment variable lookup.
  • self is always the current value. This symbol is only valid when the current value is a tuple.
  • everything else is looked up in the currently accumulated build output for this execution context.

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scope

Source§

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

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

impl PartialEq for Scope

Source§

fn eq(&self, other: &Scope) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl !Send for Scope

§

impl !Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.