From e14c1e381b8651b724c78e5663ad5365fe9cc1f0 Mon Sep 17 00:00:00 2001 From: hanwen Date: Fri, 6 Feb 2004 13:20:01 +0000 Subject: [PATCH] (Snippet.output_print_filename): new file, process printfilename option. (Snippet.__init__): rewrite: do not use global variables h or index. (main): really support -I option. (find_toplevel_snippets): new code. --- ChangeLog | 1 + input/template/GNUmakefile | 1 + scm/music-functions.scm | 3 ++- scripts/lilypond-book.py | 49 ++++++++++++++++++++++++++++---------- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8268441704..02dab38493 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ (Snippet.__init__): rewrite: do not use global variables h or index. (main): really support -I option. + (find_toplevel_snippets): new code. * tex/texinfo.tex: really add file. diff --git a/input/template/GNUmakefile b/input/template/GNUmakefile index 84f81ed45f..5e769a1264 100644 --- a/input/template/GNUmakefile +++ b/input/template/GNUmakefile @@ -1,6 +1,7 @@ depth = ../.. STEPMAKE_TEMPLATES=documentation texinfo tex +LILYPOND_BOOK_FLAGS = --process="lilypond-bin -I $(srcdir)/input/regression -e '(ly:set-option (quote internal-type-checking) \#t)'" LOCALSTEPMAKE_TEMPLATES=lilypond ly lysdoc EXTRA_DIST_FILES=README diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 9dc18d1621..91c6bbaaaf 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -501,7 +501,8 @@ Rest can contain a list of beat groupings ;;; splitting chords into voices. - +;; todo: spec \context Staff for <<\\>> +;; (define (voicify-list lst number) "Make a list of Musics. diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 678894935d..61943d67d4 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -237,7 +237,8 @@ border="0" src="%(base)s.png" alt="[picture of music]">''', BEFORE: '', AFTER: '', VERBATIM: r'''@example -%(verb)s@end example''', +%(verb)s@end example +''', }, @@ -365,9 +366,8 @@ def split_options (option_string): class Snippet: - def __init__ (self, type, source, match): + def __init__ (self, type, match): self.type = type - self.source = source self.match = match self.hash = 0 self.options = [] @@ -426,7 +426,11 @@ class Snippet: func = Snippet.__dict__ ['output_' + format] return func (self) elif self.type == 'include': - return '' + s = self.match.group (0) + f = self.substring ('filename') + nf = os.path.splitext (f)[0] + format2ext[format] + + return re.sub (f, nf, s) else: return self.match.group (0) @@ -505,7 +509,7 @@ class Snippet: -def find_toplevel_snippets (str, types): +def simple_find_toplevel_snippets (str, types): "return: (new string, snippets)" snippets = [] for t in types: @@ -523,6 +527,29 @@ def find_toplevel_snippets (str, types): str = regex.sub (notice_snippet, str) return (str, snippets) +def find_toplevel_snippets (infile, outfile, types): + res = ['(?P%s)' % (t, + + re.sub (r"\(\?P<[^>]+>", "(", snippet_res[format][t])) + for t in types] + + big_re = re.compile (string.join (res, '|')) + str = infile.read () + i = big_re.finditer(str) + + snips= [] + last_end = 0 + for match in i: + outfile.write (str[last_end:match.start (0)]) + last_end = match.end (0) + for t in types: + m =re.match (snippet_res[format][t], match.group(0)) + if m: + sn = Snippet (t, m) + snips.append (sn) + outfile.write (sn.replacement_text (format)) + break + return snips def filter_pipe (input, cmd): @@ -640,7 +667,6 @@ def do_file (input_filename): else: ih = open (input_filename) - source = ih.read () ly.progress ('\n') ly.progress (_ ("Dissecting...")) @@ -655,9 +681,6 @@ def do_file (input_filename): 'include', 'lilypond', ) - (source, snippets) = find_toplevel_snippets (source, snippet_types) - ly.progress ('\n') - output_file = None if output_name == '-' or not output_name: output_file = sys.stdout @@ -677,6 +700,9 @@ def do_file (input_filename): os.chdir (output_name) + snippets = find_toplevel_snippets (ih, output_file, snippet_types) + ly.progress ('\n') + global default_ly_options textwidth = 0 @@ -703,8 +729,6 @@ def do_file (input_filename): ly.progress (_ ("Compiling %s...") % output_filename) ly.progress ('\n') - output_file.write (source) - def process_include (snippet): os.chdir (original_dir) name = snippet.substring ('filename') @@ -770,7 +794,8 @@ def main (): files = do_options () global process_cmd if process_cmd: - process_cmd += string.join ([(' -I %s' % p) for p in include_path]) + process_cmd += string.join ([(' -I %s' % p) + for p in include_path]) ly.identify (sys.stderr) ly.setup_environment () -- 2.39.5