Class REPLContext
DefaultContext to provide
a managed context environment for REPL (Read-Eval-Print Loop) execution.
It maintains an eternal context shared across all instances and supports registering and deregistering contexts with inheritance of variables, functions, and parse tree execution states.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final DefaultContextThe eternal, shared base context for all REPL executions.Fields inherited from class org.daiitech.naftah.parser.DefaultContext
ACCESSIBLE_CLASSES, ARABIC_CLASS_QUALIFIERS, arguments, ASYNC_BOOT_STRAP, awaitingTask, blockImports, BOOT_STRAP_FAILED, BOOT_STRAPPED, BUILTIN_FUNCTIONS, CACHE_PATH, CALL_STACK, CLASS_NAMES, CLASS_QUALIFIERS, CLASSES, CONTEXTS, creatingObject, CURRENT_CONTEXT, CURRENT_LOOKUP_JVM_CLASS_INITIALIZERS, CURRENT_LOOKUP_JVM_FUNCTIONS, CURRENT_TASK_SCOPE, declarationOfAssignment, depth, FORCE_BOOT_STRAP, functionCallId, functions, implementationName, implementations, IMPORTS, INSTANTIABLE_CLASSES, JVM_CLASS_INITIALIZERS, JVM_FUNCTIONS, LOADER_CONSUMER, LOADER_TASK, LOOP_STACK, loopLabel, loopVariables, MINIMAL_CACHE_PATH, MINIMAL_LOADER_CONSUMER, MINIMAL_LOADER_TASK, owner, parameters, parent, parseTreeExecution, parsingAssignment, parsingFunctionCallId, pendingRemoval, pendingTasks, SHOULD_BOOT_STRAP, variables -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clears all REPL-related contexts.static voiddropFunctions(String[] ids) Removes the specified functions from the current REPL session.static voiddropImplementations(String[] ids) Removes the specified implementations (behaviors) from the current REPL session.static voiddropImports(String[] ids) Removes the specified imports from the REPL session.static voiddropVariables(String[] ids) Removes the specified variables from the current REPL session.static Collection<DeclaredFunction<?>>Returns all declared functions in the current REPL session.static Collection<DeclaredImplementation>Returns all declared implementations (behaviors) in the current REPL session.static Collection<String>Returns all currently imported elements in the REPL session.static Collection<DeclaredVariable>Returns all declared variables in the current REPL session.static DefaultContextRegisters a new context using the eternal context as the parent.static DefaultContextregisterContext(Map<String, DeclaredParameter> parameters, Map<String, Object> arguments) Registers a new context with specified parameters and arguments.static DefaultContextregisterContext(DefaultContext parent) Registers a newDefaultContextwith the specified parent context.static DefaultContextregisterContext(DefaultContext parent, Map<String, String> blockImports) Registers a newDefaultContextwith the specified parent context and an initial set of block imports.static DefaultContextregisterContext(DefaultContext parent, Map<String, String> blockImports, Map<String, DeclaredParameter> parameters, Map<String, Object> arguments) Registers a fully configuredDefaultContextwith the specified parent context, block imports, declared parameters, and argument values.Methods inherited from class org.daiitech.naftah.parser.DefaultContext
bootstrap, callLoader, cleanClassThreadLocals, cleanThreadLocals, completeTask, containsDeclaredFunction, containsDeclaredImplementation, containsDeclaredImplementation, containsFunction, containsFunctionArgument, containsFunctionParameter, containsJvmClassInitializer, containsLocalVariable, containsLoopVariable, containsVariable, copyDeclarationsToParent, currentLoopLabel, defaultBootstrap, defineFunction, defineFunctionArgument, defineFunctionArguments, defineFunctionParameter, defineFunctionParameters, defineImplementation, defineImport, defineLoopVariable, defineVariable, defineVariables, deregisterContext, deregisterContext, deserializeClassScanningResult, doGetJavaType, endScope, generateCallId, generateLoopId, generateParameterOrArgumentName, getAccessibleClasses, getBuiltinFunctions, getChildren, getChildren, getClasses, getCompletions, getContextsByDepth, getCurrentContext, getCurrentLookupJvmClassInitializers, getCurrentLookupJvmFunctions, getDeclarationOfAssignment, getDeclaredImplementationFunction, getDepth, getFunction, getFunctionArgument, getFunctionArgumentName, getFunctionCallId, getFunctionParameter, getFunctionParameterName, getImplementationName, getInstantiableClasses, getJavaType, getJvmClassInitializer, getJvmClassInitializers, getJvmFunctions, getLoopLabel, getLoopLabels, getLoopVariable, getLoopVariableName, getLoopVariableNames, getParseTreeExecution, getSiblings, getVariable, getVariable, hasAnyExecutedChildOrSubChildOfType, isAwaitingTask, isCreatingObject, isExecuted, isParsingAssignment, isParsingFunctionCallId, lookupJvmClassInitializer, lookupJvmFunctions, loopContainsLabel, markExecuted, markForRemoval, matchImport, matchVariable, newNaftahBugExistentFunctionArgumentError, newNaftahBugExistentFunctionError, newNaftahBugExistentFunctionParameterError, newNaftahBugExistentImplementationError, newNaftahBugExistentVariableError, newNaftahBugForeachTargetDuplicatesError, newNaftahBugForeachTargetDuplicatesError, newNaftahBugVariableNotFoundError, newNaftahBugVariableNotFoundError, peekCall, popCall, popLoop, prepareLoopVariable, prepareParseTreeExecution, pushCall, pushLoop, putAllInBuiltinFunctions, registerContext, registerTask, removeLoopVariable, removeVariable, serializeClassScanningResult, setAwaitingTask, setBuiltinFunctions, setContextFromClassScanningResult, setCreatingObject, setCurrentContext, setCurrentLookupJvmClassInitializers, setCurrentLookupJvmFunctions, setDeclarationOfAssignment, setFunction, setFunctionArgument, setFunctionCallId, setFunctionParameter, setImplementation, setImplementationName, setLoopLabel, setLoopVariable, setParsingAssignment, setParsingFunctionCallId, setVariable, startScope, tryDeregisterContext
-
Field Details
-
ETERNAL_CONTEXT
The eternal, shared base context for all REPL executions.Initialized statically with empty parameters and arguments, and prepared for parse tree execution.
-
-
Constructor Details
-
REPLContext
public REPLContext()
-
-
Method Details
-
registerContext
Registers a new context using the eternal context as the parent.The new context is prepared for parse tree execution before returning.
- Returns:
- a new
DefaultContextinstance withETERNAL_CONTEXTas parent
-
registerContext
public static DefaultContext registerContext(Map<String, DeclaredParameter> parameters, Map<String, Object> arguments) Registers a new context with specified parameters and arguments.The new context uses the eternal context as its parent. It is prepared for parse tree execution before returning.
- Parameters:
parameters- the declared parameters for the new contextarguments- the argument values for the new context- Returns:
- a new
DefaultContextinitialized with given parameters and arguments
-
registerContext
Registers a newDefaultContextwith the specified parent context.The new context inherits configuration and state from the parent context, and is automatically prepared for parse tree execution before being returned.
- Parameters:
parent- the parentDefaultContextof the new context; may benull- Returns:
- a new
DefaultContextinstance linked to the specified parent
-
registerContext
public static DefaultContext registerContext(DefaultContext parent, Map<String, String> blockImports) Registers a newDefaultContextwith the specified parent context and an initial set of block imports.The new context inherits its parent’s configuration and is initialized with the provided
blockImportsmapping. It is automatically prepared for parse tree execution before being returned.- Parameters:
parent- the parentDefaultContextof the new context; may benullblockImports- a map of block-level imports to associate with the new context; may benull- Returns:
- a new
DefaultContextinstance configured with the specified parent and block imports
-
registerContext
public static DefaultContext registerContext(DefaultContext parent, Map<String, String> blockImports, Map<String, DeclaredParameter> parameters, Map<String, Object> arguments) Registers a fully configuredDefaultContextwith the specified parent context, block imports, declared parameters, and argument values.This method provides the most flexible initialization for new contexts. The created context inherits from its parent, applies the given block imports, parameters, and argument mappings, and is automatically prepared for parse tree execution before being returned.
- Parameters:
parent- the parentDefaultContextof the new context; may benullblockImports- a map of block-level imports to associate with the new context; may benullparameters- a map of declared parameters to register with the new context; may benullarguments- a map of argument values corresponding to the declared parameters; may benull- Returns:
- a new
DefaultContextinstance initialized with the specified configuration
-
clear
public static void clear()Clears all REPL-related contexts.This method performs two main actions:
- Calls
DefaultContext.clear()to remove all globally stored contexts. - Invokes
DefaultContext.cleanThreadLocals()to reset any thread-local data associated with the REPL, preventing leakage across sessions.
- Calls
-
getImports
Returns all currently imported elements in the REPL session.Each import is returned as a string in the format:
<imported_element> تحت_إسم <alias>(meaning "under the name").- Returns:
- a collection of strings representing all imports and their aliases
-
dropImports
Removes the specified imports from the REPL session.- Parameters:
ids- an array of import identifiers to remove; whitespace is trimmed
-
getVariables
Returns all declared variables in the current REPL session.- Returns:
- a collection of
DeclaredVariableobjects
-
dropVariables
Removes the specified variables from the current REPL session.- Parameters:
ids- an array of variable names to remove; whitespace is trimmed
-
getFunctions
Returns all declared functions in the current REPL session.- Returns:
- a collection of
DeclaredFunctionobjects
-
dropFunctions
Removes the specified functions from the current REPL session.- Parameters:
ids- an array of function names to remove; whitespace is trimmed
-
getImplementations
Returns all declared implementations (behaviors) in the current REPL session.- Returns:
- a collection of
DeclaredImplementationobjects
-
dropImplementations
Removes the specified implementations (behaviors) from the current REPL session.- Parameters:
ids- an array of implementation names to remove; whitespace is trimmed
-