default_ly_options = {}
AFTER = 'after'
+FILTER = 'filter'
BEFORE = 'before'
FRAGMENT = 'fragment'
HTML = 'html'
output = {
HTML : {
+ FILTER: r'''<lilypond %(options)s>
+%(code)s
+</lilypond>
+''',
+
AFTER: r'''
</a>
</p>''',
VERBATIM: r'''\begin{verbatim}
%(verb)s\end{verbatim}
''',
+ FILTER: r'''\begin{lilypond}[%(options)s]
+%(code)s
+\end{lilypond}''',
},
TEXINFO : {
+ FILTER: r'''@lilypond[%(options)s]
+%(code)s
+@lilypond''',
AFTER: '',
BEFORE: '',
OUTPUT: r'''
class Chunk:
def replacement_text (self):
return ''
+
+ def filter_text (self):
+ return self.replacement_text ()
+
def is_outdated (self):
return 0
def substring (self, s):
return self.match.group (s)
- def filter_code (self):
- pass # todo
-
def __repr__ (self):
return `self.__class__` + " type = " + self.type
self.options = split_options (os)
def ly (self):
- if self.type == 'lilypond_file':
- name = self.substring ('filename')
- return '\\renameinput \"%s\"\n' % name\
- + open (find_file (name)).read ()
- else:
- return self.substring ('code')
+ return self.substring ('code')
def full_ly (self):
s = self.ly ()
return None
return self
+ def filter_text (self):
+ code = self.substring ('code')
+ s = run_filter (code)
+ d = {'code' : s,
+ 'options': self.match.group ('options')
+ }
+ # TODO
+ return output[self.format][FILTER] % d
+
def replacement_text (self):
func = Lilypond_snippet.__dict__ ['output_' + self.format]
return func (self)
str += '\n'
return str
+
+class Lilypond_file_snippet (Lilypond_snippet):
+ def ly (self):
+ name = self.substring ('filename')
+ return '\\renameinput \"%s\"\n' % name\
+ + open (find_file (name)).read ()
+
snippet_type_to_class = {
- 'lilypond_file' : Lilypond_snippet,
+ 'lilypond_file' : Lilypond_file_snippet,
'lilypond_block' : Lilypond_snippet,
'lilypond' : Lilypond_snippet,
'include' : Include_snippet,
def run_filter (s):
return filter_pipe (s, filter_cmd)
+def is_derived (object, base):
+ def recurse (cl, baseclass):
+ if cl == baseclass:
+ return True
+ for b in cl.__bases__:
+ if recurse (b, baseclass):
+ return True
+ return False
+
+ cl = object.__class__
+ return recurse (cl, base)
+
+
def process_snippets (cmd, snippets):
names = filter (lambda x: x, map (Lilypond_snippet.basename, snippets))
if names:
break
if filter_cmd:
- pass # todo
+ output_file.writelines ([c.filter_text () for c in chunks])
+
+
elif process_cmd:
- outdated = filter (lambda x: x.__class__ == Lilypond_snippet \
+ outdated = filter (lambda x: is_derived (x, Lilypond_snippet) \
and x.is_outdated (), chunks)
ly.progress (_ ("Writing snippets..."))
map (Lilypond_snippet.write_ly, outdated)
do_file (name)
map (process_include,
- filter (lambda x: x.__class__ == Include_snippet, chunks))
+ filter (lambda x: is_derived (x, Include_snippet), chunks))
def do_options ():
global format, output_name