]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scripts/convert-ly.py: Attempt to do a smarter update of
authormatsb <matsb>
Wed, 4 May 2005 16:11:59 +0000 (16:11 +0000)
committermatsb <matsb>
Wed, 4 May 2005 16:11:59 +0000 (16:11 +0000)
text markups from versions < 1.9.0 with arbitrary nesting.

ChangeLog
scripts/convert-ly.py

index be33aba88eb2105c1b6c5ffcda4cb83313ac276a..050a2a872da26f87839317ecf34c4186241470b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-05-04  Mats Bengtsson  <mabe@drongo.s3.kth.se>
+
+       * scripts/convert-ly.py: Attempt to do a smarter update of 
+       text markups from versions < 1.9.0 with arbitrary nesting.
+
 2005-05-04  Heikki Junes  <hjunes@cc.hut.fi>
 
        * po/fi.po: convert to utf-8, and update.
index 06097eb07ecf469c98d5b020c5c7c1a9216f5f2b..abc5e2d81d590398c63bdd79ea36f789a174388d 100644 (file)
@@ -1437,16 +1437,45 @@ if 1:
                str = re.sub (r'@ACCENT@', '>', str)
                return str
 
+       markup_start = re.compile(r"([-^_]|\\mark)\s*(#\s*'\s*)\(")
+       musicglyph = re.compile(r"\(\s*music\b")
+       submarkup_start = re.compile(r"\(\s*([a-zA-Z]+)")
+       leftpar = re.compile(r"\(")
+       rightpar = re.compile(r"\)")
+
        def text_markup (str):
-               str = re.sub (r"""([-_^]) *# *' *\( *music *(\"[^"]*\") *\)""",
-                               r"\1\\markup { \\musicglyph #\2 }", str)
-               str = re.sub (r"""([-_^]) *# *' *\( *([a-z]+) *([^()]*)\)""",
-                               r"\1\\markup { \\\2 \3 }", str)
-               str = re.sub (r"""\\mark *# *' *\( *music *(\"[^"]*\") *\)""",
-                               r"\\mark \\markup { \\musicglyph #\1 }", str)
-               str = re.sub (r"""\\mark *# *' *\( *([a-z]+) *([^()]*)\)""",
-                               r"\\mark \\markup { \\\1 \2 }", str)
-               return str
+               result = ''
+               # Find the beginning of each markup:
+               match = markup_start.search (str)
+               while match:
+                       result = result + str[:match.end (1)] + " \markup"
+                       str = str[match.end( 2):]
+                       # Count matching parentheses to find the end of the 
+                       # current markup:
+                       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:
+                                       markup_end = par.end ()
+                                       break
+                       # The full markup in old syntax:
+                       markup = str[:markup_end]
+                       # Modify to new syntax:
+                       markup = musicglyph.sub (r"{\\musicglyph", markup)
+                       markup = submarkup_start.sub (r"{\\\1", markup)
+                       markup = leftpar.sub ("{", markup)
+                       markup = rightpar.sub ("}", markup)
+       
+                       result = result + markup
+                       # Find next markup
+                       str = str[markup_end:]
+                       match = markup_start.search(str)
+               result = result + str
+               return result
 
        def articulation_substitute (str):
                str = re.sub (r"""([^-])\[ *([a-z]+[,']*[!?]?[0-9:]*\.*)""",