blob: bd180a96a2586c96aae3a53bbc027fb8473b82a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// © Copyright 2022, Scott Gasch
//
// antlr4 -Dlanguage=Python3 ./chords.g4
//
// Hi, self. In ANTLR grammars, there are two separate types of symbols: those
// for the lexer and those for the parser. The former begin with a CAPITAL
// whereas the latter begin with lowercase. The order of the lexer symbols
// is the order that the lexer will recognize them in. There's a good tutorial
// on this shit at:
//
// https://tomassetti.me/antlr-mega-tutorial/
//
// There are also a zillion premade grammars at:
//
// https://github.com/antlr/grammars-v4
grammar chords;
parse
: rootNote majMinSusPowerExpr* addNotesExpr* extensionExpr* overBassNoteExpr*
;
rootNote
: NOTE
;
overBassNoteExpr
: SLASH NOTE
;
majMinSusPowerExpr
: majExpr
| minExpr
| susExpr
| diminishedExpr
| augmentedExpr
| powerChordExpr
;
majExpr: MAJOR;
minExpr: MINOR;
susExpr: SUS ('2'|'4');
diminishedExpr: DIMINISHED;
augmentedExpr: AUGMENTED;
powerChordExpr: '5';
addNotesExpr
: SIX
| SEVEN
| MAJ_SEVEN
| ADD_NINE
;
extensionExpr
: INTERVAL
;
SPACE: [ \t\r\n] -> skip;
NOTE: (AS|BS|CS|DS|ES|FS|GS) ;
AS
: ('A'|'a')
| ('Ab'|'ab')
| ('A#'|'a#')
;
BS
: ('B'|'b')
| ('Bb'|'bb')
;
CS
: ('C'|'c')
| ('C#'|'c#')
;
DS
: ('D'|'d')
| ('Db'|'db')
| ('D#'|'d#')
;
ES
: ('E'|'e')
| ('Eb'|'eb')
;
FS
: ('F'|'f')
| ('F#'|'f#')
;
GS
: ('G'|'g')
| ('Gb'|'gb')
| ('G#'|'g#')
;
MAJOR: ('M'|'Maj'|'maj'|'Major'|'major');
MINOR: ('m'|'min'|'minor');
SUS: ('sus'|'suspended');
DIMINISHED: ('dim'|'diminished');
AUGMENTED: ('aug'|'augmented');
SLASH: ('/'|'\\');
SIX: '6';
SEVEN: '7';
MAJ_SEVEN: MAJOR '7';
ADD_NINE: ('add'|'Add')* '9';
INTERVAL: (MAJOR|MINOR)* ('b'|'#')* DIGITS ;
DIGITS: [1-9]+ ;
|