Class Repl

java.lang.Object
ch.turic.Repl

public class Repl extends Object
A REPL (Read-Eval-Print Loop) interpreter that executes code incrementally. This interpreter can process and execute small pieces of code sequentially, maintaining state between executions.

The interpreter manages its own context and provides support for code completion through the completions() method. It handles lexical analysis, program analysis, and execution of the provided code.

Thread Safety: This class is not thread-safe and should not be used in a multi-threaded environment. Each instance maintains mutable state that could be corrupted by concurrent access.

  • Field Details

    • ctx

      public ch.turic.memory.Context ctx
    • lexes

      public ch.turic.analyzer.LexList lexes
  • Constructor Details

    • Repl

      public Repl()
  • Method Details

    • completions

      public Collection<String> completions()
    • execute

      public Object execute(String source) throws BadSyntax, ExecutionException
      Executes the provided source code and returns the result of the execution.
      Parameters:
      source - The source code to execute as a string
      Returns:
      The result of executing the code, which can be any Object
      Throws:
      BadSyntax - if the provided code contains syntax errors
      ExecutionException - if an error occurs during code execution