Skip to content

Commit

Permalink
update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi committed Jul 6, 2024
1 parent c4663df commit 20f3d10
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/codeblock.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""
CodeEvaluation.codeblock!(sandbox::Sandbox, code::AbstractString) -> Result
CodeEvaluation.codeblock!(sandbox::Sandbox, code::AbstractString; kwargs...) -> Result
...
Evaluates a block of Julia code `code` in the `sandbox`, as if it is included as
a script. Returns a [`Result`](@ref) object, containing the result of the evaluation.
# Keywords
- `color::Bool=true`: determines whether or not to capture colored output (i.e. controls
the IOContext).
"""
function codeblock!(sandbox::Sandbox, code::AbstractString; color::Bool=true)
exprs = CodeEvaluation.parseblock(code)
Expand Down
38 changes: 37 additions & 1 deletion src/replblock.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
"""
struct CodeBlock
Represents a single block in a sequence of REPL inputs and outputs in the [`REPLResult`](@ref) object.
# Properties
- `input::Bool`: whether this block represents a REPL input (i.e. an input `julia>`) or an output
from the REPL (either the plain string representation of the object, or the standard output or error
stream contents).
- `code::String`: the contents of the block
"""
struct CodeBlock
input::Bool
code::String
end

"""
struct REPLResult
The result from a [`replblock!`](@ref) evaluation. It contains a sequence of input and output blocks.
The inputs and outputs are separated, so that it would be easy for the users to style them differently
if that is needed.
See also: [`CodeBlock`](@ref), [`join_to_string`](@ref).
# Properties
- `sandbox :: Sandbox`: The `Sandbox` object in which the code was evaluated.
- `blocks :: Vector{CodeBlock}`: The sequence of input and output block text.
"""
struct REPLResult
sandbox::Sandbox
Expand All @@ -22,11 +47,22 @@ function join_to_string(result::REPLResult)
end

"""
CodeEvaluation.replblock!(sandbox::Sandbox, code::AbstractString) -> REPLResult
CodeEvaluation.replblock!(sandbox::Sandbox, code::AbstractString; kwargs...) -> REPLResult
Evaluates the code in a special REPL-mode, where `code` gets split up into expressions,
each of which gets evaluated one by one. The output is a string representing what this
would look like if each expression had been evaluated in the REPL as separate commands.
See also: [`REPLResult`](@ref), [`join_to_string`](@ref).
# Keywords
- `color::Bool=true`: determines whether or not to capture colored output (i.e. controls
the IOContext).
- `post_process_inputs`: a function that can be used to post-process the input expressions.
It does not affect the code that is evaluated, just what gets included in the REPL input
blocks.
"""
function replblock!(
sandbox::Sandbox, code::AbstractString;
Expand Down
8 changes: 2 additions & 6 deletions src/sandbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ Returns the name of the underlying module of the `Sandbox` object.
"""
Base.nameof(sandbox::Sandbox) = nameof(sandbox.m)

"""
abstract type AbstractValue end
Will either [`AnsValue`](@ref) if the code evaluated successfully, or [`ExceptionValue`](@ref)
if it did not.
"""
# Will either be [`AnsValue`](@ref) if the code evaluated successfully,
# or [`ExceptionValue`](@ref) if it did not.
abstract type AbstractValue end

struct AnsValue <: AbstractValue
Expand Down

0 comments on commit 20f3d10

Please sign in to comment.