lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LSR updates: was: polychords: a working solution


From: David Kastrup
Subject: Re: LSR updates: was: polychords: a working solution
Date: Tue, 21 Feb 2012 17:55:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Thomas Morley <address@hidden> writes:

> Hi David,
>
> 2012/2/20 David Kastrup <address@hidden>:
>> Thomas Morley <address@hidden> writes:
>>
>>> Hi David, Phil,
>>>
>>> I'll be offline for two days, perhaps three. (Visiting a funeral, ~800
>>> km away from my home)
>>> May I ask you to continue the updating work?
>>
>> I'm just going to take a look at the snippet you analyzed.

Ok, I am now rather annoyed.  I was totally sure that somebody mentioned
\put-adjacent in the context of convertrules, and now doing a web search
I find that it was merely used as an example for localized messages and
nobody had a problem with it not doing any conversion.

It is a 2.11.55 rule.  Now I fixed the conversion.  Suggestions what I
am going to do with it?  Bother with checking it in?  Anybody with a
test case?

diff --git a/python/convertrules.py b/python/convertrules.py
index 3ed1d18..5541fec 100644
--- a/python/convertrules.py
+++ b/python/convertrules.py
@@ -45,6 +45,32 @@ def rule (version, message):
         conversions.append ((version, f, message))
     return dec
 
+# various helper functions creating regexps
+
+def paren_matcher (n):
+    # poor man's matched paren scanning, gives up
+    # after n+1 levels.  Matches any string with balanced
+    # parens inside; add the outer parens yourself if needed.
+    # Nongreedy.
+    return r"[^()]*?(?:\("*n+r"[^()]*?"+r"\)[^()]*?)*?"*n
+    return
+
+def brace_matcher (n):
+    # poor man's matched brace scanning, gives up
+    # after n+1 levels.  Matches any string with balanced
+    # braces inside; add the outer braces yourself if needed.
+    # Nongreedy.
+    return r"[^{}]*?(?:{"*n+r"[^{}]*?"+r"}[^{}]*?)*?"*n
+
+matchstring = r'"(?:[^"\\]|\\.)*"'
+matcharg = (r"\s+(?:[$#]['`]?\s*(?:[a-zA-Z]\S*|" + matchstring + r"|\("
+            + paren_matcher(20) + r"\))|" + matchstring + r"|\\[a-z_A-Z]+)")
+matchmarkup = (r'(?:\\markup\s*(?:{' + brace_matcher (20) +r'}|' +
+               matchstring + r'|(?:\\[a-z_A-Z][a-z_A-Z-]*(?:' + matcharg +
+               r')*?\s*)*(?:' + matchstring + "|{" + brace_matcher (20) +
+               "}))|" + matchstring + ")")
+
+
 
 @rule ((0, 1, 9), _ ('\\header { key = concat + with + operator }'))
 def conv(str):
@@ -2747,11 +2773,8 @@ def conv (str):
 \\put-adjacent markup axis dir markup -> \\put-adjacent axis dir markup 
markup")
 def conv (str):
     str = re.sub (r"#\(set-octavation (-*[0-9]+)\)", r"\\ottava #\1", str)
-    if re.search ('put-adjacent', str):
-        stderr_write (NOT_SMART % _ ("\\put-adjacent argument order"))
-        stderr_write (_ ("Axis and direction now come before markups:\n"))
-        stderr_write (_ ("\\put-adjacent axis dir markup markup."))
-        stderr_write ("\n")
+    str = re.sub (r"\\put-adjacent(" + matchmarkup + ")(" + matcharg*2 + ")",
+                  r"\\put-adjacent\2\1", str)
     return str
 
 @rule ((2, 11, 57), "\\center-align -> \\center-column, \\hcenter -> 
\\center-align")
@@ -3211,14 +3234,6 @@ def conv (str):
         stderr_write (UPDATE_MANUALLY)
     return str
 
-def paren_matcher (n):
-    # poor man's matched paren scanning, gives up
-    # after n+1 levels.  Matches any string with balanced
-    # parens inside; add the outer parens yourself if needed.
-    # Nongreedy.
-    return r"[^()]*?(?:\("*n+r"[^()]*?"+r"\)[^()]*?)*?"*n
-    return
-
 def undollar_scm (m):
     return re.sub (r"\$(.?)", r"\1", m.group (0))
 
@@ -3289,21 +3304,6 @@ def conv (str):
                   r"\1\\accidentalStyle", str)
     return str
 
-def brace_matcher (n):
-    # poor man's matched brace scanning, gives up
-    # after n+1 levels.  Matches any string with balanced
-    # braces inside; add the outer braces yourself if needed.
-    # Nongreedy.
-    return r"[^{}]*?(?:{"*n+r"[^{}]*?"+r"}[^{}]*?)*?"*n
-
-matchstring = r'"(?:[^"\\]|\\.)*"'
-matcharg = (r"\s+(?:[$#]['`]?\s*(?:[a-zA-Z]\S*|" + matchstring + r"|\("
-            + paren_matcher(20) + r"\))|" + matchstring + r"|\\[a-z_A-Z]+)")
-matchmarkup = (r'(?:\\markup\s*(?:{' + brace_matcher (20) +r'}|' +
-               matchstring + r'|(?:\\[a-z_A-Z][a-z_A-Z-]*(?:' + matcharg +
-               r')*?\s*)*(?:' + matchstring + "|{" + brace_matcher (20) +
-               "}))|" + matchstring + ")")
-
 @rule((2, 15, 25), r"\(auto)?Footnote(Grob)? -> \footnote")
 def conv (str):
     # The following replacement includes the final markup argument in

-- 
David Kastrup

reply via email to

[Prev in Thread] Current Thread [Next in Thread]