@@ -18,10 +18,9 @@ std::string escape_json(const std::string& s) {
18
18
return o.str ();
19
19
}
20
20
21
- std::function<void (size_t , size_t , const std::string&)> makeJSONFormatter (std::string& json) {
22
- auto init = std::make_shared<bool >(true );
23
-
24
- return [&json, init](size_t ln, size_t col, const std::string& msg) mutable {
21
+ std::function<void (size_t , size_t , const std::string&)> makeJSONFormatter (std::string& json, bool & init) {
22
+ init = true ;
23
+ return [&](size_t ln, size_t col, const std::string& msg) mutable {
25
24
if (!init) {
26
25
json += " ," ;
27
26
}
@@ -30,12 +29,14 @@ std::function<void(size_t, size_t, const std::string&)> makeJSONFormatter(std::s
30
29
json += R"( "col":)" + std::to_string (col) + " ," ;
31
30
json += R"( "msg":")" + escape_json (msg) + R"( ")" ;
32
31
json += " }" ;
33
- *init = false ;
32
+
33
+ init = false ;
34
34
};
35
35
}
36
36
37
37
bool parse_grammar (const std::string& text, peg::parser& peg, std::string& json) {
38
- peg.log = makeJSONFormatter (json);
38
+ bool init;
39
+ peg.log = makeJSONFormatter (json, init);
39
40
json += " [" ;
40
41
auto ret = peg.load_grammar (text.data (), text.size ());
41
42
json += " ]" ;
@@ -45,7 +46,8 @@ bool parse_grammar(const std::string& text, peg::parser& peg, std::string& json)
45
46
bool parse_code (const std::string& text, peg::parser& peg, std::string& json,
46
47
std::shared_ptr<peg::Ast>& ast) {
47
48
peg.enable_ast ();
48
- peg.log = makeJSONFormatter (json);
49
+ bool init;
50
+ peg.log = makeJSONFormatter (json, init);
49
51
json += " [" ;
50
52
auto ret = peg.parse_n (text.data (), text.size (), ast);
51
53
json += " ]" ;
0 commit comments