Skip to content

Commit

Permalink
Make the AI rabbit happy
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Mar 26, 2024
1 parent 14083df commit b08fa85
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ use tree_sitter::Parser;
#[cfg(feature = "grit-parser")]
pub fn parse_input_file(lang: &TargetLanguage, input: &str, path: &Path) -> Result<InputFile> {
use crate::tree_sitter_serde::tree_sitter_node_to_json;
use anyhow::Context;
use marzano_language::language::Language;
use serde_json::to_string_pretty;

let mut parser = Parser::new().unwrap();
parser.set_language(lang.get_ts_language()).unwrap();
let tree = parser.parse(input.as_bytes(), None).unwrap().unwrap();
let mut parser = Parser::new().context("Failed to create new parser")?;
parser
.set_language(lang.get_ts_language())
.context("Failed to set language for parser")?;
let tree = parser
.parse(input.as_bytes(), None)
.context("Failed to parse input")?
.context("Parsed tree is empty")?;
let input_file_debug_text = to_string_pretty(&tree_sitter_node_to_json(
&tree.root_node(),
input,
Some(lang),
))
.unwrap();
.context("Failed to convert tree to pretty JSON string")?;
Ok(InputFile {
source_file: path.to_string_lossy().to_string(),
syntax_tree: input_file_debug_text,
Expand Down

0 comments on commit b08fa85

Please sign in to comment.