mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-22 07:39:41 +00:00
docs: add and clean up AI-generated rustdoc comments (grok-4.5)
This commit is contained in:
@@ -15,21 +15,29 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/// Core module for language support in the DCR build system.
|
||||
/// Defines the Language trait and helper functions to register and lookup languages.
|
||||
pub mod asm;
|
||||
pub mod c;
|
||||
pub mod cxx;
|
||||
pub mod llvm_ir;
|
||||
|
||||
/// Trait representing a supported programming language.
|
||||
/// Each implementation must specify its unique identifier, list of supported file extensions,
|
||||
/// and a method to determine if a given token matches the language.
|
||||
pub trait Language {
|
||||
fn id(&self) -> &'static str;
|
||||
fn extensions(&self) -> &'static [&'static str];
|
||||
fn matches_token(&self, token: &str) -> bool;
|
||||
}
|
||||
|
||||
/// Returns a fixed-size array containing static references to all supported language types.
|
||||
pub fn languages() -> [&'static dyn Language; 4] {
|
||||
[&c::C, &cxx::Cxx, &asm::Asm, &llvm_ir::LlvmIr]
|
||||
}
|
||||
|
||||
/// Looks up the language implementation that matches the given token by checking each language's
|
||||
/// matches_token method. Returns the first match or None if no language matches.
|
||||
pub fn language_for_token(token: &str) -> Option<&'static dyn Language> {
|
||||
languages().into_iter().find(|l| l.matches_token(token))
|
||||
}
|
||||
@@ -38,6 +46,7 @@ pub fn language_for_token(token: &str) -> Option<&'static dyn Language> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Ensures that input tokens are resolved to the correct language IDs.
|
||||
#[test]
|
||||
fn tokens_resolve_to_languages() {
|
||||
assert_eq!(language_for_token("c").unwrap().id(), "c");
|
||||
@@ -48,6 +57,7 @@ mod tests {
|
||||
assert!(language_for_token("rust").is_none());
|
||||
}
|
||||
|
||||
/// Ensures that each language reports the expected set of file extensions.
|
||||
#[test]
|
||||
fn languages_expose_expected_extensions() {
|
||||
assert_eq!(c::C.extensions(), &["c"]);
|
||||
|
||||
Reference in New Issue
Block a user