]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/lilypond.words.py
* scm/document-backend.scm (interface-doc): sort grob list for interface.
[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 ]:
60     F = open(name, 'r')
61     for line in F.readlines():
62         m = re.search(r"^(\s*)([a-zA-Z]+)(\s*=)",line)
63         if m:
64             kw = kw + [m.group(2)]
65     F.close()
66
67 # note names
68 for name in [
69 'ly/catalan.ly',
70 'ly/deutsch.ly',
71 'ly/drumpitch-init.ly',
72 'ly/english.ly',
73 'ly/espanol.ly',
74 'ly/italiano.ly',
75 'ly/nederlands.ly',
76 'ly/norsk.ly',
77 'ly/suomi.ly',
78 'ly/svenska.ly',
79 ]:
80     F = open(name, 'r')
81     for line in F.readlines():
82         m = re.search(r"^(\s*\()([a-z]+)([^l]+ly:make-pitch)",line)
83         if m:
84             notes = notes + ['' + m.group(2)]
85     F.close()
86
87
88     
89 # reserved words
90 for name in [
91 'ly/engraver-init.ly',
92 'ly/performer-init.ly',
93 ]:
94     F = open(name, 'r')
95     for line in F.readlines():
96         for pattern in [
97         r"^(\s*.consists\s+\")([a-zA-Z_]+)(\")",
98         r"([\\]name\s+[\"]?)([a-zA-Z_]+)([\"]?)",
99         r"(\s+)([a-zA-Z_]+)(\s*[\\]((set)|(override)))",
100         ]:
101             m = re.search(pattern,line)
102             if m:
103                 rw = rw + ['' + m.group(2)]
104     F.close()
105
106 # the output file
107 if sys.argv[1:] == []:
108   out_el = open('lilypond.words.el', 'w')
109   out_vim = open('lilypond.words.vim', 'w')
110 else:
111   out_el = open(sys.argv[1]+'/lilypond.words.el', 'w')
112   out_vim = open(sys.argv[1]+'/lilypond.words.vim', 'w')
113    
114 # alphabetically ordered words
115 kw.sort()
116 kw.reverse()
117 prevline = ''
118 out_vim.write('syn match lilyKeyword \"[-_^]\\?\\\\\\(');
119 for line in kw:
120     if line != prevline:
121         out_el.write('\\\\' + line + '\n')
122         out_vim.write(line + '\\|')
123     prevline = line
124 out_vim.write('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
125
126 rw.sort()
127 rw.reverse()
128 prevline = ''
129 out_vim.write('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(');
130 for line in rw:
131     if line != prevline:
132         out_el.write(line + '\n')
133         out_vim.write(line + '\\|')
134     prevline = line
135 out_vim.write('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
136
137 notes.sort()
138 notes.reverse()
139 prevline = ''
140 out_vim.write('syn match lilyNote \"\\<\\(\\(\\(');
141 for line in notes:
142     if line != prevline:
143         out_el.write(line + '\n')
144         out_vim.write(line + '\\|')
145     prevline = line
146 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')
147
148 # the menu in lilypond-mode.el
149 for line in [
150 '/( - _ /) -',
151 '/[ - _ /] -',
152 '< - _ > -',
153 '<< - _ >> -',
154 '///( - _ ///) -',
155 '///[ - _ ///] -',
156 '///< - _ ///! -',
157 '///> - _ ///! -',
158 '//center - / << _ >> -',
159 '//column - / << _ >> -',
160 '//context/ Staff/ = - % { _ } -',
161 '//context/ Voice/ = - % { _ } -',
162 '//markup - { _ } -',
163 '//notes - { _ } -',
164 '//relative - % { _ } -',
165 '//score - { //n /? //simultaneous { //n _ //n } /! //n //paper {  } //n /? //midi {  } //n /! } //n -',
166 '//simultaneous - { _ } -',
167 '//sustainDown - _ //sustainUp -',
168 '//times - % { _ } -',
169 '//transpose - % { _ } -',
170 ]:
171     # urg. escape char '/' is replaced with '\\' which python writes as a '\'.
172     out_el.write(string.join(string.split(line,'/'),'\\') + '\n')
173  
174 out_el.close()
175 out_vim.close()