-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace cg-comp with tree-sitter (#83)
* First attempt * Bump tree-sitter-apertium * Toss core tool installation * Single cc build * Tweaks * Bump tree-sitter-apertium
- Loading branch information
Showing
7 changed files
with
46 additions
and
66 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 |
---|---|---|
|
@@ -47,11 +47,6 @@ jobs: | |
- name: Restore Rust cache | ||
uses: Swatinem/rust-cache@v1 | ||
|
||
- name: Install apertium-all-dev | ||
run: wget http://apertium.projectjj.com/apt/install-nightly.sh -O - | sudo bash | ||
- name: Install other language tools | ||
run: sudo apt-get install cg3 | ||
|
||
- name: Install diesel_cli | ||
uses: actions-rs/[email protected] | ||
with: | ||
|
@@ -77,11 +72,6 @@ jobs: | |
- name: Restore Rust cache | ||
uses: Swatinem/rust-cache@v1 | ||
|
||
- name: Install apertium-all-dev | ||
run: wget http://apertium.projectjj.com/apt/install-nightly.sh -O - | sudo bash | ||
- name: Install other language tools | ||
run: sudo apt-get install cg3 | ||
|
||
- name: Install diesel_cli | ||
uses: actions-rs/[email protected] | ||
with: | ||
|
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let ts_dir: PathBuf = ["src", "stats", "tree-sitter-apertium", "tree-sitter-lexd", "src"] | ||
.iter() | ||
.collect(); | ||
let includes = vec![ | ||
PathBuf::from(r"src/stats/tree-sitter-apertium/tree-sitter-lexd/src"), | ||
PathBuf::from(r"src/stats/tree-sitter-apertium/tree-sitter-cg/src"), | ||
]; | ||
cc::Build::new() | ||
.include(&ts_dir) | ||
.file(ts_dir.join("parser.c")) | ||
.compile("tree-sitter-lexd"); | ||
.includes(&includes) | ||
.files(vec![includes[0].join("parser.c"), includes[1].join("parser.c")]) | ||
.compile("tree-sitter"); | ||
} |
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,32 @@ | ||
use rocket_contrib::{json, json::JsonValue}; | ||
use slog::Logger; | ||
use tree_sitter::{Language, Parser, TreeCursor}; | ||
|
||
use crate::{models::StatKind, stats::StatsError}; | ||
|
||
extern "C" { | ||
fn tree_sitter_cg() -> Language; | ||
} | ||
|
||
pub fn get_stats(_logger: &Logger, body: &str) -> Result<Vec<(StatKind, JsonValue)>, StatsError> { | ||
let mut parser = Parser::new(); | ||
let language = unsafe { tree_sitter_cg() }; | ||
parser | ||
.set_language(language) | ||
.map_err(|e| StatsError::Rlx(format!("Unable to load tree-sitter parser: {}", e)))?; | ||
let tree = parser | ||
.parse(body, None) | ||
.ok_or_else(|| StatsError::Rlx("Unable to parse rlx file".to_string()))?; | ||
|
||
let mut rules: usize = 0; | ||
|
||
let mut walker: TreeCursor = tree.root_node().walk(); | ||
for child in tree.root_node().children(&mut walker) { | ||
let kind = child.kind(); | ||
if kind == "rule" || kind.starts_with("rule_") { | ||
rules += 1; | ||
} | ||
} | ||
|
||
Ok(vec![(StatKind::Rules, json!(rules))]) | ||
} |
Submodule tree-sitter-apertium
updated
38 files
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