summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavid Kastrup <dak@gnu.org>2013-09-17 14:51:53 +0200
committerDavid Kastrup <dak@gnu.org>2013-09-20 17:29:14 +0200
commit85368f8f3acd73268bae4b5bbfc983aa6b665ef8 (patch)
treed0cc0b0398f32394fc489b07635a886ce94b4704 /python
parent91a368bfa103d6c74e0ad5f9701582509c5b1703 (diff)
Issue 3292/2: Add \defaultchild rule for convert-ly
Diffstat (limited to 'python')
-rw-r--r--python/convertrules.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/python/convertrules.py b/python/convertrules.py
index 854b8d2304..fbc683330d 100644
--- a/python/convertrules.py
+++ b/python/convertrules.py
@@ -3521,6 +3521,28 @@ def conv(str):
r"\1/\2", str)
return str
+@rule((2, 17, 14), r"\accepts ... -> \accepts ... \defaultchild ...")
+def conv(str):
+ def matchaccepts(m):
+ # First weed out definitions starting from an existing
+ # definition: we assume that the inherited \defaultchild is
+ # good enough for our purposes. Heuristic: starts with a
+ # backslash and an uppercase letter.
+ if re.match (r"\s*\\[A-Z]", m.group (1)):
+ return m.group (0)
+ # existing defaultchild obviously trumps all
+ if re.search (r"\\defaultchild[^-_a-zA-Z]", m.group (1)):
+ return m.group (0)
+ # take the first \\accepts if any and replicate it
+ return re.sub ("(\r?\n[ \t]*|[ \t]+)"
+ + r"""\\accepts(\s+(?:#?".*?"|[-_a-zA-Z]+))""",
+ r"\g<0>\1\\defaultchild\2",
+ m.group (0), 1)
+
+ str = re.sub (r"\\context\s*@?\{(" + brace_matcher (20) + ")\}",
+ matchaccepts, str)
+ return str
+
@rule((2, 17, 15), r"""#(ly:set-option 'old-relative)
\relative -> \relative c'""")
def conv(str):