From 7d5df0215e6aa2ca0da039a394f8820b3a015bcb Mon Sep 17 00:00:00 2001 From: Mats Bengtsson Date: Mon, 9 May 2005 08:41:16 +0000 Subject: [PATCH] * scripts/convert-ly.py: In the conversion to version 1.9.0, keep Scheme expressions and strings unmodified when doing the conversion to postfix notation for slurs and beams. Should hopefully solve most related conversion problems. --- ChangeLog | 5 +++++ scripts/convert-ly.py | 44 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8387f9e803..6118eea170 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-05-09 Mats Bengtsson + * scripts/convert-ly.py: In the conversion to version 1.9.0, + keep Scheme expressions and strings unmodified when doing the + conversion to postfix notation for slurs and beams. Should + hopefully solve most related conversion problems. + * Documentation/user/lilypond-book.itely : Clarify and correct how to call dvips with -h psfonts. diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index abc5e2d81d..4119d0f8f1 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -1439,6 +1439,7 @@ if 1: markup_start = re.compile(r"([-^_]|\\mark)\s*(#\s*'\s*)\(") musicglyph = re.compile(r"\(\s*music\b") + columns = re.compile(r"\(\s*columns\b") submarkup_start = re.compile(r"\(\s*([a-zA-Z]+)") leftpar = re.compile(r"\(") rightpar = re.compile(r"\)") @@ -1466,6 +1467,7 @@ if 1: markup = str[:markup_end] # Modify to new syntax: markup = musicglyph.sub (r"{\\musicglyph", markup) + markup = columns.sub (r"{", markup) markup = submarkup_start.sub (r"{\\\1", markup) markup = leftpar.sub ("{", markup) markup = rightpar.sub ("}", markup) @@ -1478,7 +1480,7 @@ if 1: return result def articulation_substitute (str): - str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""", + str = re.sub (r"""([^-])\[ *(\\?\)?[a-z]+[,']*[!?]?[0-9:]*\.*)""", r"\1 \2[", str) str = re.sub (r"""([^-])\\\) *([a-z]+[,']*[!?]?[0-9:]*\.*)""", r"\1 \2\\)", str) @@ -1488,6 +1490,44 @@ if 1: r"\1 \2\\!", str) return str + string_or_scheme = re.compile ('("(?:[^"\\\\]|\\\\.)*")|(#\\s*\'?\\s*\\()') + + # Only apply articulation_substitute () outside strings and + # Scheme expressions: + def smarter_articulation_subst (str): + result = '' + # Find the beginning of next string or Scheme expr.: + match = string_or_scheme.search (str) + while match: + # Convert the preceding LilyPond code: + previous_chunk = str[:match.start()] + result = result + articulation_substitute (previous_chunk) + if match.group (1): # Found a string + # Copy the string to output: + result = result + match.group (1) + str = str[match.end(1):] + else: # Found a Scheme expression. Count + # matching parentheses to find its end + str = str[match.start ():] + nesting_level = 0 + pars = re.finditer(r"[()]",str) + for par in pars: + if par.group () == '(': + nesting_level = nesting_level + 1 + else: + nesting_level = nesting_level - 1 + if nesting_level == 0: + scheme_end = par.end () + break + # Copy the Scheme expression to output: + result = result + str[:scheme_end] + str = str[scheme_end:] + # Find next string or Scheme expression: + match = string_or_scheme.search (str) + # Convert the remainder of the file + result = result + articulation_substitute (str) + return result + def conv_relative(str): if re.search (r"\\relative", str): str= "#(ly:set-option 'old-relative)\n" + str @@ -1500,7 +1540,7 @@ if 1: str = sub_chords (str) str = text_markup (str) - str = articulation_substitute (str) + str = smarter_articulation_subst (str) str = re.sub ("@SCM_EOL@", "#'()", str) return str -- 2.39.2