Enum ModuleSymbol

Source
#[non_exhaustive]
pub enum ModuleSymbol {
Show 17 variants Nil, Use(UseSymbol), Package(PackageSymbol), Var(VarSymbol), Loop(LoopSymbol), Break(BreakSymbol), Fn(FnSymbol), Return(ReturnSymbol), Struct(StructSymbol), Array(ArraySymbol), Entry(EntrySymbol), Ident(IdentSymbol), Field(FieldSymbol), Literal(LiteralSymbol), Operator(OperatorSymbol), Call(CallSymbol), Index(IndexSymbol),
}
Expand description

A variant type that enumerates all language constructions currently available for inspection.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Nil

A special enum variant that indicates the absence of a language construction.

Several API functions may return this value to indicate that the construction does not have an associated symbol or that the analyzer was unable to infer it. For example, VarSymbol::let_value may return ModuleSymbol::Nil if the let x; syntax does not have an initialization expression.

This is the Default value of the ModuleSymbol.

§

Use(UseSymbol)

An import statement: use foo.bar;.

§

Package(PackageSymbol)

A package identifier: use <package_ident>;.

§

Var(VarSymbol)

A variable introduction: let <var>;, fn(<var>), or for <var> in range {}.

§

Loop(LoopSymbol)

A loop statement: loop {} or for x in range {}.

§

Break(BreakSymbol)

A loop-breaking statement: break; or continue;.

§

Fn(FnSymbol)

A function constructor: fn() {} or fn(x, y) x + y.

§

Return(ReturnSymbol)

A return statement: return 100; or return;.

§

Struct(StructSymbol)

A structure constructor: struct { foo: 10, bar: 20 }.

§

Array(ArraySymbol)

An array constructor: [10, 20, 30].

§

Entry(EntrySymbol)

An entry of the struct declaration: struct { <entry>: 10 }.

§

Ident(IdentSymbol)

An identifier in the expression: <ident> + 10.

§

Field(FieldSymbol)

A field access operator: foo.<field>.

§

Literal(LiteralSymbol)

Any literal in the expression: 100, or true, or "string".

§

Operator(OperatorSymbol)

Any binary or unary operator in the expression: 10 + 20 or !false.

§

Call(CallSymbol)

An invocation operator: foo(a, b, c). The operator includes the content surrounded by the parentheses, as well as the parentheses themselves.

§

Index(IndexSymbol)

An index operator: foo[10] or foo[10..20]. The operator includes the content surrounded by the brackets, as well as the brackets themselves.

Implementations§

Source§

impl ModuleSymbol

Source

pub fn is_nil(&self) -> bool

Returns true if the ModuleSymbol’s variant is Nil.

Source

pub fn kind(&self) -> SymbolKind

Returns a descriptor object of the enum variant.

The names of the SymbolKind variants match the names of this enum’s variants exactly, except that the SymbolKind does not own the actual symbol object.

Source

pub fn is_valid<H: TaskHandle>(&self, read: &impl ModuleRead<H>) -> bool

Returns true if this symbol still exists in the ScriptModule.

Symbol objects you have obtained may become obsolete over time, for example, if the module’s source code has been edited and the change affects the corresponding source code construction. This function checks the symbol’s validity.

The read argument is any content access guard object (ModuleReadGuard or ModuleWriteGuard).

Note that for ModuleSymbol::Nil, this function always returns false.

Source

pub fn origin<H: TaskHandle>(&self, read: &impl ModuleRead<H>) -> ScriptOrigin

Returns the source code range of the underlying symbol.

The returned object typically covers just the “tagging” part of the symbol’s syntax, such as the symbol’s keyword.

For example, for the use foo.bar; statement, the symbol’s origin is the source code span that covers only the “use” keyword. For the a + b expression, the origin would cover only the “+” character.

The intended use of this range is for annotating the most meaningful part of the syntax in the source code. For instance, if you want to highlight a hint in a code editor’s user interface, it is more useful to annotate just the “fn” keyword of a function declaration rather than the entire function syntax, including its body.

However, if the symbol is an expression, and you need to fetch the entire expression range for code refactoring purposes, consider using the expr_outer_origin function instead.

The read argument is any content access guard object (ModuleReadGuard or ModuleWriteGuard).

Note that if the symbol is not valid, this function returns ScriptOrigin::nil.

Source

pub fn expr_outer_origin<H: TaskHandle>( &self, read: &impl ModuleRead<H>, ) -> ScriptOrigin

Returns the full source code range of the underlying symbol if this symbol is an expression. Otherwise, returns a ScriptOrigin::nil range.

Unlike the origin function, this range covers all parts of the symbol’s construction. For example, for the a + b binary operator, this range includes both the left- and right-hand operands of the operator.

Additionally, if the expression is wrapped in parentheses, the range covers the outermost parentheses: the expr_outer_origin range of the ((a + b)) expression includes the outermost “(” and “)” characters.

The read argument is any content access guard object (ModuleReadGuard or ModuleWriteGuard).

Note that if the symbol is not valid, this function also returns ScriptOrigin::nil.

Source

pub fn expr_ty<H: TaskHandle>( &self, read: &impl ModuleRead<H>, ) -> ModuleResult<Description>

Returns the inferred type of the expression if this symbol is an expression. Otherwise, returns a dynamic type description.

The read argument is any content access guard object (ModuleReadGuard or ModuleWriteGuard).

The function may return an Interrupted error if the type inference requires deep source code analysis, and the analysis procedure is interrupted by the revocation of the module content access guard (see ScriptModule documentation for details).

Note that if the symbol is not valid, this function will also return a description of the dynamic type.

Trait Implementations§

Source§

impl Clone for ModuleSymbol

Source§

fn clone(&self) -> ModuleSymbol

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 Default for ModuleSymbol

Source§

fn default() -> Self

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

impl From<ArraySymbol> for ModuleSymbol

Source§

fn from(symbol: ArraySymbol) -> Self

Converts to this type from the input type.
Source§

impl From<BreakSymbol> for ModuleSymbol

Source§

fn from(symbol: BreakSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<CallSymbol> for ModuleSymbol

Source§

fn from(symbol: CallSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<EntrySymbol> for ModuleSymbol

Source§

fn from(symbol: EntrySymbol) -> Self

Converts to this type from the input type.
Source§

impl From<FieldSymbol> for ModuleSymbol

Source§

fn from(symbol: FieldSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<FnSymbol> for ModuleSymbol

Source§

fn from(symbol: FnSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<IdentSymbol> for ModuleSymbol

Source§

fn from(symbol: IdentSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<IndexSymbol> for ModuleSymbol

Source§

fn from(symbol: IndexSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<LiteralSymbol> for ModuleSymbol

Source§

fn from(symbol: LiteralSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<LoopSymbol> for ModuleSymbol

Source§

fn from(symbol: LoopSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<OperatorSymbol> for ModuleSymbol

Source§

fn from(symbol: OperatorSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<PackageSymbol> for ModuleSymbol

Source§

fn from(symbol: PackageSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<ReturnSymbol> for ModuleSymbol

Source§

fn from(symbol: ReturnSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<StructSymbol> for ModuleSymbol

Source§

fn from(symbol: StructSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<UseSymbol> for ModuleSymbol

Source§

fn from(symbol: UseSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<VarSymbol> for ModuleSymbol

Source§

fn from(symbol: VarSymbol) -> Self

Converts to this type from the input type.
Source§

impl Hash for ModuleSymbol

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Identifiable for ModuleSymbol

Source§

fn id(&self) -> Id

Returns the globally unique identifier of the compilation unit to which this object belongs.
Source§

impl Ord for ModuleSymbol

Source§

fn cmp(&self, other: &ModuleSymbol) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ModuleSymbol

Source§

fn eq(&self, other: &ModuleSymbol) -> 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 PartialOrd for ModuleSymbol

Source§

fn partial_cmp(&self, other: &ModuleSymbol) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for ModuleSymbol

Source§

impl Eq for ModuleSymbol

Source§

impl StructuralPartialEq for ModuleSymbol

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