-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathterminals.py
187 lines (133 loc) · 4.33 KB
/
terminals.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
src = """
#
# Skoar Tokes
#
# format (at very start of line): TokeName: regex
#
# If token carries information: TokeName*: regex
# - be sure an inspector for TokeName exists
#
<e>: unused
EOF: unused
Whitespace: [ \\t]*
Newline: [\\n\\r][\\n\\r \\t]*
True: yes|true
False: no|false
Cat: =\\^\\.\\^=
Voice*: \\.(([a-zA-Z_][a-zA-Z0-9_]*)?|\\.+)
Comment: <[?](.|[\\n\\r])*?[?]>
# careful not to match ottavas ending in (ma,mb,va,vb), or steal from floats
Int*: (-)?(0|[1-9][0-9]*)(?![0-9]*Hz|[mv][ab]|\\.[0-9]|/)
Float*: (-)?(0|[1-9][0-9]*)\\.[0-9]+(?!Hz)
Freq*: (0|[1-9][0-9]*)(\\.[0-9]+)?Hz
Meter*: [1-9][0-9]*/[1-9][0-9]*
ArgSpec: <[a-zA-Z]+(,[a-zA-Z]+)*>
ListS: <(?![=?])|<(?=[=]\\^\\.)
ListE: >(?![=])
ListSep: ,
# one ^ but don't eat ^^( which is cthulhu's left wing
Carrot*: \\^(?!\\^[(])
LWing: \\^\\^[(]
RWing: [)]\\^\\^
Tuplet*: /\\d+(:\\d+)?|(du|tri|quadru)plets?|(quin|sex|sep|oc)tuplets?
Crotchets*: [}]+\\.?
Quavers*: o+/\\.?
Quarters*: \\.?[)]+(?:__?)?\\.?
Eighths*: \\.?\\]+(?:__?)?\\.?
Caesura: //
Slash: /(?![/0-9])
HashLevel: \\[#*[ ]*\\]
# we can't allow f for forte as f is a noat, so we allow
#
# forte fforte ffforte ff fff, but not f
#
# for consisentecy, piano, ppiano, pppiano work too.
#
# default velocity:
# ppp (16), pp (32), p (48), mp (64), mf (80), f (96), ff (112), fff (127)
DynPiano*: (m(ezzo)?p|p+)(iano)?
DynForte*: m(ezzo)?f(orte)?|f+orte|ff+
DynSFZ: sfz
DynFP: fp
AssOp: =>|[+]>|->|[*]>
MsgOp: \\.(?![)\\]])
MathOp: [+*\\-](?!>)
NamedNoat*: (?:_?)(?:[a-g](?![ac-zA-Z_]))(#|b)?
Choard*: ~*[ABCDEFG](?![.ce-ln-rt-zA-LN-Z]|a[l ])(#|b)?([Mm0-9]|sus|dim|aug|dom)*(/[A-G][#b]?)?~*
BooleanOp*: ==|!=|<=|>=|and|or|xor
CondS: [{][?][\\n]*
CondIf: [?][?](?![}])
CondE: [?][}]
Semicolon: ;
CutsS: [{]=[\\n]*
CutsE: =[}]
LoopS: [{]:[\\n]*
LoopE: :[}]
LoopSep: ::[\\n]*(?![|])
Fairy: [$]
# we do this, because skoaroids can follow skoaroids.
MsgName*: [a-zA-Z_][a-zA-Z0-9_]*(?!<)
MsgNameWithArgs*: [a-zA-Z_][a-zA-Z0-9_]*<
Symbol*: [\\\\@][a-zA-Z0-9_][a-zA-Z0-9_]*
SymbolName*: [a-zA-Z0-9_][a-zA-Z0-9_]*
SymbolColon*: [a-zA-Z0-9_][a-zA-Z0-9_]*[ \\t]*:(?![:|}])
SkoarpionStart: [{]!
SkoarpionEnd: ![}]
SkoarpionSep: !!
Deref: !(?![!}]|=)
Nosey: ,
DaCapo: D\\.C\\.|Da Capo
DalSegno: D\\.S\\.|Dal Segno
Fine: fine
Segno*: ,[Ss](?:egno)?`(?:[a-zA-Z_][a-zA-Z0-9_]*`)*
Coda: \\([+]\\)(?:`(?:[a-zA-Z_][a-zA-Z0-9_]*`)*)?
Rep*: %+
AlCoda: al(la)? coda
AlSegno: al segno
AlFine: al fine
UGen: u[A-Z][A-Za-z0-9_]*
OctaveShift*: ~+o|o~+
OttavaA: 8va|ottava (alta|sopra)|all' ottava
OttavaB: 8vb|ottava (bassa|sotto)
QuindicesimaA: 15ma|alla quindicesima
QuindicesimaB: 15mb
Portamento: port\\.?
Loco: loco
Volta*: \\[\\d+\\.\\]
# TODO: deal with \"
String*: \'[^']*\'
Bars*: :?\\|+:?
Times: [Tt]imes
"""
#
#
#
list_of_names = None
inspectables = None
tokens = None
Empty = None
EOF = None
Whitespace = None
odd_balls = None
def init():
from Skoarcery.langoids import Terminal
global src, list_of_names, tokens, EOF, Empty, Whitespace, odd_balls, inspectables
list_of_names = []
inspectables = []
tokens = dict()
for token_line in src.split("\n"):
token_line = token_line.strip()
if len(token_line) > 0 and not token_line.startswith("#"):
(token, v, regex) = token_line.partition(":")
token = token.strip()
regex = regex.strip()
if token.endswith("*"):
token = token.rstrip("*")
inspectables.append(token)
list_of_names.append(token)
tokens[token] = Terminal(token, regex)
#print("# tokens initialized.")
Empty = Terminal("<e>", None)
EOF = Terminal("EOF", None)
Whitespace = tokens["Whitespace"]
odd_balls = {Empty, EOF, Whitespace}