言語ごとの Cargo フィーチャ
Every tree-sitter grammar this library bundles is gated behind its own Cargo feature. The default feature set is all-languages, so the default
[dependencies]
big-code-analysis = "2.4.0"
pulls every grammar in, matching the library’s historical behaviour and what the bca / bca-web binaries ship with. The cost is concrete: every grammar crate compiles when the library compiles, and every grammar’s parsing tables stay live in the final binary.
Library consumers that need only a subset of languages can opt out of the defaults and re-enable just the grammars they use.
具体例
Rust と TypeScript だけを解析する下流のサービスの例です。
[dependencies]
big-code-analysis = { version = "2.4.0", default-features = false, features = ["rust", "typescript"] }
この場合でもライブラリはコンパイルでき、LANG enum には引き続きすべてのバリアントがあり、analyze / Ast をはじめとするディスパッチ面は、有効化された言語に対してそのまま機能します。
サポートされるフィーチャ
利用できる言語別フィーチャは次のとおりです。各フィーチャは、対応する文法クレート(および言語別パイプラインが依存するヘルパー文法)を取り込みます。
| フィーチャ | 取り込まれる文法クレート |
|---|---|
bash | tree-sitter-bash |
c | tree-sitter-c(+ c-family-helpers)。.c を担当する専用の C バリアント(#721 で追加) |
c-family-helpers | bca-tree-sitter-ccomment, bca-tree-sitter-preproc; internal, enabled automatically by c / cpp / mozcpp; gates the Ccomment / Preproc helper variants. Not meant to be selected directly |
cpp | tree-sitter-cpp(+ c-family-helpers)。Cpp バリアント(#720 以降はアップストリーム文法)。Ccomment / Preproc ヘルパーバリアントも有効化します |
csharp | tree-sitter-c-sharp |
elixir | tree-sitter-elixir |
go | tree-sitter-go |
groovy | dekobon-tree-sitter-groovy |
irules | tree-sitter-irules(F5 iRules、Tcl 方言) |
java | tree-sitter-java |
javascript | tree-sitter-javascript |
kotlin | tree-sitter-kotlin-ng |
lua | tree-sitter-lua |
mozcpp | bca-tree-sitter-mozcpp (+ c-family-helpers); opt-in Mozilla/Gecko C++ dialect, Mozcpp variant; owns no extensions, selected by name |
mozjs | bca-tree-sitter-mozjs |
objc | tree-sitter-objc。Objc バリアント(Objective-C)です。.m を担当し、.mm(Objective-C++)は Cpp のままです |
perl | tree-sitter-perl |
php | tree-sitter-php |
python | tree-sitter-python |
ruby | tree-sitter-ruby |
rust | tree-sitter-rust |
tcl | bca-tree-sitter-tcl |
typescript | tree-sitter-typescript(Typescript と Tsx の両バリアントで使用) |
Since #1376 the grammar crates are dependencies of big-code-analysis-ast, the parse and classification layer this crate is built on, so every feature above forwards to the same-named feature there and the grammars appear one level down in cargo tree. Nothing changes for a consumer: the feature names, the LANG enum and the whole analysis surface are unaffected, and enabling rust still links exactly one grammar.
包括フィーチャ all-languages は、この表のすべてのエントリを有効にします。bca-tree-sitter-* クレートは、アップストリームの Mozilla / コミュニティ文法のツリー内フォークですが、Rust のインポートパスはいずれも tree_sitter_<lang> のままです。リネームの理由と、利用側の呼び出し箇所を変更せずに済ませるワークスペースの package = ... エイリアスの仕組みについては、RELEASING.md を参照してください。
フィーチャが無効なときに起こること
The LANG enum keeps every variant defined regardless of the active feature set. Disabling a feature does not change the enum surface or any of the file-extension and Emacs mode declaration detection helpers. Selecting a LANG whose feature is off only affects the dispatch path.
Result を返すすべてのディスパッチエントリポイントは、無効状態を Err(MetricsError::LanguageDisabled(LANG)) として表面化させます。
analyzeAst::parse/Ast::from_tree_sitter(および返されたAstのmetrics/opsメソッド)LANG::tree_sitter_language, which returnsResult<tree_sitter::Language, MetricsError>rather than the bareLanguagethe upstream project returned
呼び出し側は、ディスパッチャを経由せずに、コンパイル時に組み込まれた言語の集合を照会できます。
#![allow(unused)]
fn main() {
use big_code_analysis::LANG;
for lang in LANG::into_enum_iter() {
if lang.is_enabled() {
println!("{:?} is compiled in", lang);
}
}
}
This pairs well with the get_language_for_file / guess_language helpers, which still hand back any LANG variant for a recognised extension. Callers walking a directory may want to skip files whose language is not enabled in the current build.
安定性
言語ごとのフィーチャ自体も契約の一部です。新しい言語フィーチャの追加はマイナーバンプでの追加的変更ですが、削除はメジャーバンプ(3.0)の破壊的変更です。デフォルトの all-languages は 2.x の間は恒久的であり、デフォルトビルドがカバーするバリアントが 3.0 より前に減ることはありません。この種の変更は、チェンジログで (breaking) として明示されます。