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
|
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
#
# Copyright (c) 2008, 2009, 2010 by Wilbert Berendsen
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# See http://www.gnu.org/licenses/ for more information.
from __future__ import unicode_literals
""" All kinds or regular expressions dealing with the LilyPond format """
import re
step = (
r"\b("
r"[a-h]("
r"(iss){1,2}|(ess){1,2}|(is){1,2}|(es){1,2}"
r"|(sharp){1,2}|(flat){1,2}|ss?|x|ff?"
r"|(is)?ih|(es)eh|t?q[sf]" # quarter tones
r")?"
r"|(do|re|mi|fa|sol|la|si)("
r"dd?|bb?|ss?|kk?"
r"b?sb|d?sd|[bs]t?qt" # quarter tones
r")?"
r"|as|asess?|asas|es|esess?" # special cases
r"|eseh|as[ae]h" # special quarter tone cases
r")(?![A-Za-z])"
)
named_step = "(?P<step>" + step + ")"
rest = r"(\b[Rrs]|\\skip)(?![A-Za-z])"
named_rest = "(?P<rest>" + rest + ")"
octave = r"('+|,+|(?![A-Za-z]))"
named_octave = "(?P<octave>" + octave + ")"
cautionary = r"[?!]?"
named_cautionary = "(?P<cautionary>" + cautionary + ")"
octcheck = "=[',]*"
named_octcheck = "(?P<octcheck>" + octcheck + ")"
pitch = (
step + octave + cautionary + r"(\s*" + octcheck + r")?")
named_pitch = (
named_step + named_octave + named_cautionary + r"(\s*" +
named_octcheck + r")?")
duration = (
r"(?P<duration>"
r"(?P<dur>"
r"\\(maxima|longa|breve)\b|"
r"(1|2|4|8|16|32|64|128|256|512|1024|2048)(?!\d)"
r")"
r"(\s*(?P<dots>\.+))?"
r"(?P<scale>(\s*\*\s*\d+(/\d+)?)*)"
r")"
)
quotedstring = r"\"(?:\\\\|\\\"|[^\"])*\""
skip_pitches = (
# skip \relative or \transpose pitch, etc:
r"\\(relative|transposition)\s+" + pitch +
r"|\\transpose\s+" + pitch + r"\s*" + pitch +
# and skip commands
r"|\\[A-Za-z]+"
)
# a sounding pitch/chord with duration
chord = re.compile(
# skip this:
r"<<|>>|" + quotedstring +
# but catch either a pitch plus an octave
r"|(?P<full>(?P<chord>" + named_pitch +
# or a chord:
r"|<(\\[A-Za-z]+|" + quotedstring + r"|[^>])*>"
r")"
# finally a duration?
r"(\s*" + duration + r")?)"
r"|" + skip_pitches
)
# a sounding pitch/chord OR rest/skip with duration
chord_rest = re.compile(
# skip this:
r"<<|>>|" + quotedstring +
# but catch either a pitch plus an octave
r"|(?P<full>(?P<chord>" + named_pitch +
# or a chord:
r"|<(\\[A-Za-z]+|" + quotedstring + r"|[^>])*>"
# or a spacer or rest:
r"|" + named_rest +
r")"
# finally a duration?
r"(\s*" + duration + r")?)"
r"|" + skip_pitches
)
finddurs = re.compile(duration)
lyric_word = re.compile(r'[^\W0-9_]+', re.UNICODE)
include_file = re.compile(r'\\include\s*"([^"]+)"')
# does not take percent signs inside quoted strings into account
comment = r'%\{.*?%\}|%.*?\n'
all_comments = re.compile(comment, re.DOTALL)
# document language
language = re.compile(
r'.*\\include\s*"('
"nederlands|english|deutsch|norsk|svenska|suomi|"
"italiano|catalan|espanol|portugues|vlaams"
r')\.ly"', re.DOTALL)
# point and click, check for matchgroup 1 (on) and/or 2 (off)
point_and_click = re.compile(
quotedstring + "|" + comment +
r"|(\\pointAndClickOn\b|#\s*\(ly:set-option\s+'point-and-click\s+#t\s*\))"
r"|(\\pointAndClickOff\b|#\s*\(ly:set-option\s+'point-and-click\s+#f\s*\))",
re.DOTALL)
|