Layout nitpicks for notime fragment option.
[lilypond.git] / buildscripts / lilypond-words.py
blobeacece2c38dfc590da52e8cabe76e213f7060af6
1 #!@PYTHON@
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.
8 import re
9 import sys
10 import os
11 import getopt
13 keywords = []
14 reserved_words = []
15 note_names = []
17 # keywords not otherwise found
18 keywords += ['include', 'maininput', 'version']
20 # the main keywords
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',
31 'ly/grace-init.ly',
32 'ly/gregorian-init.ly',
33 'ly/music-functions-init.ly',
34 'ly/performer-init.ly',
35 'ly/property-init.ly',
36 'ly/scale-definitions-init.ly',
37 'ly/script-init.ly',
38 'ly/spanners-init.ly',
39 'ly/declarations-init.ly',
40 'ly/params-init.ly']:
41 s = open (name, 'r').read ()
42 keywords += [w for w in re.findall (r"(?m)^\s*\"?([a-zA-Z]+)\"?\s*=", s)]
44 # note names
45 for name in ['ly/catalan.ly',
46 'ly/deutsch.ly',
47 'ly/drumpitch-init.ly',
48 'ly/english.ly',
49 'ly/espanol.ly',
50 'ly/italiano.ly',
51 'ly/nederlands.ly',
52 'ly/norsk.ly',
53 'ly/portugues.ly',
54 'ly/suomi.ly',
55 'ly/svenska.ly',
56 'ly/vlaams.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)]
60 # reserved words
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)
79 # output
80 outdir = ''
81 out_words = False
82 out_el = False
83 out_vim = False
85 options = getopt.getopt (sys.argv[1:],
86 '', ['words', 'el', 'vim', 'dir='])[0]
88 for (o, a) in options:
89 if o == '--words':
90 out_words = True
91 elif o == '--el':
92 out_el = True
93 elif o == '--vim':
94 out_vim = True
95 elif o == '--dir':
96 outdir = a
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])
103 if out_words:
104 f = open (os.path.join (outdir, 'lilypond-words'), 'w')
105 f.write (outstring)
107 if out_el:
108 f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
109 f.write (outstring)
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 = ['/( - _ /) -',
115 '/[ - _ /] -',
116 '< - _ > -',
117 '<< - _ >> -',
118 '///( - _ ///) -',
119 '///[ - _ ///] -',
120 '///< - _ ///! -',
121 '///> - _ ///! -',
122 '//center - / << _ >> -',
123 '//column - / << _ >> -',
124 '//context/ Staff/ = - % { _ } -',
125 '//context/ Voice/ = - % { _ } -',
126 '//markup - { _ } -',
127 '//notes - { _ } -',
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]))
137 if out_vim:
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')