-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrates all the lower level code to tree-sitter not touching passes yet.
- Loading branch information
Showing
9 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ target | |
/invalid.rs | ||
/invalid | ||
.direnv/ | ||
g | ||
g | ||
perf.data* | ||
*.svg |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ use std::{ | |
|
||
mod build; | ||
mod dylib_flag; | ||
mod formatting; | ||
mod tree_sitter; | ||
mod passes; | ||
mod processor; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use anyhow::{Context, Result}; | ||
|
||
pub fn parse(source: &str) -> Result<tree_sitter::Tree> { | ||
let mut parser = tree_sitter::Parser::new(); | ||
parser | ||
.set_language(tree_sitter_rust::language()) | ||
.context("loading tree sitter rust grammar")?; | ||
let content_ts = parser.parse(source, None).context("parsing file")?; | ||
Ok(content_ts) | ||
} | ||
|
||
pub fn format(file: tree_sitter::Tree, source: &str) -> anyhow::Result<String> { | ||
let mut s = Vec::new(); | ||
tree_sitter_edit::render(&mut s, &file, source.as_bytes(), &Editor); | ||
|
||
Ok(String::from_utf8(s).unwrap()) | ||
} | ||
|
||
struct Editor; | ||
|
||
impl tree_sitter_edit::Editor for Editor { | ||
fn has_edit(&self, tree: &tree_sitter::Tree, node: &tree_sitter::Node<'_>) -> bool { | ||
false | ||
} | ||
|
||
fn edit( | ||
&self, | ||
source: &[u8], | ||
tree: &tree_sitter::Tree, | ||
node: &tree_sitter::Node<'_>, | ||
) -> Vec<u8> { | ||
unimplemented!() | ||
} | ||
} |