Skip to content

Commit

Permalink
@feet with no arguments gives an empty Vector{StockAndFlow0}. Errors in
Browse files Browse the repository at this point in the history
@foot and @feet no longer occur at the macro replace stage.
  • Loading branch information
neonWhiteout committed Sep 27, 2023
1 parent 6719a9a commit 8720599
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ macro feet(block::Expr)
end
end

macro feet()
quote
Vector{StockAndFlow0}()
end
end

"""
create_foot(block :: Expr)
Expand All @@ -1011,8 +1016,8 @@ multiple_links = @foot A => B, A => B # will have two links from A to B.
function create_foot(block::Expr)
@match block.head begin
:tuple => begin
if length(block.args) < 2 # case for create_foot(:())
return error("Cannot create foot with no arguments.")
if isempty(block.args) # case for create_foot(:())
error("Cannot create foot with zero arguments.")
end
foot_s = Vector{Symbol}()
foot_sv = Vector{Symbol}()
Expand Down
5 changes: 3 additions & 2 deletions test/Syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Base: is_unary_and_binary_operator
using Test
using StockFlow
using StockFlow.Syntax
using StockFlow.Syntax: is_binop_or_unary, sum_variables, infix_expression_to_binops, fnone_value_or_vector, extract_function_name_and_args_expr, is_recursive_dyvar, create_foot, apply_flags, substitute_symbols
using StockFlow.Syntax: is_binop_or_unary, sum_variables, infix_expression_to_binops, fnone_value_or_vector, extract_function_name_and_args_expr, is_recursive_dyvar, create_foot, apply_flags, substitute_symbols, DSLArgument

@testset "Stratification DSL" begin
include("syntax/Stratification.jl")
Expand Down Expand Up @@ -342,10 +342,11 @@ end
foot(:J, (:K, :Q), (:J => :K, :J => :Q))
]

@test (@feet ) == Vector{StockAndFlow0}();
end

@testset "feet syntax fails on invalid feet" begin # mostly to check that an exception is thrown even if some of the feet are valid.
@test_throws ErrorException @feet A => B => C # eval required so the errors occur at runtime, rather than at compilation
@test_throws ErrorException @feet A => B => C
@test_throws ErrorException @feet begin A => B; =>(D,E,F) end
@test_throws ErrorException @feet begin A => B; 1 => 2; end
end
Expand Down

0 comments on commit 8720599

Please sign in to comment.