]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/lilypond-words.py
Merge branch 'master' into lilypond/translation
[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 # markup commands
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)]
31
32 # identifiers and keywords
33 for name in ['ly/chord-modifiers-init.ly',
34              'ly/dynamic-scripts-init.ly',
35              'ly/engraver-init.ly',
36              'ly/grace-init.ly',
37              'ly/gregorian.ly',
38              'ly/music-functions-init.ly',
39              'ly/performer-init.ly',
40              'ly/property-init.ly',
41              'ly/scale-definitions-init.ly',
42              'ly/script-init.ly',
43              'ly/spanners-init.ly',
44              'ly/toc-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)]
48
49 # note names
50 for name in ['ly/catalan.ly',
51              'ly/deutsch.ly',
52              'ly/drumpitch-init.ly',
53              'ly/english.ly',
54              'ly/espanol.ly',
55              'ly/italiano.ly',
56              'ly/makam.ly',
57              'ly/nederlands.ly',
58              'ly/norsk.ly',
59              'ly/portugues.ly',
60              'ly/suomi.ly',
61              'ly/svenska.ly',
62              'ly/vlaams.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)]
65
66 # reserved words
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)]
74
75 keywords = list (set (keywords))
76 keywords.sort (reverse=True)
77
78 reserved_words = list (set (reserved_words))
79 reserved_words.sort (reverse=True)
80
81 note_names = list (set (note_names))
82 note_names.sort (reverse=True)
83
84
85 # output
86 outdir = ''
87 out_words = False
88 out_el = False
89 out_vim = False
90
91 options = getopt.getopt (sys.argv[1:],
92   '', ['words', 'el', 'vim', 'dir='])[0]
93
94 for (o, a) in options:
95     if o == '--words':
96         out_words = True
97     elif o == '--el':
98         out_el = True
99     elif o == '--vim':
100         out_vim = True
101     elif o == '--dir':
102         outdir = a
103
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])
108
109 if out_words:
110     f = open (os.path.join (outdir, 'lilypond-words'), 'w')
111     f.write (outstring)
112
113 if out_el:
114     f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
115     f.write (outstring)
116
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 = ['/( - _ /) -',
121                   '/[ - _ /] -',
122                   '< - _ > -',
123                   '<< - _ >> -',
124                   '///( - _ ///) -',
125                   '///[ - _ ///] -',
126                   '///< - _ ///! -',
127                   '///> - _ ///! -',
128                   '//center - / << _ >> -',
129                   '//column - / << _ >> -',
130                   '//context/ Staff/ = - % { _ } -',
131                   '//context/ Voice/ = - % { _ } -',
132                   '//markup - { _ } -',
133                   '//notes - { _ } -',
134                   '//relative - % { _ } -',
135                   '//score - { //n /? //simultaneous { //n _ //n } /! //n //layout {  } //n /? //midi {  } //n /! } //n -',
136                   '//simultaneous - { _ } -',
137                   '//sustainOn - _ //sustainOff -',
138                   '//times - % { _ } -',
139                   '//transpose - % { _ } -',
140                   '']
141     f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
142
143 if out_vim:
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')
148
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')
152
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')