Extract Identifier type.
This commit is contained in:
39
src/ast.rs
39
src/ast.rs
@@ -16,7 +16,8 @@ use crate::stdlib::{
|
||||
};
|
||||
use crate::token::Token;
|
||||
use crate::{
|
||||
Dynamic, FnNamespace, FnPtr, ImmutableString, Module, Position, Shared, StaticVec, INT,
|
||||
Dynamic, FnNamespace, FnPtr, Identifier, ImmutableString, Module, Position, Shared, StaticVec,
|
||||
INT,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "no_float"))]
|
||||
@@ -50,14 +51,14 @@ pub struct ScriptFnDef {
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub mods: crate::engine::Imports,
|
||||
/// Function name.
|
||||
pub name: ImmutableString,
|
||||
pub name: Identifier,
|
||||
/// Function access mode.
|
||||
pub access: FnAccess,
|
||||
/// Names of function parameters.
|
||||
pub params: StaticVec<ImmutableString>,
|
||||
pub params: StaticVec<Identifier>,
|
||||
/// Access to external variables.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
pub externals: BTreeSet<ImmutableString>,
|
||||
pub externals: BTreeSet<Identifier>,
|
||||
/// Function doc-comments (if any).
|
||||
pub comments: StaticVec<String>,
|
||||
}
|
||||
@@ -144,7 +145,7 @@ impl<'a> Into<ScriptFnMetadata<'a>> for &'a ScriptFnDef {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AST {
|
||||
/// Source of the [`AST`].
|
||||
source: Option<ImmutableString>,
|
||||
source: Option<Identifier>,
|
||||
/// Global statements.
|
||||
body: StmtBlock,
|
||||
/// Script-defined functions.
|
||||
@@ -190,7 +191,7 @@ impl AST {
|
||||
pub fn new_with_source(
|
||||
statements: impl IntoIterator<Item = Stmt>,
|
||||
functions: impl Into<Shared<Module>>,
|
||||
source: impl Into<ImmutableString>,
|
||||
source: impl Into<Identifier>,
|
||||
) -> Self {
|
||||
Self {
|
||||
source: Some(source.into()),
|
||||
@@ -210,12 +211,12 @@ impl AST {
|
||||
}
|
||||
/// Clone the source, if any.
|
||||
#[inline(always)]
|
||||
pub(crate) fn clone_source(&self) -> Option<ImmutableString> {
|
||||
pub(crate) fn clone_source(&self) -> Option<Identifier> {
|
||||
self.source.clone()
|
||||
}
|
||||
/// Set the source.
|
||||
#[inline(always)]
|
||||
pub fn set_source(&mut self, source: impl Into<ImmutableString>) -> &mut Self {
|
||||
pub fn set_source(&mut self, source: impl Into<Identifier>) -> &mut Self {
|
||||
self.source = Some(source.into());
|
||||
|
||||
if let Some(module) = Shared::get_mut(&mut self.functions) {
|
||||
@@ -756,7 +757,7 @@ impl AsRef<Module> for AST {
|
||||
}
|
||||
}
|
||||
|
||||
/// _(INTERNALS)_ An identifier containing an [immutable string][ImmutableString] name and a [position][Position].
|
||||
/// _(INTERNALS)_ An identifier containing a name and a [position][Position].
|
||||
/// Exported under the `internals` feature only.
|
||||
///
|
||||
/// # Volatile Data Structure
|
||||
@@ -765,7 +766,7 @@ impl AsRef<Module> for AST {
|
||||
#[derive(Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Ident {
|
||||
/// Identifier name.
|
||||
pub name: ImmutableString,
|
||||
pub name: Identifier,
|
||||
/// Declaration position.
|
||||
pub pos: Position,
|
||||
}
|
||||
@@ -869,11 +870,11 @@ pub enum Stmt {
|
||||
/// `do` `{` stmt `}` `while`|`until` expr
|
||||
Do(Box<StmtBlock>, Expr, bool, Position),
|
||||
/// `for` id `in` expr `{` stmt `}`
|
||||
For(Expr, Box<(String, StmtBlock)>, Position),
|
||||
For(Expr, Box<(Identifier, StmtBlock)>, Position),
|
||||
/// \[`export`\] `let` id `=` expr
|
||||
Let(Expr, Ident, bool, Position),
|
||||
Let(Expr, Box<Ident>, bool, Position),
|
||||
/// \[`export`\] `const` id `=` expr
|
||||
Const(Expr, Ident, bool, Position),
|
||||
Const(Expr, Box<Ident>, bool, Position),
|
||||
/// expr op`=` expr
|
||||
Assignment(Box<(Expr, Expr, Option<OpAssignment>)>, Position),
|
||||
/// `{` stmt`;` ... `}`
|
||||
@@ -894,7 +895,7 @@ pub enum Stmt {
|
||||
Return(ReturnType, Option<Expr>, Position),
|
||||
/// `import` expr `as` var
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Import(Expr, Option<Ident>, Position),
|
||||
Import(Expr, Option<Box<Ident>>, Position),
|
||||
/// `export` var `as` var `,` ...
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Export(Vec<(Ident, Option<Ident>)>, Position),
|
||||
@@ -1256,7 +1257,7 @@ pub struct CustomExpr {
|
||||
/// List of keywords.
|
||||
pub keywords: StaticVec<Expr>,
|
||||
/// List of tokens actually parsed.
|
||||
pub tokens: Vec<ImmutableString>,
|
||||
pub tokens: Vec<Identifier>,
|
||||
/// Delta number of variables in the scope.
|
||||
pub scope_delta: isize,
|
||||
}
|
||||
@@ -1400,11 +1401,11 @@ pub struct FnCallExpr {
|
||||
/// List of function call argument expressions.
|
||||
pub args: StaticVec<Expr>,
|
||||
/// List of function call arguments that are constants.
|
||||
pub constant_args: StaticVec<(Dynamic, Position)>,
|
||||
pub constant_args: smallvec::SmallVec<[(Dynamic, Position); 2]>,
|
||||
/// Namespace of the function, if any. Boxed because it occurs rarely.
|
||||
pub namespace: Option<NamespaceRef>,
|
||||
/// Function name.
|
||||
pub name: ImmutableString,
|
||||
pub name: Identifier,
|
||||
}
|
||||
|
||||
impl FnCallExpr {
|
||||
@@ -1554,7 +1555,7 @@ pub enum Expr {
|
||||
/// Variable access - (optional index, optional (hash, modules), variable name)
|
||||
Variable(Box<(Option<NonZeroUsize>, Option<(u64, NamespaceRef)>, Ident)>),
|
||||
/// Property access - ((getter, hash), (setter, hash), prop)
|
||||
Property(Box<((ImmutableString, u64), (ImmutableString, u64), Ident)>),
|
||||
Property(Box<((Identifier, u64), (Identifier, u64), Ident)>),
|
||||
/// { [statement][Stmt] ... }
|
||||
Stmt(Box<StmtBlock>),
|
||||
/// func `(` expr `,` ... `)`
|
||||
@@ -1609,7 +1610,7 @@ impl Expr {
|
||||
Self::Map(x, _) if self.is_constant() => {
|
||||
let mut map = x.1.clone();
|
||||
x.0.iter().for_each(|(k, v)| {
|
||||
*map.get_mut(&k.name).unwrap() = v.get_constant_value().unwrap()
|
||||
*map.get_mut(k.name.as_str()).unwrap() = v.get_constant_value().unwrap()
|
||||
});
|
||||
Dynamic(Union::Map(Box::new(map), AccessMode::ReadOnly))
|
||||
}
|
||||
|
Reference in New Issue
Block a user