Skip to content

Commit

Permalink
Merge pull request #1074 from stan-dev/clear-lexing-stack
Browse files Browse the repository at this point in the history
Clear lexing stack before parsing starts
  • Loading branch information
WardBrian authored Dec 10, 2021
2 parents 6fa471d + a8d1c3d commit 8b92b84
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/frontend/Preprocessor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test/stancjs/good_after_bad.js
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions test/stancjs/stancjs.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 8b92b84

Please sign in to comment.