]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/lilypond-words.py
Remove params-init.ly.
[lilypond.git] / scripts / build / lilypond-words.py
1 #!@PYTHON@
2
3 # Created 01 September 2003 by Heikki Junes.
4 # Rewritten by John Mandereau
5
6 # Generates lilypond-words.el for (X)Emacs and lilypond-words[.vim] for Vim.
7
8 import re
9 import sys
10 import os
11 import getopt
12
13 keywords = []
14 reserved_words = []
15 note_names = []
16
17 # keywords not otherwise found
18 keywords += ['include', 'maininput', 'version']
19
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)]
23
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)]
26
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.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     s = open (name, 'r').read ()
41     keywords += [w for w in re.findall (r"(?m)^\s*\"?([a-zA-Z]+)\"?\s*=", s)]
42
43 # note names
44 for name in ['ly/catalan.ly',
45              'ly/deutsch.ly',
46              'ly/drumpitch-init.ly',
47              'ly/english.ly',
48              'ly/espanol.ly',
49              'ly/italiano.ly',
50              'ly/nederlands.ly',
51              'ly/norsk.ly',
52              'ly/portugues.ly',
53              'ly/suomi.ly',
54              'ly/svenska.ly',
55              'ly/vlaams.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)]
58
59 # reserved words
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)]
67
68 keywords = list (set (keywords))
69 keywords.sort (reverse=True)
70
71 reserved_words = list (set (reserved_words))
72 reserved_words.sort (reverse=True)
73
74 note_names = list (set (note_names))
75 note_names.sort (reverse=True)
76
77
78 # output
79 outdir = ''
80 out_words = False
81 out_el = False
82 out_vim = False
83
84 options = getopt.getopt (sys.argv[1:],
85   '', ['words', 'el', 'vim', 'dir='])[0]
86
87 for (o, a) in options:
88     if o == '--words':
89         out_words = True
90     elif o == '--el':
91         out_el = True
92     elif o == '--vim':
93         out_vim = True
94     elif o == '--dir':
95         outdir = a
96
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])
101
102 if out_words:
103     f = open (os.path.join (outdir, 'lilypond-words'), 'w')
104     f.write (outstring)
105
106 if out_el:
107     f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
108     f.write (outstring)
109
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 = ['/( - _ /) -',
114                   '/[ - _ /] -',
115                   '< - _ > -',
116                   '<< - _ >> -',
117                   '///( - _ ///) -',
118                   '///[ - _ ///] -',
119                   '///< - _ ///! -',
120                   '///> - _ ///! -',
121                   '//center - / << _ >> -',
122                   '//column - / << _ >> -',
123                   '//context/ Staff/ = - % { _ } -',
124                   '//context/ Voice/ = - % { _ } -',
125                   '//markup - { _ } -',
126                   '//notes - { _ } -',
127                   '//relative - % { _ } -',
128                   '//score - { //n /? //simultaneous { //n _ //n } /! //n //paper {  } //n /? //midi {  } //n /! } //n -',
129                   '//simultaneous - { _ } -',
130                   '//sustainDown - _ //sustainUp -',
131                   '//times - % { _ } -',
132                   '//transpose - % { _ } -',
133                   '']
134     f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
135
136 if out_vim:
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')
141
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')
145
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')