ChordPro
actor ChordPro
The ChordPro
file parser
-
Parse a ChordPro file
Declaration
Swift
static func parse(id: UUID, text: String, transpose: Int, instrument: Instrument, fileURL: URL?) -> Song
Parameters
text
The text of the file
transpose
The optional transpose of the song
id
The ID of the song
instrument
The instrument of the song
fileURL
The optional file url of the song
Return Value
A
Song
item
-
Process a directive
Declaration
Parameters
text
The text to process
song
The
Song
currentSection
The current
section
of thesong
-
Process a section
Declaration
Swift
private static func processSection(label: String, type: Environment, song: inout Song, currentSection: inout Song.Section)
Parameters
label
The label of the
section
type
The type of
section
song
The
song
currentSection
The current
section
of thesong
-
Process a chord definition
Declaration
Swift
private static func processDefine(text: String, song: inout Song)
Parameters
text
The chord definition
song
The
song
-
Process a tab environment
Declaration
Parameters
text
The text to process
song
The
Song
currentSection
The current
section
of thesong
-
Process a grid environment
Declaration
Parameters
text
The text to process
song
The
Song
currentSection
The current
section
of thesong
-
Process a strum environment
Declaration
Parameters
text
The text to process
song
The
Song
currentSection
The current
section
of thesong
-
Process a line
Declaration
Parameters
text
The text to process
song
The
Song
currentSection
The current
section
of thesong
-
Process a chord
Declaration
Swift
private static func processChord(chord: String, song: inout Song) -> ChordDefinition
Parameters
chord
The
chord
as Stringsong
The
Song
Return Value
The processed
chord
as String
-
The directives Chord Provider supports
See moreDeclaration
Swift
enum Directive: String, CaseIterable
-
The environment of a section of the song
See moreDeclaration
Swift
enum Environment: String
-
All the directives we know about
Declaration
Swift
static let directives = ChordPro.Directive.allCases.map(\.rawValue)
-
The regex for a
directive
with an optionallabel
/// ## Examples {title: The title of the song} {chorus} {start_of_verse} {start_of_verse: Last Verse}
Note
This needs an extension forChoiceOf
Declaration
Swift
static let directiveRegex = Regex { "{" Capture { ChoiceOf(directives) } transform: { Directive(rawValue: $0.lowercased()) ?? .none } Optionally { ":" TryCapture { OneOrMore { CharacterClass( .anyOf("}").inverted ) } } transform: { $0.trimmingCharacters(in: .whitespacesAndNewlines) } } "}" Optionally { CharacterClass( .anyOf("{").inverted ) } }
-
The regex for a normal line with optional
chords
and/orlyrics
/// ## Example [A]I sing you a [G]song!!
Declaration
Swift
static let lineRegex = Regex { /// The chord Optionally { chordRegex } /// The lyric Optionally { Capture { OneOrMore { CharacterClass( .anyOf("[]").inverted ) } } } }
-
Regex for brackets for chords and directives
Declaration
Swift
static let bracketRegex = Regex { Capture { OneOrMore { CharacterClass( .anyOf("[]{}") ) } } }
-
Regex for a chord
Declaration
Swift
static let chordRegex = Regex { Regex { "[" Capture { OneOrMore { CharacterClass( .anyOf("[] ").inverted ) } } "]" } }