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)]
25 for name in ['ly/toc-init.ly',
26 'scm/define-markup-commands.scm',
27 'scm/fret-diagrams.scm',
28 'scm/harp-pedals.scm']:
29 s = open (name, 'r').read ()
30 keywords += [w for w in re.findall (r"\(define-markup[a-z-]+\s+\(([a-zA-Z-]+)", s)]
32 # identifiers and keywords
33 for name in ['ly/chord-modifiers-init.ly',
34 'ly/dynamic-scripts-init.ly',
35 'ly/engraver-init.ly',
38 'ly/music-functions-init.ly',
39 'ly/performer-init.ly',
40 'ly/property-init.ly',
41 'ly/scale-definitions-init.ly',
43 'ly/spanners-init.ly',
45 'ly/declarations-init.ly']:
46 s = open (name, 'r').read ()
47 keywords += [w for w in re.findall (r"(?m)^\s*\"?([a-zA-Z]+)\"?\s*=", s)]
50 for name in ['ly/catalan.ly',
52 'ly/drumpitch-init.ly',
63 s = open (name, 'r').read ()
64 note_names += [n for n in re.findall (r"(?m)^\s*\(([a-z]+)[^l]+ly:make-pitch", s)]
67 for name in ['ly/engraver-init.ly',
68 'ly/performer-init.ly']:
69 s = open (name, 'r').read ()
70 for pattern in [r"(?m)^\s*.consists\s+\"([a-zA-Z_]+)\"",
71 r"[\\]name\s+[\"]?([a-zA-Z_]+)[\"]?",
72 r"\s+([a-zA-Z_]+)\s*\\(?:set|override)"]:
73 reserved_words += [w for w in re.findall (pattern, s)]
75 keywords = list (set (keywords))
76 keywords.sort (reverse=True)
78 reserved_words = list (set (reserved_words))
79 reserved_words.sort (reverse=True)
81 note_names = list (set (note_names))
82 note_names.sort (reverse=True)
91 options = getopt.getopt (sys.argv[1:],
92 '', ['words', 'el', 'vim', 'dir='])[0]
94 for (o, a) in options:
104 if out_words or out_el:
105 outstring = ''.join (['\\\\' + w + '\n' for w in keywords])
106 outstring += ''.join ([w + '\n' for w in reserved_words])
107 outstring += ''.join ([w + '\n' for w in note_names])
110 f = open (os.path.join (outdir, 'lilypond-words'), 'w')
114 f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
117 # the menu in lilypond-mode.el
118 # for easier typing of this list, replace '/' with '\' below
119 # when writing to file
120 elisp_menu = ['/( - _ /) -',
128 '//center - / << _ >> -',
129 '//column - / << _ >> -',
130 '//context/ Staff/ = - % { _ } -',
131 '//context/ Voice/ = - % { _ } -',
132 '//markup - { _ } -',
134 '//relative - % { _ } -',
135 '//score - { //n /? //simultaneous { //n _ //n } /! //n //layout { } //n /? //midi { } //n /! } //n -',
136 '//simultaneous - { _ } -',
137 '//sustainOn - _ //sustainOff -',
138 '//times - % { _ } -',
139 '//transpose - % { _ } -',
141 f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
144 f = open (os.path.join (outdir, 'lilypond-words.vim'), 'w')
145 f.write ('syn match lilyKeyword \"[-_^]\\?\\\\\\(')
146 f.write (''.join ([w + '\\|' for w in keywords]))
147 f.write ('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
149 f.write ('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(')
150 f.write (''.join ([w + '\\|' for w in reserved_words]))
151 f.write ('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
153 f.write ('syn match lilyNote \"\\<\\(\\(\\(')
154 f.write (''.join ([w + '\\|' for w in note_names]))
155 f.write ('a\\)\\([,\']\\)\\{,4}\\([?!]\\)\\?\\)\\|s\\|r\\|R\\|q\\)\\(\\(128\\|64\\|32\\|16\\|8\\|4\\|2\\|1\\|\\\\breve\\|\\\\longa\\|\\\\maxima\\)[.]\\{,8}\\)\\?\\(\\A\\|\\n\\)\"me=e-1\n')