Skip to content

Commit ce33cbb

Browse files
committed
refactor(parser): change parser constructor to be const functions
1 parent 7e4da7b commit ce33cbb

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

bin/ast-doc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ description = "CLI for generating optimized llms.txt documentation from codebase
1212
readme = "README.md"
1313

1414
[features]
15-
default = ["all-languages"]
1615
all-languages = ["ast-doc-core/all-languages"]
16+
default = ["all-languages"]
1717
hotpath = ["ast-doc-core/hotpath", "dep:hotpath"]
1818

1919
[dependencies]

crates/ast-doc-core/src/parser/lang/c_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub struct CParser;
2222
impl CParser {
2323
/// Create a new C parser.
2424
#[must_use]
25-
pub fn new() -> Self {
25+
pub const fn new() -> Self {
2626
Self
2727
}
2828

2929
/// Parse source with tree-sitter, returning the tree.
30-
fn parse_tree(&self, source: &str) -> Result<Tree, AstDocError> {
30+
fn parse_tree(source: &str) -> Result<Tree, AstDocError> {
3131
let mut parser = Parser::new();
3232
let language = tree_sitter_c::LANGUAGE;
3333
parser.set_language(&language.into()).map_err(|e| AstDocError::Parse {
@@ -43,7 +43,7 @@ impl CParser {
4343

4444
impl LanguageParser for CParser {
4545
fn parse(&self, source: &str, path: &Path) -> Result<ParsedFile, AstDocError> {
46-
let tree = self.parse_tree(source)?;
46+
let tree = Self::parse_tree(source)?;
4747
let root_node = tree.root_node();
4848

4949
// C has no standard test markers

crates/ast-doc-core/src/parser/lang/go_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub struct GoParser;
2222
impl GoParser {
2323
/// Create a new Go parser.
2424
#[must_use]
25-
pub fn new() -> Self {
25+
pub const fn new() -> Self {
2626
Self
2727
}
2828

2929
/// Parse source with tree-sitter, returning the tree.
30-
fn parse_tree(&self, source: &str) -> Result<Tree, AstDocError> {
30+
fn parse_tree(source: &str) -> Result<Tree, AstDocError> {
3131
let mut parser = Parser::new();
3232
let language = tree_sitter_go::LANGUAGE;
3333
parser.set_language(&language.into()).map_err(|e| AstDocError::Parse {
@@ -43,7 +43,7 @@ impl GoParser {
4343

4444
impl LanguageParser for GoParser {
4545
fn parse(&self, source: &str, path: &Path) -> Result<ParsedFile, AstDocError> {
46-
let tree = self.parse_tree(source)?;
46+
let tree = Self::parse_tree(source)?;
4747
let root_node = tree.root_node();
4848

4949
let is_test_file = path.to_string_lossy().ends_with("_test.go");

crates/ast-doc-core/src/parser/lang/python_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub struct PythonParser;
2222
impl PythonParser {
2323
/// Create a new Python parser.
2424
#[must_use]
25-
pub fn new() -> Self {
25+
pub const fn new() -> Self {
2626
Self
2727
}
2828

2929
/// Parse source with tree-sitter, returning the tree.
30-
fn parse_tree(&self, source: &str) -> Result<Tree, AstDocError> {
30+
fn parse_tree(source: &str) -> Result<Tree, AstDocError> {
3131
let mut parser = Parser::new();
3232
let language = tree_sitter_python::LANGUAGE;
3333
parser.set_language(&language.into()).map_err(|e| AstDocError::Parse {
@@ -43,7 +43,7 @@ impl PythonParser {
4343

4444
impl LanguageParser for PythonParser {
4545
fn parse(&self, source: &str, path: &Path) -> Result<ParsedFile, AstDocError> {
46-
let tree = self.parse_tree(source)?;
46+
let tree = Self::parse_tree(source)?;
4747
let root_node = tree.root_node();
4848

4949
let test_ranges = collect_test_ranges(&root_node, source);

crates/ast-doc-core/src/parser/lang/typescript_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub struct TypeScriptParser;
2222
impl TypeScriptParser {
2323
/// Create a new TypeScript parser.
2424
#[must_use]
25-
pub fn new() -> Self {
25+
pub const fn new() -> Self {
2626
Self
2727
}
2828

2929
/// Parse source with tree-sitter, returning the tree.
30-
fn parse_tree(&self, source: &str) -> Result<Tree, AstDocError> {
30+
fn parse_tree(source: &str) -> Result<Tree, AstDocError> {
3131
let mut parser = Parser::new();
3232
let language = tree_sitter_typescript::LANGUAGE_TYPESCRIPT;
3333
parser.set_language(&language.into()).map_err(|e| AstDocError::Parse {
@@ -43,7 +43,7 @@ impl TypeScriptParser {
4343

4444
impl LanguageParser for TypeScriptParser {
4545
fn parse(&self, source: &str, path: &Path) -> Result<ParsedFile, AstDocError> {
46-
let tree = self.parse_tree(source)?;
46+
let tree = Self::parse_tree(source)?;
4747
let root_node = tree.root_node();
4848

4949
let test_ranges = collect_test_ranges(&root_node, source);

crates/ast-doc-core/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn parse_file(file: &DiscoveredFile, lang: &Language) -> Result<ParsedFile,
167167
Language::Generic(name) => {
168168
lang::generic_parser::GenericParser::new(name).parse(&file.content, &file.path)
169169
}
170-
#[allow(unreachable_patterns)]
170+
#[expect(unreachable_patterns)]
171171
_ => Err(AstDocError::UnsupportedLanguage { language: lang.to_string() }),
172172
}
173173
}

0 commit comments

Comments
 (0)