@maniascript/parser
Version:
Maniascript parser
73 lines (72 loc) • 2.17 kB
TypeScript
import { Node, Identifier, BlockStatement, type AST } from './ast.js';
declare class ScopeManager {
#private;
scopes: Scope[];
nodeToScope: Map<Node, Scope>;
constructor();
openScope(type: ScopeType, node: Node): void;
closeScope(): void;
getScope(node: Node): Scope | null;
static canCreateBlockScope(blockStatement: BlockStatement): boolean;
analyze(ast: AST): void;
}
declare enum ScopeType {
Global = "Global",
Function = "Function",
For = "For",
Foreach = "Foreach",
While = "While",
Meanwhile = "Meanwhile",
SwitchCase = "SwitchCase",
ConditionalBranch = "ConditionalBranch",
LabelDeclaration = "LabelDeclaration",
Block = "Block"
}
interface VariableParameters {
isGlobal?: boolean;
isFunctionParameter?: boolean;
isForValue?: boolean;
isForeachKey?: boolean;
isForeachValue?: boolean;
isTrait?: boolean;
}
declare class Variable implements VariableParameters {
name: string;
references: Reference[];
node: Identifier;
isGlobal: boolean;
isFunctionParameter: boolean;
isForValue: boolean;
isForeachKey: boolean;
isForeachValue: boolean;
isTrait: boolean;
static getNameFromIdentifier(identifier: Identifier): string;
constructor(node: Identifier, parameters?: VariableParameters);
}
declare enum ReferenceFlag {
Read = 0,
Write = 1
}
declare class Reference {
variable: Variable | null;
node: Identifier;
flag: ReferenceFlag;
constructor(variable: Variable | null, node: Identifier);
isRead(): boolean;
isWrite(): boolean;
}
declare class Scope {
type: ScopeType;
variables: Map<string, Variable>;
references: Reference[];
couldReferenceVariableInLabel: boolean;
parent: Scope | null;
children: Scope[];
node: Node;
constructor(type: ScopeType, node: Node, parent: Scope | null);
defineVariable(node: Identifier, parameters?: VariableParameters): Variable;
referenceVariable(node: Identifier): Reference;
getVariable(name: string | Identifier): Variable | null;
referenceLabel(): void;
}
export { ScopeManager, ScopeType, Variable, Scope };