abc-parser 0.4.0

An ABC music notation parser. Turns ABC text into Rust data structures and back.
Documentation

rust-abc-2

ABC Parser written in rust using PEG.

Usage

Add the package to your cargo dependencies.

[dependencies]
abc-parser = "0.4"

Then you can use the PEG generated rules through the abc module.

use abc_parser::abc;
use abc_parser::datatypes::*;

let parsed = abc::tune_book("X:1\nT:Example\nK:D\n").unwrap();
assert_eq!(
    parsed,
    TuneBook::new(
        vec![],
        None,
        vec![Tune::new(
            TuneHeader::new(vec![
                HeaderLine::Field(InfoField::new('X', "1".to_string()), None),
                HeaderLine::Field(InfoField::new('T', "Example".to_string()), None),
                HeaderLine::Field(InfoField::new('K', "D".to_string()), None)
            ]),
            None
        )]
    )
)

Feature List

These are roughly taken in order from the abc standard.

  • Comments
    • Comment lines with preceding whitespace
  • Info fields
    • Inline fields
    • Remarks
    • Macros
    • Redefining Symbols
    • Multiple Voices
    • Clefs and Transposition
  • Field continuation
  • Notes
    • Pitch
    • Accidentals
    • Lengths
    • Ties
    • Broken Rhythm
      • Splitting grace notes e.g. A{g}<A
  • Rests
  • Beams
  • Bars
  • First and second repeats
    • Shortened e.g. |1 and :|2
  • Variant Endings
  • Slurs
  • Grace Notes
  • Tuplets
  • Decorations
  • Symbol Lines
  • Chords and Unisons
  • Annotations
    • Chord Symbols
  • Lyrics
  • Multiple Voices
    • Voice grouping shorthand syntax
  • Text Strings
  • Reserved characters
  • Stylesheet Directives
  • Dialects
  • Spacers

History

The first version was an attempt to write the parser by hand, but using PEG is much more maintainable. The older repo is here: https://gitlab.com/Askaholic/rust-abc