Skip to main content

chordsketch_chordpro/
lib.rs

1//! ChordPro parser, AST definitions, and transforms.
2
3pub mod abc_importer;
4pub mod ast;
5pub mod chord;
6pub mod chord_diagram;
7pub mod config;
8pub mod escape;
9#[cfg(not(target_arch = "wasm32"))]
10pub mod external_tool;
11pub mod formatter;
12pub mod grid;
13pub mod heuristic;
14pub mod image_path;
15pub mod inline_markup;
16pub mod json;
17pub mod lexer;
18pub mod notation;
19pub mod parser;
20pub mod render_result;
21pub mod rrjson;
22pub mod selector;
23pub mod token;
24pub mod transpose;
25pub mod typography;
26pub mod voicings;
27
28// Re-export key types for convenience.
29pub use abc_importer::convert_abc;
30pub use chord::{Accidental, ChordDetail, ChordQuality, Note, parse_chord};
31pub use chord_diagram::{canonical_chord_name, resolve_diagrams_instrument};
32// Aliased as `format_chordpro` to avoid ambiguity with the `format!` macro at
33// call sites that use glob imports.
34pub use formatter::{FormatOptions, format as format_chordpro};
35pub use heuristic::{
36    InputFormat, PlainTextImporter, convert_plain_text, detect_format, song_to_chordpro,
37};
38pub use lexer::Lexer;
39pub use parser::{
40    MultiParseResult, ParseError, ParseOptions, ParseResult, Parser, parse, parse_image_attributes,
41    parse_lenient, parse_lenient_with_options, parse_multi, parse_multi_lenient,
42    parse_multi_lenient_with_options, parse_multi_with_options, parse_with_options,
43};
44pub use render_result::RenderResult;
45pub use token::{Position, Span, Token, TokenKind};
46pub use voicings::{
47    guitar_voicing, keyboard_voicing, lookup_diagram, lookup_keyboard_voicing, ukulele_voicing,
48};
49
50/// Returns the library version.
51#[must_use]
52pub fn version() -> &'static str {
53    env!("CARGO_PKG_VERSION")
54}
55
56/// Capitalize the first character of a string.
57///
58/// Returns a new string with the first character uppercased and the
59/// rest unchanged. Returns an empty string for empty input.
60#[must_use]
61pub fn capitalize(s: &str) -> String {
62    let mut chars = s.chars();
63    match chars.next() {
64        None => String::new(),
65        Some(c) => c.to_uppercase().to_string() + chars.as_str(),
66    }
67}
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn test_version() {
75        assert_eq!(version(), env!("CARGO_PKG_VERSION"));
76    }
77}