]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lilypond.words.py
64045a1445ad433908c06a32c6bbbf6c21aa2022
[lilypond.git] / buildscripts / lilypond.words.py
1 #!@PYTHON@
2
3 # Created 01 September 2003 by Heikki Junes.
4 # Generates lilypond.words.el for (X)Emacs and lilypond.words.vim for Vim.
5
6 import string
7 import re
8 import sys
9
10 kw = []
11 rw = []
12 notes = []
13
14 # keywords not otherwise found
15 for line in ['include','maininput','version']:
16     kw = kw + [line]
17
18 # the main keywords
19 F = open('lily/my-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()
25
26 # keywords in markup
27 F = open('scm/new-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()
33
34 # identifiers and keywords
35 for name in [
36 'ly/a4-init.ly',
37 'ly/chord-modifiers-init.ly',
38 'ly/dynamic-scripts-init.ly',
39 'ly/engraver-init.ly',
40 'ly/grace-init.ly',
41 'ly/gregorian-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',
47 ]:
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()
54
55 # more identifiers
56 for name in [
57 'ly/declarations-init.ly',
58 'ly/params-init.ly',
59 'ly/params-as-init.ly',
60 ]:
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()
67
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/suomi.ly',
79 'ly/svenska.ly',
80 ]:
81     F = open(name, 'r')
82     for line in F.readlines():
83         m = re.search(r"^(\s*\()([a-z]+)([^l]+ly:make-pitch)",line)
84         if m:
85             notes = notes + ['' + m.group(2)]
86     F.close()
87
88 # (short) drum names
89 for name in [
90 'scm/drums.scm'
91 ]:
92     F = open(name, 'r')
93     for line in F.readlines():
94         m = re.search(r"^(\s*\([a-z]+\s*)([a-z]+)(\s*,\(ly:make-pitch)",line)
95         if m:
96             notes = notes + ['' + m.group(2)]
97     F.close()
98     
99 # reserved words
100 for name in [
101 'ly/engraver-init.ly',
102 'ly/performer-init.ly',
103 ]:
104     F = open(name, 'r')
105     for line in F.readlines():
106         for pattern in [
107         r"^(\s*.consists\s+\")([a-zA-Z_]+)(\")",
108         r"([\\]name\s+[\"]?)([a-zA-Z_]+)([\"]?)",
109         r"(\s+)([a-zA-Z_]+)(\s*[\\]((set)|(override)))",
110         ]:
111             m = re.search(pattern,line)
112             if m:
113                 rw = rw + ['' + m.group(2)]
114     F.close()
115
116 # the output file
117 if sys.argv[1:] == []:
118   out_el = open('lilypond.words.el', 'w')
119   out_vim = open('lilypond.words.vim', 'w')
120 else:
121   out_el = open(sys.argv[1]+'/lilypond.words.el', 'w')
122   out_vim = open(sys.argv[1]+'/lilypond.words.vim', 'w')
123    
124 # alphabetically ordered words
125 kw.sort()
126 kw.reverse()
127 prevline = ''
128 out_vim.write('syn match lilyKeyword \"[-_^]\\?\\\\\\(');
129 for line in kw:
130     if line != prevline:
131         out_el.write('\\\\' + line + '\n')
132         out_vim.write(line + '\\|')
133     prevline = line
134 out_vim.write('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
135
136 rw.sort()
137 rw.reverse()
138 prevline = ''
139 out_vim.write('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(');
140 for line in rw:
141     if line != prevline:
142         out_el.write(line + '\n')
143         out_vim.write(line + '\\|')
144     prevline = line
145 out_vim.write('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
146
147 notes.sort()
148 notes.reverse()
149 prevline = ''
150 out_vim.write('syn match lilyNote \"\\<\\(\\(\\(');
151 for line in notes:
152     if line != prevline:
153         out_el.write(line + '\n')
154         out_vim.write(line + '\\|')
155     prevline = line
156 out_vim.write('a\\)\\([,\']\\)\\{,4}\\([?!]\\)\\?\\)\\|s\\|r\\)\\(\\(128\\|64\\|32\\|16\\|8\\|4\\|2\\|1\\|\\\\breve\\|\\\\longa\\|\\\\maxima\\)[.]\\{,8}\\)\\?\\(\\A\\|\\n\\)\"me=e-1\n')
157
158 # the menu in lilypond-mode.el
159 for line in [
160 '/( - _ /) -',
161 '/[ - _ /] -',
162 '< - _ > -',
163 '<< - _ >> -',
164 '///( - _ ///) -',
165 '///[ - _ ///] -',
166 '///< - _ ///! -',
167 '///> - _ ///! -',
168 '//center - / << _ >> -',
169 '//column - / << _ >> -',
170 '//context/ Staff/ = - % { _ } -',
171 '//context/ Voice/ = - % { _ } -',
172 '//markup - { _ } -',
173 '//notes - { _ } -',
174 '//relative - % { _ } -',
175 '//score - { //n /? //simultaneous { //n _ //n } /! //n //paper {  } //n /? //midi {  } //n /! } //n -',
176 '//simultaneous - { _ } -',
177 '//sustainDown - _ //sustainUp -',
178 '//times - % { _ } -',
179 '//transpose - % { _ } -',
180 ]:
181     # urg. escape char '/' is replaced with '\\' which python writes as a '\'.
182     out_el.write(string.join(string.split(line,'/'),'\\') + '\n')
183  
184 out_el.close()
185 out_vim.close()