From 8720599818df119abf21b2398402e9f81a2f7890 Mon Sep 17 00:00:00 2001 From: Thomas Purdy Date: Tue, 26 Sep 2023 22:02:13 -0600 Subject: [PATCH] @feet with no arguments gives an empty Vector{StockAndFlow0}. Errors in @foot and @feet no longer occur at the macro replace stage. --- src/Syntax.jl | 9 +++++++-- test/Syntax.jl | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Syntax.jl b/src/Syntax.jl index 0f4c89e5..b14566bb 100644 --- a/src/Syntax.jl +++ b/src/Syntax.jl @@ -990,6 +990,11 @@ macro feet(block::Expr) end end +macro feet() + quote + Vector{StockAndFlow0}() + end +end """ create_foot(block :: Expr) @@ -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}() diff --git a/test/Syntax.jl b/test/Syntax.jl index 64ee0308..22c55e64 100755 --- a/test/Syntax.jl +++ b/test/Syntax.jl @@ -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") @@ -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