Include MY_PATCH_LEVEL in config.make's
[lilypond/patrick.git] / buildscripts / lilypond-words.py
blob9059b1d749b24a2649f5e8b2bda77c061f40ca3c
1 #!@PYTHON@
3 # Created 01 September 2003 by Heikki Junes.
4 # Generates lilypond-words.el for (X)Emacs and lilypond-words[.vim] for Vim.
6 import string
7 import re
8 import sys
10 kw = []
11 rw = []
12 notes = []
14 # keywords not otherwise found
15 for line in ['include','maininput','version']:
16 kw = kw + [line]
18 # the main keywords
19 F = open('lily/lily-lexer.cc', 'r')
20 for line in F.readlines():
21 m = re.search(r"(\s*{\")(.*)(\",\s*.*},\s*\n)",line)
22 if m:
23 kw = kw + [m.group(2)]
24 F.close()
26 # keywords in markup
27 F = open('scm/markup.scm', 'r')
28 for line in F.readlines():
29 m = re.search(r"^(\s*\(cons\s*)([a-z-]*)(-markup)",line)
30 if m:
31 kw = kw + [m.group(2)]
32 F.close()
34 # identifiers and keywords
35 for name in [
36 'ly/chord-modifiers-init.ly',
37 'ly/dynamic-scripts-init.ly',
38 'ly/engraver-init.ly',
39 'ly/grace-init.ly',
40 'ly/gregorian-init.ly',
41 'ly/music-functions-init.ly',
42 'ly/performer-init.ly',
43 'ly/property-init.ly',
44 'ly/scale-definitions-init.ly',
45 'ly/script-init.ly',
46 'ly/spanners-init.ly',
48 F = open(name, 'r')
49 for line in F.readlines():
50 m = re.search(r"^([a-zA-Z]+)(\s*=)",line)
51 if m:
52 kw = kw + [m.group(1)]
53 F.close()
55 # more identifiers
56 for name in [
57 'ly/declarations-init.ly',
58 'ly/declarations-init.ly',
59 'ly/params-init.ly',
61 F = open(name, 'r')
62 for line in F.readlines():
63 m = re.search(r"^(\s*)([a-zA-Z]+)(\s*=)",line)
64 if m:
65 kw = kw + [m.group(2)]
66 F.close()
68 # note names
69 for name in [
70 'ly/catalan.ly',
71 'ly/deutsch.ly',
72 'ly/drumpitch-init.ly',
73 'ly/english.ly',
74 'ly/espanol.ly',
75 'ly/italiano.ly',
76 'ly/nederlands.ly',
77 'ly/norsk.ly',
78 'ly/portugues.ly',
79 'ly/suomi.ly',
80 'ly/svenska.ly',
81 'ly/vlaams.ly',
83 F = open(name, 'r')
84 for line in F.readlines():
85 m = re.search(r"^(\s*\()([a-z]+)([^l]+ly:make-pitch)",line)
86 if m:
87 notes = notes + ['' + m.group(2)]
88 F.close()
92 # reserved words
93 for name in [
94 'ly/engraver-init.ly',
95 'ly/performer-init.ly',
97 F = open(name, 'r')
98 for line in F.readlines():
99 for pattern in [
100 r"^(\s*.consists\s+\")([a-zA-Z_]+)(\")",
101 r"([\\]name\s+[\"]?)([a-zA-Z_]+)([\"]?)",
102 r"(\s+)([a-zA-Z_]+)(\s*[\\]((set)|(override)))",
104 m = re.search(pattern,line)
105 if m:
106 rw = rw + ['' + m.group(2)]
107 F.close()
109 # the output file
110 outdir = '.';
111 suffix = ['skip','skip','skip'];
112 outs = ['','',''];
113 for s in sys.argv[1:]:
114 if s == '--words':
115 suffix[0] = '';
116 if s == '--el':
117 suffix[1] = '.el';
118 if s == '--vim':
119 suffix[2] = '.vim';
120 m = re.search(r"(--dir=)(\S*)",s)
121 if m:
122 outdir = m.group(2)
124 if '' in suffix:
125 outs[0] = open(outdir+'/lilypond-words'+suffix[0], 'w')
126 if '.el' in suffix:
127 outs[1] = open(outdir+'/lilypond-words'+suffix[1], 'w')
128 if '.vim' in suffix:
129 outs[2] = open(outdir+'/lilypond-words'+suffix[2], 'w')
131 # alphabetically ordered words
132 kw.sort()
133 kw.reverse()
134 prevline = ''
135 if '.vim' in suffix:
136 outs[2].write('syn match lilyKeyword \"[-_^]\\?\\\\\\(');
137 for line in kw:
138 if line != prevline:
139 if '' in suffix:
140 outs[0].write('\\\\' + line + '\n')
141 if '.el' in suffix:
142 outs[1].write('\\\\' + line + '\n')
143 if '.vim' in suffix:
144 outs[2].write(line + '\\|')
145 prevline = line
146 if '.vim' in suffix:
147 outs[2].write('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
149 rw.sort()
150 rw.reverse()
151 prevline = ''
152 if '.vim' in suffix:
153 outs[2].write('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(')
154 for line in rw:
155 if line != prevline:
156 if '' in suffix:
157 outs[0].write(line + '\n')
158 if '.el' in suffix:
159 outs[1].write(line + '\n')
160 if '.vim' in suffix:
161 outs[2].write(line + '\\|')
162 prevline = line
163 if '.vim' in suffix:
164 outs[2].write('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
166 notes.sort()
167 notes.reverse()
168 prevline = ''
169 if '.vim' in suffix:
170 outs[2].write('syn match lilyNote \"\\<\\(\\(\\(');
171 for line in notes:
172 if line != prevline:
173 if '' in suffix:
174 outs[0].write(line + '\n')
175 if '.el' in suffix:
176 outs[1].write(line + '\n')
177 if '.vim' in suffix:
178 outs[2].write(line + '\\|')
179 prevline = line
180 if '.vim' in suffix:
181 outs[2].write('a\\)\\([,\']\\)\\{,4}\\([?!]\\)\\?\\)\\|s\\|r\\)\\(\\(128\\|64\\|32\\|16\\|8\\|4\\|2\\|1\\|\\\\breve\\|\\\\longa\\|\\\\maxima\\)[.]\\{,8}\\)\\?\\(\\A\\|\\n\\)\"me=e-1\n')
183 # the menu in lilypond-mode.el
184 for line in [
185 '/( - _ /) -',
186 '/[ - _ /] -',
187 '< - _ > -',
188 '<< - _ >> -',
189 '///( - _ ///) -',
190 '///[ - _ ///] -',
191 '///< - _ ///! -',
192 '///> - _ ///! -',
193 '//center - / << _ >> -',
194 '//column - / << _ >> -',
195 '//context/ Staff/ = - % { _ } -',
196 '//context/ Voice/ = - % { _ } -',
197 '//markup - { _ } -',
198 '//notes - { _ } -',
199 '//relative - % { _ } -',
200 '//score - { //n /? //simultaneous { //n _ //n } /! //n //paper { } //n /? //midi { } //n /! } //n -',
201 '//simultaneous - { _ } -',
202 '//sustainDown - _ //sustainUp -',
203 '//times - % { _ } -',
204 '//transpose - % { _ } -',
206 # urg. escape char '/' is replaced with '\\' which python writes as a '\'.
207 if '.el' in suffix:
208 outs[1].write(string.join(string.split(line,'/'),'\\') + '\n')
210 if '' in suffix:
211 outs[0].close()
212 if '.el' in suffix:
213 outs[1].close()
214 if '.vim' in suffix:
215 outs[2].close()