Skip to content

Commit

Permalink
Merge pull request #35 from nsajko/mandatory_arguments
Browse files Browse the repository at this point in the history
make all `maketerm` arguments mandatory
  • Loading branch information
ChrisRackauckas authored May 29, 2024
2 parents 801430a + 1f87c6c commit 3331fd2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/TermInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function metadata end


"""
maketerm(T, head, children, type=nothing, metadata=nothing)
maketerm(T, head, children, type, metadata)
Constructs an expression. `T` is a constructor type, `head` and `children` are
the head and tail of the S-expression, `type` is the `type` of the S-expression.
Expand All @@ -125,8 +125,7 @@ the sub-expression. `T` will be the type of the outer expression.
Packages providing expression types _must_ implement this method for each expression type.
If your types do not support type information or metadata, you still need to accept
these arguments and may choose to not use them.
Giving `nothing` for `type` or `metadata` results in a default being selected.
"""

function maketerm end
Expand Down
2 changes: 1 addition & 1 deletion src/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ children(e::Expr) = e.args
operation(e::Expr) = iscall(e) ? first(children(e)) : error("operation called on a non-function call expression")
arguments(e::Expr) = iscall(e) ? @view(e.args[2:end]) : error("arguments called on a non-function call expression")

function maketerm(::Type{Expr}, head, args, type=nothing, metadata=nothing)
function maketerm(::Type{Expr}, head, args, type, metadata)
Expr(head, args...)
end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using Test
@test arguments(ex) == [:a, :b]
@test isexpr(ex)
@test iscall(ex)
@test ex == maketerm(Expr, :call, [:f, :a, :b])
@test ex == maketerm(Expr, :call, [:f, :a, :b], nothing, nothing)


ex = :(arr[i, j])
Expand All @@ -18,5 +18,5 @@ using Test
@test_throws ErrorException arguments(ex)
@test isexpr(ex)
@test !iscall(ex)
@test ex == maketerm(Expr, :ref, [:arr, :i, :j])
@test ex == maketerm(Expr, :ref, [:arr, :i, :j], nothing, nothing)
end

0 comments on commit 3331fd2

Please sign in to comment.