Skip to content

Commit

Permalink
chords grammar done
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Oct 3, 2024
1 parent c3be3bb commit 2652abd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class ChordConstants
(ChordType.Major, "major", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),

(ChordType.Minor, "m", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Minor, "mi", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Minor, "min", MatchCase.MatchUpperFirst, MatchAmbiguity.Safe),
(ChordType.Minor, "minor", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),

Expand All @@ -33,14 +34,16 @@ public static class ChordConstants
(ChordType.Dim7, "o", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordType.Sus2, "sus2", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordType.Sus2, "s2", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Sus2, "susp2", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordType.Sus4, "sus4", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordType.Sus4, "s4", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Sus4, "susp4", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Sus4, "sus", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordType.Sus4, "susp", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordType.Power, "5", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Power, "5", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordType.Power, "no3", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Power, "no3rd", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordType.Power, "omit3", MatchCase.ExactOnly, MatchAmbiguity.Safe),
Expand All @@ -49,15 +52,18 @@ public static class ChordConstants

public static readonly IReadOnlyList<(ChordTypeExtension extension, string representation, MatchCase matchCase, MatchAmbiguity matchAmbiguity)> ChordTypeExtensionRepresentations =
[
(ChordTypeExtension.X7, "7", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.X9, "9", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.X11, "11", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.X13, "13", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.X7, "add7", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeExtension.X7, "7", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeExtension.X9, "9", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeExtension.X11, "11", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeExtension.X13, "13", MatchCase.ExactOnly, MatchAmbiguity.Degree),

(ChordTypeExtension.XMaj7, "maj", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "maj7", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "maj", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "ma7", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "major7", MatchCase.MatchUpperFirst, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "M7", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "MA7", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeExtension.XMaj7, "M", MatchCase.ExactOnly, MatchAmbiguity.Dangerous),
(ChordTypeExtension.XMaj7, "7M", MatchCase.ExactOnly, MatchAmbiguity.Dangerous),

Expand All @@ -84,38 +90,54 @@ public static class ChordConstants

(ChordTypeAdditions.No11, "no11", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordTypeAdditions.Add2, "2", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add2, "add2", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add2, "2", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeAdditions.Add2, "add2", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Degree),

(ChordTypeAdditions.Add4, "4", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add4, "add4", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add4, "4", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeAdditions.Add4, "add4", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Degree),

(ChordTypeAdditions.Flat5, "addb5", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat6, "addb6", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat9, "addb9", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat11, "addb11", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat13, "addb13", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat5, "add-5", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat6, "add-6", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat9, "add-9", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat11, "add-11", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Flat13, "add-13", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordTypeAdditions.Sharp4, "add#4", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp5, "add#5", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp9, "add#9", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp11, "add#11", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp13, "add#13", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp4, "add+4", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp5, "add+5", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp9, "add+9", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp11, "add+11", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Sharp13, "add+13", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordTypeAdditions.Add6, "6", MatchCase.ExactOnly, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add6, "add6", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add6, "6", MatchCase.ExactOnly, MatchAmbiguity.Degree),
(ChordTypeAdditions.Add6, "add6", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Degree),

(ChordTypeAdditions.Add9, "add9", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add11, "add11", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add13, "add13", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Safe),
(ChordTypeAdditions.Add9, "add9", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Degree),
(ChordTypeAdditions.Add11, "add11", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Degree),
(ChordTypeAdditions.Add13, "add13", MatchCase.MatchUpperFirstOrAll, MatchAmbiguity.Degree),

(ChordTypeAdditions.HalfDiminished7, "ø", MatchCase.ExactOnly, MatchAmbiguity.Safe),

(ChordTypeAdditions.Sharp, "#", MatchCase.ExactOnly, MatchAmbiguity.DegreeAlteration),
(ChordTypeAdditions.Flat, "b", MatchCase.ExactOnly, MatchAmbiguity.DegreeAlteration),
(ChordTypeAdditions.Plus, "+", MatchCase.ExactOnly, MatchAmbiguity.DegreeAlteration),
(ChordTypeAdditions.Minus, "-", MatchCase.ExactOnly, MatchAmbiguity.DegreeAlteration),
];

public static readonly IReadOnlyList<(ChordTypeMeaninglessAddition meaninglessAddition, string representation)> ChordTypeMeaninglessAdditionRepresentations =
[
(ChordTypeMeaninglessAddition.Star, "*"),
(ChordTypeMeaninglessAddition.Question, "?"),
(ChordTypeMeaninglessAddition.Slash, "/"),
];

public static readonly IReadOnlyList<string> Romans =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public enum ChordTypeAdditions
Sharp13 = 1 << 19,

HalfDiminished7 = 1 << 20,

Plus = 1 << 21,
Minus = 1 << 22,
Sharp = 1 << 23,
Flat = 1 << 24,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public enum ChordTypeMeaninglessAddition
{
Star,
Question,
FragmentSeparator,
Slash,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public enum MatchAmbiguity
{
Safe,
Dangerous,
Degree,
DegreeAlteration,
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public static class ChordParser
var fragments = UnwrapParentheses(input, options);
List<(ChordType? type, ChordTypeExtension? extension, ChordTypeAdditions? addition, byte? fret, ChordTypeMeaninglessAddition? meaninglessAddition, bool fromParentheses, MatchAmbiguity matchAmbiguity)> result = new();

foreach (var (fragment, fromParentheses) in fragments)
foreach (var ((fragment, fromParentheses), i) in fragments.WithIndices())
{
if (i > 0)
{
result.Add((null, null, null, null, ChordTypeMeaninglessAddition.FragmentSeparator, true, MatchAmbiguity.Safe));
}

var currentFragment = fragment;

while (true)
Expand Down

0 comments on commit 2652abd

Please sign in to comment.