diff --git a/src/frontend/Preprocessor.ml b/src/frontend/Preprocessor.ml index 06c166b507..0a9bbbcc0f 100644 --- a/src/frontend/Preprocessor.ml +++ b/src/frontend/Preprocessor.ml @@ -14,7 +14,10 @@ let include_stack = Stack.create () let include_paths : string list ref = ref [] let included_files : string list ref = ref [] let size () = Stack.length include_stack -let init buf = Stack.push include_stack buf + +let init buf = + Stack.clear include_stack ; + Stack.push include_stack buf let current_buffer () = let buf = Stack.top_exn include_stack in diff --git a/test/stancjs/good_after_bad.js b/test/stancjs/good_after_bad.js new file mode 100644 index 0000000000..041fa6f9d9 --- /dev/null +++ b/test/stancjs/good_after_bad.js @@ -0,0 +1,33 @@ +var stanc = require('../../src/stancjs/stancjs.bc.js'); +var utils = require("./utils/utils.js"); + + + +let bad = ` +parameters { + real y; +} +model { + y ~ std_normal(); +} +model { + y ~ std_normal(); +} +` + +let basic_bad = stanc.stanc("basic_bad", bad, []); +utils.print_error(basic_bad) + +// we now test a syntactically valid model to make sure the parser has cleared its state + +let basic_model = ` +parameters { + real y; +} +model { + y ~ std_normal(); +} +` + +let basic = stanc.stanc("basic", basic_model); +utils.print_error(basic) diff --git a/test/stancjs/stancjs.expected b/test/stancjs/stancjs.expected index e2e725e188..29713a592b 100644 --- a/test/stancjs/stancjs.expected +++ b/test/stancjs/stancjs.expected @@ -149,6 +149,10 @@ real test_rng(real a) { real test_lpdf(real a, real b) { return normal_lpdf(a | b, 1); } +$ node good_after_bad.js +Syntax error in 'string', line 8, column 0 to column 5, parsing error: +Expected "generated quantities {" or end of file after end of model block. + $ node info.js { "inputs": { "a": { "type": "int", "dimensions": 0}, "b": { "type": "real", "dimensions": 0},