3 # Created 01 September 2003 by Heikki Junes.
4 # Rewritten by John Mandereau
6 # Generates lilypond-words.el for (X)Emacs and lilypond-words[.vim] for Vim.
17 # keywords not otherwise found
18 keywords
+= ['include', 'maininput', 'version']
21 s
= open ('lily/lily-lexer.cc', 'r').read ()
22 keywords
+= [w
for w
in re
.findall (r
"\s*{\"(.+)\",\s
*.*},\s
*\n", s)]
24 s = open ('scm/markup.scm', 'r').read ()
25 keywords += [w for w in re.findall (r"(?m
)^\s
*\
(cons\s
*([a
-z
-]+)-markup
", s)]
27 # identifiers and keywords
28 for name in ['ly/chord-modifiers-init.ly',
29 'ly/dynamic-scripts-init.ly',
30 'ly/engraver-init.ly',
33 'ly/music-functions-init.ly',
34 'ly/performer-init.ly',
35 'ly/property-init.ly',
36 'ly/scale-definitions-init.ly',
38 'ly/spanners-init.ly',
39 'ly/declarations-init.ly',
41 s = open (name, 'r').read ()
42 keywords += [w for w in re.findall (r"(?m
)^\s
*\"?
([a
-zA
-Z
]+)\"?\s
*=", s)]
45 for name in ['ly/catalan.ly',
47 'ly/drumpitch-init.ly',
57 s = open (name, 'r').read ()
58 note_names += [n for n in re.findall (r"(?m
)^\s
*\
(([a
-z
]+)[^l
]+ly
:make
-pitch
", s)]
61 for name in ['ly/engraver-init.ly',
62 'ly/performer-init.ly']:
63 s = open (name, 'r').read ()
64 for pattern in [r"(?m
)^\s
*.consists\s
+\"([a
-zA
-Z_
]+)\"",
65 r"[\\]name\s
+[\"]?
([a
-zA
-Z_
]+)[\"]?
",
66 r"\s
+([a
-zA
-Z_
]+)\s
*\\(?
:set|override
)"]:
67 reserved_words += [w for w in re.findall (pattern, s)]
69 keywords = list (set (keywords))
70 keywords.sort (reverse=True)
72 reserved_words = list (set (reserved_words))
73 reserved_words.sort (reverse=True)
75 note_names = list (set (note_names))
76 note_names.sort (reverse=True)
85 options = getopt.getopt (sys.argv[1:],
86 '', ['words', 'el', 'vim', 'dir='])[0]
88 for (o, a) in options:
98 if out_words or out_el:
99 outstring = ''.join (['\\\\' + w + '\n' for w in keywords])
100 outstring += ''.join ([w + '\n' for w in reserved_words])
101 outstring += ''.join ([w + '\n' for w in note_names])
104 f = open (os.path.join (outdir, 'lilypond-words'), 'w')
108 f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
111 # the menu in lilypond-mode.el
112 # for easier typing of this list, replace '/' with '\' below
113 # when writing to file
114 elisp_menu = ['/( - _ /) -',
122 '//center - / << _ >> -',
123 '//column - / << _ >> -',
124 '//context/ Staff/ = - % { _ } -',
125 '//context/ Voice/ = - % { _ } -',
126 '//markup - { _ } -',
128 '//relative - % { _ } -',
129 '//score - { //n /? //simultaneous { //n _ //n } /! //n //paper { } //n /? //midi { } //n /! } //n -',
130 '//simultaneous - { _ } -',
131 '//sustainDown - _ //sustainUp -',
132 '//times - % { _ } -',
133 '//transpose - % { _ } -',
135 f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
138 f = open (os.path.join (outdir, 'lilypond-words.vim'), 'w')
139 f.write ('syn match lilyKeyword \"[-_^]\\?\\\\\\(')
140 f.write (''.join ([w + '\\|' for w in keywords]))
141 f.write ('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
143 f.write ('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(')
144 f.write (''.join ([w + '\\|' for w in reserved_words]))
145 f.write ('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
147 f.write ('syn match lilyNote \"\\<\\(\\(\\(')
148 f.write (''.join ([w + '\\|' for w in note_names]))
149 f.write ('a\\)\\([,\']\\)\\{,4}\\([?!]\\)\\?\\)\\|s\\|r\\)\\(\\(128\\|64\\|32\\|16\\|8\\|4\\|2\\|1\\|\\\\breve\\|\\\\longa\\|\\\\maxima\\)[.]\\{,8}\\)\\?\\(\\A\\|\\n\\)\"me=e-1\n')