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']:
40 s = open (name, 'r').read ()
41 keywords += [w for w in re.findall (r"(?m)^\s*\"?([a-zA-Z]+)\"?\s*=", s)]
44 for name in ['ly/catalan.ly',
46 'ly/drumpitch-init.ly',
56 s = open (name, 'r').read ()
57 note_names += [n for n in re.findall (r"(?m)^\s*\(([a-z]+)[^l]+ly:make-pitch", s)]
60 for name in ['ly/engraver-init.ly',
61 'ly/performer-init.ly']:
62 s = open (name, 'r').read ()
63 for pattern in [r"(?m)^\s*.consists\s+\"([a-zA-Z_]+)\"",
64 r"[\\]name\s+[\"]?([a-zA-Z_]+)[\"]?",
65 r"\s+([a-zA-Z_]+)\s*\\(?:set|override)"]:
66 reserved_words += [w for w in re.findall (pattern, s)]
68 keywords = list (set (keywords))
69 keywords.sort (reverse=True)
71 reserved_words = list (set (reserved_words))
72 reserved_words.sort (reverse=True)
74 note_names = list (set (note_names))
75 note_names.sort (reverse=True)
84 options = getopt.getopt (sys.argv[1:],
85 '', ['words', 'el', 'vim', 'dir='])[0]
87 for (o, a) in options:
97 if out_words or out_el:
98 outstring = ''.join (['\\\\' + w + '\n' for w in keywords])
99 outstring += ''.join ([w + '\n' for w in reserved_words])
100 outstring += ''.join ([w + '\n' for w in note_names])
103 f = open (os.path.join (outdir, 'lilypond-words'), 'w')
107 f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
110 # the menu in lilypond-mode.el
111 # for easier typing of this list, replace '/' with '\' below
112 # when writing to file
113 elisp_menu = ['/( - _ /) -',
121 '//center - / << _ >> -',
122 '//column - / << _ >> -',
123 '//context/ Staff/ = - % { _ } -',
124 '//context/ Voice/ = - % { _ } -',
125 '//markup - { _ } -',
127 '//relative - % { _ } -',
128 '//score - { //n /? //simultaneous { //n _ //n } /! //n //paper { } //n /? //midi { } //n /! } //n -',
129 '//simultaneous - { _ } -',
130 '//sustainDown - _ //sustainUp -',
131 '//times - % { _ } -',
132 '//transpose - % { _ } -',
134 f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
137 f = open (os.path.join (outdir, 'lilypond-words.vim'), 'w')
138 f.write ('syn match lilyKeyword \"[-_^]\\?\\\\\\(')
139 f.write (''.join ([w + '\\|' for w in keywords]))
140 f.write ('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
142 f.write ('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(')
143 f.write (''.join ([w + '\\|' for w in reserved_words]))
144 f.write ('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
146 f.write ('syn match lilyNote \"\\<\\(\\(\\(')
147 f.write (''.join ([w + '\\|' for w in note_names]))
148 f.write ('a\\)\\([,\']\\)\\{,4}\\([?!]\\)\\?\\)\\|s\\|r\\)\\(\\(128\\|64\\|32\\|16\\|8\\|4\\|2\\|1\\|\\\\breve\\|\\\\longa\\|\\\\maxima\\)[.]\\{,8}\\)\\?\\(\\A\\|\\n\\)\"me=e-1\n')