Skip to main content

parse_multi

Function parse_multi 

Source
pub fn parse_multi(input: &str) -> Result<Vec<Song>, ParseError>
Expand description

Parses a multi-song ChordPro source string, splitting at {new_song} / {ns} boundaries and parsing each segment as an independent Song.

If the input contains no {new_song} directives, the result is a single-element vector containing the entire input parsed as one song.

§Errors

Returns a ParseError if any song segment contains structural problems. On error, parsing stops at the first problematic segment.

§Examples

use chordsketch_core::parser::parse_multi;

let input = "{title: Song One}\nLyrics one\n{new_song}\n{title: Song Two}\nLyrics two";
let songs = parse_multi(input).unwrap();
assert_eq!(songs.len(), 2);
assert_eq!(songs[0].metadata.title.as_deref(), Some("Song One"));
assert_eq!(songs[1].metadata.title.as_deref(), Some("Song Two"));