pub struct Repl { /* private fields */ }Expand description
A small persistent REPL environment wrapper.
Notes:
Repl::new()creates a persistent environment and initializes built-ins.Repl::eval(&self, code)evaluates the provided code in the persistent env so variables, functions and imports persist between calls.
Implementations§
Source§impl Repl
impl Repl
Sourcepub fn eval<T: AsRef<str>>(&self, script: T) -> Result<Value, JSError>
pub fn eval<T: AsRef<str>>(&self, script: T) -> Result<Value, JSError>
Evaluate a script in the persistent environment. Returns the evaluation result or an error.
Sourcepub fn is_complete_input(src: &str) -> bool
pub fn is_complete_input(src: &str) -> bool
Returns true when the given input looks like a complete JavaScript
top-level expression/program piece (i.e. brackets and template expressions
are balanced, strings/comments/regex literals are properly closed).
This uses heuristics (not a full parser) but covers common REPL cases:
- ignores brackets inside single/double-quoted strings
- supports template literals and nested ${ … } expressions
- ignores brackets inside // and /* */ comments
- attempts to detect regex literals using a simple context heuristic and ignores brackets inside them