Skip to content

Commit a4a3d82

Browse files
committed
produce values like we had been doing
1 parent 185dcdd commit a4a3d82

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

crates/quarto-markdown-pandoc/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ struct Args {
3434
#[arg(long = "loose")]
3535
loose: bool,
3636

37-
#[arg(long = "_internal-report-error-state", hide = true)]
37+
#[arg(
38+
long = "_internal-report-error-state",
39+
hide = true,
40+
default_value_t = false
41+
)]
3842
_internal_report_error_state: bool,
3943
}
4044

crates/quarto-markdown-pandoc/src/readers/qmd.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,17 @@ pub fn read<T: Write>(
7171
let tree = parser
7272
.parse(&input_bytes, None)
7373
.expect("Failed to parse input");
74+
log_observer.parses.iter().for_each(|parse| {
75+
writeln!(output_stream, "tree-sitter parse:").unwrap();
76+
parse
77+
.messages
78+
.iter()
79+
.for_each(|msg| writeln!(output_stream, " {}", msg).unwrap());
80+
writeln!(output_stream, "---").unwrap();
81+
});
7482
if log_observer.had_errors() {
7583
return Err(produce_error_message(input_bytes, &log_observer, filename));
7684
}
77-
log_observer.parses.into_iter().for_each(|parse| {
78-
eprintln!("tree-sitter parse:");
79-
parse.messages.iter().for_each(|msg| eprintln!(" {}", msg));
80-
eprintln!("---");
81-
});
8285

8386
let depth = crate::utils::concrete_tree_depth::concrete_tree_depth(&tree);
8487
// this is here mostly to prevent our fuzzer from blowing the stack

crates/quarto-markdown-pandoc/src/readers/qmd_error_messages.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ pub fn produce_error_message(
1919
let mut result: Vec<String> = vec![];
2020

2121
for parse in &tree_sitter_log.parses {
22-
if !parse.found_accept {
23-
// there was an error in the block structure; report that.
24-
for state in &parse.error_states {
25-
let mut msg = error_message_from_parse_state(input_bytes, state, filename);
26-
result.append(&mut msg);
27-
}
22+
// there was an error in the block structure; report that.
23+
for state in &parse.error_states {
24+
let mut msg = error_message_from_parse_state(input_bytes, state, filename);
25+
result.append(&mut msg);
2826
}
2927
}
3028

@@ -61,19 +59,16 @@ pub fn produce_error_message_json(
6159
let mut result: Vec<String> = vec![];
6260

6361
for parse in &tree_sitter_log.parses {
64-
if !parse.found_accept {
65-
// there was an error in the block structure; report that.
66-
for state in &parse.error_states {
67-
result.push(
68-
serde_json::to_string(&serde_json::json!({
69-
"state": state.state,
70-
"sym": state.sym,
71-
"row": state.row,
72-
"column": state.column,
73-
}))
74-
.unwrap(),
75-
);
76-
}
62+
for state in &parse.error_states {
63+
result.push(
64+
serde_json::to_string(&serde_json::json!({
65+
"state": state.state,
66+
"sym": state.sym,
67+
"row": state.row,
68+
"column": state.column,
69+
}))
70+
.unwrap(),
71+
);
7772
}
7873
}
7974

crates/quarto-markdown-pandoc/src/utils/tree_sitter_log_observer.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ pub struct TreeSitterLogObserver {
3737

3838
impl TreeSitterLogObserver {
3939
pub fn had_errors(&self) -> bool {
40-
!self.parses.iter().all(|parse| parse.found_accept)
40+
!self
41+
.parses
42+
.iter()
43+
.all(|parse| parse.found_accept && parse.error_states.is_empty())
4144
}
4245
pub fn log(&mut self, _log_type: tree_sitter::LogType, message: &str) {
4346
// Implement your logging logic here
@@ -151,6 +154,12 @@ impl TreeSitterLogObserver {
151154
params.get("size").unwrap().parse::<usize>().unwrap();
152155
}
153156
"lex_external" | "lex_internal" | "shift" | "reduce" => {}
157+
"accept" => {
158+
self.parses
159+
.last_mut()
160+
.expect("No current parse to log process to")
161+
.found_accept = true;
162+
}
154163
_ => {
155164
if self.state != TreeSitterLogState::InParse {
156165
return;

0 commit comments

Comments
 (0)