From 0da4aefd99bdff86a21a9ba1e854c924f1dd1f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 25 Jul 2018 18:51:03 +0200 Subject: [PATCH] Update preprocessor submodule with macroprocessor refactoring By the way, add new tests for the macroprocessor. --- preprocessor | 2 +- tests/Makefile.am | 2 +- ...xample1_macroif.mod => example1_macro.mod} | 36 ++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) rename tests/{example1_macroif.mod => example1_macro.mod} (58%) diff --git a/preprocessor b/preprocessor index 49e1c43ae..9cf3e034d 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 49e1c43aed1acd80237d7fe911603ac4dd52d67d +Subproject commit 9cf3e034de954f9b221fd72f6cd02334d47bda89 diff --git a/tests/Makefile.am b/tests/Makefile.am index 651f1ba03..a9472adfe 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -64,7 +64,7 @@ MODFILES = \ example1_with_tags.mod \ example1_irf_shocks.mod \ example1_abs_sign.mod \ - example1_macroif.mod \ + example1_macro.mod \ example1long.mod \ example2long.mod \ example2long_use_dll.mod \ diff --git a/tests/example1_macroif.mod b/tests/example1_macro.mod similarity index 58% rename from tests/example1_macroif.mod rename to tests/example1_macro.mod index 02749cc3b..34a81277f 100644 --- a/tests/example1_macroif.mod +++ b/tests/example1_macro.mod @@ -1,4 +1,5 @@ -// Example 1 from Collard's guide to Dynare +// Various tests for the macroprocessor + var y, c, k, a, h, b; varexo e, u; @@ -21,6 +22,39 @@ theta = 2.95; phi = 0.1; @#endif +@#define a = 5 +@#define b = 2*(a + 3)/4-1 +@#if b != 3 +@#error "Arithmetic problem" +@#endif + +@#define v = [ "a", 1, 2:3] +@#define empty = [] +@#define z = v[2:3] +@#if z != [ 1, [ 2, 3 ]] || length(v) != 3 || 5 in v || !("a" in v) || length(empty) != 0 +@#error "Array problem" +@#endif + +@#define w = [ 1 ] +@#for elt in v +@#define w = w + [ elt ] +@#endfor +@#if w != [ 1, "a", 1, 2:3] +@#error "For loop problem" +@#endif + +@#define s = "abcde" +@#if length(s) != 5 || s[3:4] != "cd" +@#error "String problem" +@#endif + +@#define f(y, z) = "@{y}bar@{z}" +@#if f("foo", "baz") != "foobarbaz" +@#error "Function problem" +@#endif + + + model; c*theta*h^(1+psi)=(1-alpha)*y; k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))