init commit
This commit is contained in:
+39
-19
@@ -83,26 +83,46 @@ defmodule CljElixir.Compiler do
|
||||
@spec eval_string(String.t(), keyword()) :: {:ok, term(), keyword()} | {:error, list()}
|
||||
def eval_string(source, opts \\ []) do
|
||||
with {:ok, ast} <- compile_string(source, opts) do
|
||||
try do
|
||||
bindings = opts[:bindings] || []
|
||||
env_opts = build_eval_opts(opts)
|
||||
{result, new_bindings} = Code.eval_quoted(ast, bindings, env_opts)
|
||||
{:ok, result, new_bindings}
|
||||
rescue
|
||||
e ->
|
||||
file = opts[:file] || "nofile"
|
||||
eval_ast(ast, opts)
|
||||
end
|
||||
end
|
||||
|
||||
{:error,
|
||||
[
|
||||
%{
|
||||
severity: :error,
|
||||
message: format_eval_error(e),
|
||||
file: file,
|
||||
line: extract_line(e),
|
||||
col: 0
|
||||
}
|
||||
]}
|
||||
end
|
||||
@doc """
|
||||
Evaluate pre-parsed CljElixir AST forms.
|
||||
|
||||
Runs analyze → transform → eval, skipping the read step.
|
||||
Used by the REPL for incremental re-evaluation of accumulated definitions.
|
||||
|
||||
Returns `{:ok, result, bindings}` on success, or `{:error, diagnostics}` on failure.
|
||||
"""
|
||||
@spec eval_forms(list(), keyword()) :: {:ok, term(), keyword()} | {:error, list()}
|
||||
def eval_forms(forms, opts \\ []) do
|
||||
with {:ok, forms} <- analyze(forms, opts),
|
||||
{:ok, ast} <- transform(forms, opts) do
|
||||
eval_ast(ast, opts)
|
||||
end
|
||||
end
|
||||
|
||||
defp eval_ast(ast, opts) do
|
||||
try do
|
||||
bindings = opts[:bindings] || []
|
||||
env_opts = build_eval_opts(opts)
|
||||
{result, new_bindings} = Code.eval_quoted(ast, bindings, env_opts)
|
||||
{:ok, result, new_bindings}
|
||||
rescue
|
||||
e ->
|
||||
file = opts[:file] || "nofile"
|
||||
|
||||
{:error,
|
||||
[
|
||||
%{
|
||||
severity: :error,
|
||||
message: format_eval_error(e),
|
||||
file: file,
|
||||
line: extract_line(e),
|
||||
col: 0
|
||||
}
|
||||
]}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user