tiny.syn.fromPath
Defined in language.
A caller that opens a file picks the language from its path.
Source
Source: lib/syn/src/language.zig:173
zig
/// A caller that opens a file picks the language from its path. The call returns the language for a/// file path, or null when neither its extension nor its file name is known. The lookup tries the/// extension first, ignoring letter case, so `src/main.rs` gives Rust and `src/app.tsx` gives/// TypeScript. A file named `.chic` counts as Chiclet. Without a known extension the lookup tries/// the whole file name through `fromName`, so a file called `Makefile` gives Make. It then knows a/// few names with no extension: `Dockerfile` as shell, `GNUmakefile` and `BSDmakefile` as Make, and/// shell start-up files such as `.bashrc`, `.zshrc` and `.profile` as shell. The lookup reads only/// the path text and never opens the file.pub fn fromPath(path: []const u8) ?Language { const extension = std.fs.path.extension(path); const basename = std.fs.path.basename(path); if (extension.len > 1) { if (fromExtension(extension[1..])) |language| return language; } if (eq(basename, ".chic")) return .chiclet; if (fromName(basename)) |language| return language; if (eq(basename, "Dockerfile")) return .shell; if (eq(basename, "Makefile") or eq(basename, "GNUmakefile") or eq(basename, "BSDmakefile")) return .make; if (eq(basename, ".bashrc") or eq(basename, ".zshrc") or eq(basename, ".profile") or eq(basename, ".bash_profile") or eq(basename, ".zprofile")) return .shell; if (eq(basename, "flake.nix")) return .nix; return null;}Source: lib/syn/src/root.zig:57
zig
pub const fromPath = language.fromPath;Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |