From 5fb7f9474841b217ee893fa12b1085a8f611cf0c Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sun, 26 May 2024 04:43:06 +0200 Subject: [PATCH] make all `maketerm` arguments mandatory Fixes #33 --- src/TermInterface.jl | 7 +++---- src/expr.jl | 2 +- test/runtests.jl | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/TermInterface.jl b/src/TermInterface.jl index a244a7d..5c297a2 100644 --- a/src/TermInterface.jl +++ b/src/TermInterface.jl @@ -111,7 +111,7 @@ 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. @@ -127,11 +127,10 @@ 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(T::Type, head, children, type=nothing, metadata=nothing) +function maketerm(T::Type, head, children, type, metadata) error("maketerm for $T is not implemented") end export maketerm diff --git a/src/expr.jl b/src/expr.jl index 2a5f1d6..5b19b98 100644 --- a/src/expr.jl +++ b/src/expr.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 8508a2c..0e9e5dc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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]) @@ -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