Spaces:
Sleeping
Sleeping
File size: 5,696 Bytes
f65fe85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# lilypond-words.py
#
# This file is part of LilyPond, the GNU music typesetter.
#
# Copyright (C) 2003 Heikki Junes <[email protected]>,
# 2008-2020 John Mandereau <[email protected]>
#
# LilyPond is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LilyPond is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
# Created 01 September 2003 by Heikki Junes.
# Rewritten by John Mandereau
# Generates lilypond-words.el for (X)Emacs and lilypond-words[.vim] for Vim.
import codecs
import re
import sys
import os
import getopt
keywords = []
reserved_words = []
note_names = []
# keywords not otherwise found
keywords += ['include', 'maininput', 'version']
# the main keywords
s = codecs.open('lily/lily-lexer.cc', 'r', 'utf-8').read()
keywords += [w for w in re.findall(r"\s*{\"(.+)\",\s*.*},\s*\n", s)]
# markup commands
for name in ['ly/toc-init.ly',
'scm/define-markup-commands.scm',
'scm/fret-diagrams.scm',
'scm/harp-pedals.scm']:
s = codecs.open(name, 'r', 'utf-8').read()
keywords += [w for w in re.findall(
r"\(define-markup[a-z-]+\s+\(([a-zA-Z-]+)", s)]
# identifiers and keywords
for name in ['ly/chord-modifiers-init.ly',
'ly/dynamic-scripts-init.ly',
'ly/engraver-init.ly',
'ly/grace-init.ly',
'ly/gregorian.ly',
'ly/music-functions-init.ly',
'ly/performer-init.ly',
'ly/property-init.ly',
'ly/scale-definitions-init.ly',
'ly/script-init.ly',
'ly/spanners-init.ly',
'ly/toc-init.ly',
'ly/declarations-init.ly']:
s = codecs.open(name, 'r', 'utf-8').read()
keywords += [w for w in re.findall(r"(?m)^\s*\"?([a-zA-Z]+)\"?\s*=", s)]
# note names
s = codecs.open('scm/define-note-names.scm', 'r', 'utf-8').read()
note_names += [n for n in re.findall(
r"(?m)^\s*\(([a-z]+)\s+\.\s+,\(ly:make-pitch", s)]
# reserved words
for name in ['ly/engraver-init.ly',
'ly/performer-init.ly']:
s = codecs.open(name, 'r', 'utf-8').read()
for pattern in [r"(?m)^\s*.consists\s+\"([a-zA-Z_]+)\"",
r"[\\]name\s+[\"]?([a-zA-Z_]+)[\"]?",
r"\s+([a-zA-Z_]+)\s*\\(?:set|override)"]:
reserved_words += [w for w in re.findall(pattern, s)]
keywords = list(set(keywords))
keywords.sort(reverse=True)
reserved_words = list(set(reserved_words))
reserved_words.sort(reverse=True)
note_names = list(set(note_names))
note_names.sort(reverse=True)
# output
outdir = ''
out_words = False
out_el = False
out_vim = False
options = getopt.getopt(sys.argv[1:],
'', ['words', 'el', 'vim', 'dir='])[0]
for (o, a) in options:
if o == '--words':
out_words = True
elif o == '--el':
out_el = True
elif o == '--vim':
out_vim = True
elif o == '--dir':
outdir = a
if out_words or out_el:
outstring = ''.join(['\\\\' + w + '\n' for w in keywords])
outstring += ''.join([w + '\n' for w in reserved_words])
outstring += ''.join([w + '\n' for w in note_names])
if out_words:
f = open(os.path.join(outdir, 'lilypond-words'), 'w', encoding='utf8')
f.write(outstring)
if out_el:
f = open(os.path.join(outdir, 'lilypond-words.el'), 'w', encoding='utf8')
f.write(outstring)
# the menu in lilypond-mode.el
# for easier typing of this list, replace '/' with '\' below
# when writing to file
elisp_menu = ['/( - _ /) -',
'/[ - _ /] -',
'< - _ > -',
'<< - _ >> -',
'///( - _ ///) -',
'///[ - _ ///] -',
'///< - _ ///! -',
'///> - _ ///! -',
'//center - / << _ >> -',
'//column - / << _ >> -',
'//context/ Staff/ = - % { _ } -',
'//context/ Voice/ = - % { _ } -',
'//markup - { _ } -',
'//notes - { _ } -',
'//relative - % { _ } -',
'//score - { //n /? //simultaneous { //n _ //n } /! //n //layout { } //n /? //midi { } //n /! } //n -',
'//simultaneous - { _ } -',
'//sustainOn - _ //sustainOff -',
'//times - % { _ } -',
'//transpose - % { _ } -',
'']
f.write('\n'.join([line.replace('/', '\\') for line in elisp_menu]))
if out_vim:
f = open(os.path.join(outdir, 'lilypond-words.vim'), 'w', encoding='utf8')
f.write('syn match lilyKeyword \"[-_^]\\?\\\\\\(')
f.write(''.join([w + '\\|' for w in keywords]))
f.write('n\\)\\(\\A\\|\\n\\)\"me=e-1\n')
f.write('syn match lilyReservedWord \"\\(\\A\\|\\n\\)\\(')
f.write(''.join([w + '\\|' for w in reserved_words]))
f.write('Score\\)\\(\\A\\|\\n\\)\"ms=s+1,me=e-1\n')
f.write('syn match lilyNote \"\\<\\(\\(\\(')
f.write(''.join([w + '\\|' for w in note_names]))
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')
|