#[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
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
impl ModuleSymbol
Sourcepub fn kind(&self) -> SymbolKind
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.
Sourcepub fn is_valid<H: TaskHandle>(&self, read: &impl ModuleRead<H>) -> bool
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.
Sourcepub fn origin<H: TaskHandle>(&self, read: &impl ModuleRead<H>) -> ScriptOrigin
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.
Sourcepub fn expr_outer_origin<H: TaskHandle>(
&self,
read: &impl ModuleRead<H>,
) -> ScriptOrigin
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
.
Sourcepub fn expr_ty<H: TaskHandle>(
&self,
read: &impl ModuleRead<H>,
) -> ModuleResult<Description>
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
impl Clone for ModuleSymbol
Source§fn clone(&self) -> ModuleSymbol
fn clone(&self) -> ModuleSymbol
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more