]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/lilypond-words.py
Add '-dcrop' option to ps and svg backends
[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 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)]
52
53 # reserved words
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)]
61
62 keywords = list (set (keywords))
63 keywords.sort (reverse=True)
64
65 reserved_words = list (set (reserved_words))
66 reserved_words.sort (reverse=True)
67
68 note_names = list (set (note_names))
69 note_names.sort (reverse=True)
70
71
72 # output
73 outdir = ''
74 out_words = False
75 out_el = False
76 out_vim = False
77
78 options = getopt.getopt (sys.argv[1:],
79   '', ['words', 'el', 'vim', 'dir='])[0]
80
81 for (o, a) in options:
82     if o == '--words':
83         out_words = True
84     elif o == '--el':
85         out_el = True
86     elif o == '--vim':
87         out_vim = True
88     elif o == '--dir':
89         outdir = a
90
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])
95
96 if out_words:
97     f = open (os.path.join (outdir, 'lilypond-words'), 'w')
98     f.write (outstring)
99
100 if out_el:
101     f = open (os.path.join (outdir, 'lilypond-words.el'), 'w')
102     f.write (outstring)
103
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 = ['/( - _ /) -',
108                   '/[ - _ /] -',
109                   '< - _ > -',
110                   '<< - _ >> -',
111                   '///( - _ ///) -',
112                   '///[ - _ ///] -',
113                   '///< - _ ///! -',
114                   '///> - _ ///! -',
115                   '//center - / << _ >> -',
116                   '//column - / << _ >> -',
117                   '//context/ Staff/ = - % { _ } -',
118                   '//context/ Voice/ = - % { _ } -',
119                   '//markup - { _ } -',
120                   '//notes - { _ } -',
121                   '//relative - % { _ } -',
122                   '//score - { //n /? //simultaneous { //n _ //n } /! //n //layout {  } //n /? //midi {  } //n /! } //n -',
123                   '//simultaneous - { _ } -',
124                   '//sustainOn - _ //sustainOff -',
125                   '//times - % { _ } -',
126                   '//transpose - % { _ } -',
127                   '']
128     f.write ('\n'.join ([line.replace ('/', '\\') for line in elisp_menu]))
129
130 if out_vim:
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')
135
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')
139
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')