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 s = open ('scm/define-note-names.scm', 'r').read ()
51 note_names += [n for n in re.findall (r"(?m)^\s*\(([a-z]+)\s+\.\s+,\(ly:make-pitch", s)]
54 for name in ['ly/engraver-init.ly',
55 'ly/performer-init.ly']:
56 s = open (name, 'r').read ()
57 for pattern in [r"(?m)^\s*.consists\s+\"([a-zA-Z_]+)\"",
58 r"[\\]name\s+[\"]?([a-zA-Z_]+)[\"]?",
59 r"\s+([a-zA-Z_]+)\s*\\(?:set|override)"]:
60 reserved_words += [w for w in re.findall (pattern, s)]
62 keywords = list (set (keywords))
63 keywords.sort (reverse=True)
65 reserved_words = list (set (reserved_words))
66 reserved_words.sort (reverse=True)
68 note_names = list (set (note_names))
69 note_names.sort (reverse=True)
78 options = getopt.getopt (sys.argv[1:],
79 '', ['words', 'el', 'vim', 'dir='])[0]
81 for (o, a) in options:
91 if out_words or out_el:
92 outstring = ''.join (['\\\\' + w + '\n' for w in keywords])
93 outstring += ''.join ([w + '\n' for w in reserved_words])
94 outstring += ''.join ([w + '\n' for w in note_names])
97 f = open (os.path.join (outdir, 'lilypond-words'), 'w')
101 f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
104 # the menu in lilypond-mode.el
105 # for easier typing of this list, replace '/' with '\' below
106 # when writing to file
107 elisp_menu = ['/( - _ /) -',
115 '//center - / << _ >> -',
116 '//column - / << _ >> -',
117 '//context/ Staff/ = - % { _ } -',
118 '//context/ Voice/ = - % { _ } -',
119 '//markup - { _ } -',
121 '//relative - % { _ } -',
122 '//score - { //n /? //simultaneous { //n _ //n } /! //n //layout { } //n /? //midi { } //n /! } //n -',
123 '//simultaneous - { _ } -',
124 '//sustainOn - _ //sustainOff -',
125 '//times - % { _ } -',
126 '//transpose - % { _ } -',
128 f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
131 f = open (os.path.join (outdir, 'lilypond-words.vim'), 'w')
132 f.write ('syn match lilyKeyword \"[-_^]\\?\\\\\\(')
133 f.write (''.join ([w + '\\|' for w in keywords]))
134 f.write ('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
136 f.write ('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(')
137 f.write (''.join ([w + '\\|' for w in reserved_words]))
138 f.write ('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
140 f.write ('syn match lilyNote \"\\<\\(\\(\\(')
141 f.write (''.join ([w + '\\|' for w in note_names]))
142 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')