Skip to content

Commit 3fde4e3

Browse files
alehander92pxor
andcommitted
feat: try to add initial flow support for python: grammar, node names, setup
TODO: match logic(overally?); for/else; while/else; some match-es marked immediately in the whole file Co-authored-by: pxor <[email protected]>
1 parent b88e851 commit 3fde4e3

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/db-backend/Cargo.lock

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

src/db-backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ regex = "1"
2121
tree-sitter = "*"
2222
tree-sitter-rust = "0.24"
2323
tree-sitter-ruby = "0.23.1"
24+
tree-sitter-python = "0.25.0"
2425
tree-sitter-traversal2 = "0.2.0"
2526
indexmap = "1.9.3"
2627
once_cell = "1.10.0"

src/db-backend/src/expr_loader.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ static NODE_NAMES: Lazy<HashMap<Lang, NodeNames>> = Lazy::new(|| {
7070
comments: vec!["".to_string()],
7171
},
7272
);
73+
74+
m.insert(
75+
Lang::PythonDb,
76+
NodeNames {
77+
if_conditions: vec!["if_statement".to_string(), "match_statement".to_string(),],
78+
else_conditions: vec!["else_clause".to_string()], // TODO: "case_clause".to_string(),?
79+
loops: vec!["for_statement".to_string(), "while_statement".to_string()],
80+
branches_body: vec!["block".to_string()],
81+
branches: vec!["block".to_string()],
82+
functions: vec!["function_definition".to_string()],
83+
values: vec!["identifier".to_string()],
84+
comments: vec!["comment".to_string()],
85+
}
86+
);
87+
7388
m
7489
});
7590

@@ -146,6 +161,8 @@ impl ExprLoader {
146161
Lang::Small
147162
} else if extension == "rs" {
148163
Lang::RustWasm // TODO RustWasm?
164+
} else if extension == "py" {
165+
Lang::PythonDb
149166
} else {
150167
Lang::Unknown
151168
}
@@ -163,6 +180,8 @@ impl ExprLoader {
163180
parser.set_language(&tree_sitter_rust::LANGUAGE.into())?;
164181
} else if lang == Lang::Ruby {
165182
parser.set_language(&tree_sitter_ruby::LANGUAGE.into())?;
183+
} else if lang == Lang::PythonDb {
184+
parser.set_language(&tree_sitter_python::LANGUAGE.into())?;
166185
} else {
167186
// else if lang == Lang::Small {
168187
// parser.set_language(&tree_sitter_elisp::LANGUAGE.into())?;

src/db-backend/src/lang.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ pub enum Lang {
3333
RustWasm,
3434
CppWasm,
3535
Small,
36+
PythonDb,
3637
Unknown,
3738
}

0 commit comments

Comments
 (0)