Skip to content

Commit de41e7c

Browse files
authored
feat: more languages (#25)
* Update features * Add a bunch of languages * Disable languages * Enable ts
1 parent 761421e commit de41e7c

File tree

11 files changed

+189
-6
lines changed

11 files changed

+189
-6
lines changed

Cargo.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ log = { workspace = true }
1515
rayon = { workspace = true}
1616
sysinfo = "0.33.1"
1717
rkyv.workspace = true
18+
[features]
19+
# python = [ "codegen-sdk-cst/python"] # TODO: Add python support
20+
typescript = [ "codegen-sdk-cst/typescript"]
21+
tsx = [ "codegen-sdk-cst/tsx"]
22+
jsx = [ "codegen-sdk-cst/jsx"]
23+
javascript = [ "codegen-sdk-cst/typescript"]
24+
json = [ "codegen-sdk-cst/json"]
25+
java = [ "codegen-sdk-cst/java"]
26+
# ruby = [ "codegen-sdk-cst/ruby"]
27+
# rust = [ "codegen-sdk-cst/rust"]
28+
go = [ "codegen-sdk-cst/go"]
29+
# markdown = [ "codegen-sdk-cst/markdown"]
30+
yaml = [ "codegen-sdk-cst/yaml"]
31+
toml = [ "codegen-sdk-cst/toml"]
32+
ts_query = []
33+
default = ["json", "ts_query", "toml"]
1834
[dev-dependencies]
1935
test-log = { workspace = true }
2036
[workspace]
@@ -35,6 +51,12 @@ tree-sitter-typescript = "0.23.2"
3551
tree-sitter-javascript = "0.23.1"
3652
tree-sitter-json = "0.24.0"
3753
tree-sitter-java = "0.23.5"
54+
tree-sitter-ruby = "0.23.1"
55+
tree-sitter-rust = "0.23.2"
56+
tree-sitter-go = "0.23.4"
57+
tree-sitter-md = "0.3.2"
58+
tree-sitter-yaml = "0.7.0"
59+
tree-sitter-toml-ng = "0.7.0"
3860
bytes = "1.10.0"
3961
convert_case = "0.7.1"
4062
serde = { version = "1.0.217", features = ["derive"] }
@@ -45,7 +67,7 @@ test-log = "0.2.17"
4567
enum_delegate = "0.2.0"
4668
mockall = "0.13.1"
4769
codegen-sdk-common = { path = "codegen-sdk-common" }
48-
codegen-sdk-cst = { path = "codegen-sdk-cst", features = ["typescript"]}
70+
codegen-sdk-cst = { path = "codegen-sdk-cst"}
4971
codegen-sdk-ast = { path = "codegen-sdk-ast" }
5072

5173
[profile.dev.package]

codegen-sdk-ast/Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
codegen-sdk-cst = { workspace = true }
7+
codegen-sdk-cst = { workspace = true, features = ["json"]}
88
codegen-sdk-common = { workspace = true }
99

1010
[build-dependencies]
1111
codegen-sdk-common = { workspace = true }
1212
env_logger = { workspace = true }
1313
rayon = { workspace = true }
1414
codegen-sdk-ast-generator = { path = "../codegen-sdk-ast-generator"}
15+
[features]
16+
python = [ "codegen-sdk-cst/python"]
17+
typescript = [ "codegen-sdk-cst/typescript"]
18+
tsx = [ "codegen-sdk-cst/tsx"]
19+
jsx = [ "codegen-sdk-cst/jsx"]
20+
javascript = [ "codegen-sdk-cst/typescript"]
21+
json = [ "codegen-sdk-cst/json"]
22+
java = [ "codegen-sdk-cst/java"]
23+
rust = [ "codegen-sdk-cst/rust"]
24+
go = [ "codegen-sdk-cst/go"]
25+
ruby = [ "codegen-sdk-cst/ruby"]
26+
yaml = [ "codegen-sdk-cst/yaml"]
27+
toml = [ "codegen-sdk-cst/toml"]
28+
markdown = [ "codegen-sdk-cst/markdown"]
29+
ts_query = []
30+
default = ["json", "ts_query"]

codegen-sdk-ast/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ impl<T: File> Named for T {
1010
}
1111
}
1212
use std::path::PathBuf;
13-
include!(concat!(env!("OUT_DIR"), "/typescript.rs"));
13+
include!(concat!(env!("OUT_DIR"), "/json.rs"));

codegen-sdk-common/Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ tree-sitter-typescript = { workspace = true, optional = true }
1111
tree-sitter-javascript = { workspace = true, optional = true }
1212
tree-sitter-json = { workspace = true, optional = true }
1313
tree-sitter-java = { workspace = true, optional = true }
14+
tree-sitter-rust = { workspace = true, optional = true }
15+
tree-sitter-go = { workspace = true, optional = true }
16+
tree-sitter-ruby = { workspace = true, optional = true }
17+
tree-sitter-yaml = { workspace = true, optional = true }
18+
tree-sitter-toml-ng = { workspace = true, optional = true }
19+
tree-sitter-md = { workspace = true, optional = true }
1420
lazy_static = "1.5.0"
1521
thiserror = "2.0.11"
1622
serde = { workspace = true, features = ["derive"] }
@@ -35,6 +41,12 @@ python = ["dep:tree-sitter-python"]
3541
json = ["dep:tree-sitter-json"]
3642
java = ["dep:tree-sitter-java"]
3743
typescript = ["dep:tree-sitter-typescript", "dep:tree-sitter-javascript"]
44+
rust = ["dep:tree-sitter-rust"]
45+
go = ["dep:tree-sitter-go"]
46+
ruby = ["dep:tree-sitter-ruby"]
47+
yaml = ["dep:tree-sitter-yaml"]
48+
toml = ["dep:tree-sitter-toml-ng"]
49+
markdown = ["dep:tree-sitter-md"]
3850
ts_query = ["dep:tree-sitter-query"]
3951
default = ["all"]
40-
all = ["python", "typescript", "json", "java", "ts_query"]
52+
all = ["python", "typescript", "json", "java", "ts_query", "ruby", "rust", "go", "yaml", "toml"]

codegen-sdk-common/src/language.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Language {
5151
self.nodes()
5252
.iter()
5353
.find(|node| node.root)
54-
.unwrap()
54+
.unwrap_or_else(|| panic!("No root node found for language: {}", self.name))
5555
.type_name
5656
.to_case(Case::Pascal)
5757
}
@@ -71,6 +71,8 @@ impl Language {
7171
self.name
7272
}
7373
}
74+
#[cfg(feature = "go")]
75+
pub mod go;
7476
#[cfg(feature = "java")]
7577
pub mod java;
7678
#[cfg(feature = "typescript")]
@@ -79,14 +81,24 @@ pub mod javascript;
7981
pub mod json;
8082
#[cfg(feature = "typescript")]
8183
pub mod jsx;
84+
#[cfg(feature = "markdown")]
85+
pub mod markdown;
8286
#[cfg(feature = "python")]
8387
pub mod python;
88+
#[cfg(feature = "ruby")]
89+
pub mod ruby;
90+
#[cfg(feature = "rust")]
91+
pub mod rust;
92+
#[cfg(feature = "toml")]
93+
pub mod toml;
8494
#[cfg(feature = "ts_query")]
8595
pub mod ts_query;
8696
#[cfg(feature = "typescript")]
8797
pub mod tsx;
8898
#[cfg(feature = "typescript")]
8999
pub mod typescript;
100+
#[cfg(feature = "yaml")]
101+
pub mod yaml;
90102
lazy_static! {
91103
pub static ref LANGUAGES: Vec<&'static Language> = vec![
92104
#[cfg(feature = "python")]
@@ -99,6 +111,18 @@ lazy_static! {
99111
&jsx::JSX,
100112
#[cfg(feature = "typescript")]
101113
&javascript::Javascript,
114+
#[cfg(feature = "rust")]
115+
&rust::Rust,
116+
#[cfg(feature = "go")]
117+
&go::Go,
118+
#[cfg(feature = "ruby")]
119+
&ruby::Ruby,
120+
#[cfg(feature = "yaml")]
121+
&yaml::Yaml,
122+
#[cfg(feature = "toml")]
123+
&toml::TOML,
124+
#[cfg(feature = "markdown")]
125+
&markdown::Markdown,
102126
#[cfg(feature = "json")]
103127
&json::JSON,
104128
#[cfg(feature = "java")]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::Language;
2+
lazy_static! {
3+
pub static ref Markdown: Language = Language::new(
4+
"markdown",
5+
"Markdown",
6+
tree_sitter_md::NODE_TYPES_BLOCK,
7+
&["md"],
8+
tree_sitter_md::LANGUAGE.into(),
9+
"",
10+
)
11+
.unwrap();
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::Language;
2+
lazy_static! {
3+
pub static ref TOML: Language = Language::new(
4+
"toml",
5+
"TOML",
6+
tree_sitter_toml_ng::NODE_TYPES,
7+
&["toml"],
8+
tree_sitter_toml_ng::LANGUAGE.into(),
9+
"",
10+
)
11+
.unwrap();
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::Language;
2+
lazy_static! {
3+
pub static ref Yaml: Language = Language::new(
4+
"yaml",
5+
"Yaml",
6+
tree_sitter_yaml::NODE_TYPES,
7+
&["yaml", "yml"],
8+
tree_sitter_yaml::LANGUAGE.into(),
9+
"",
10+
)
11+
.unwrap();
12+
}

codegen-sdk-common/src/naming.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static MAPPINGS: phf::Map<char, &'static str> = phf_map! {
3636
'"' => "DoubleQuote",
3737
'|' => "Pipe",
3838
';' => "Semicolon",
39+
'\0' => "Null",
3940
};
4041
pub fn normalize_field_name(field_name: &str) -> String {
4142
if field_name == "type" {

0 commit comments

Comments
 (0)