From: Han-Wen Nienhuys Date: Fri, 6 Feb 2004 19:19:39 +0000 (+0000) Subject: (Snippet.output_print_filename): new X-Git-Tag: release/2.1.23~75 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=398cb0d1b17ff211a203de2d4bb4359c94358c39;p=lilypond.git (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. (find_toplevel_snippets): reinstate old version, without global variables. --- diff --git a/ChangeLog b/ChangeLog index 02dab38493..6d8affe3e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ index. (main): really support -I option. (find_toplevel_snippets): new code. + (find_toplevel_snippets): reinstate old version, without global variables. * tex/texinfo.tex: really add file. diff --git a/make/ly-rules.make b/make/ly-rules.make index 15069294f0..8eef144810 100644 --- a/make/ly-rules.make +++ b/make/ly-rules.make @@ -10,7 +10,7 @@ $(outdir)/%.latex: %.doc # it is not, for --srcdir builds $(outdir)/%.texi: %.tely if [ -f $@ ]; then chmod a+w $@; fi - $(PYTHON) $(LILYPOND_BOOK) $(LILYPOND_BOOK_INCLUDES) --process='$(LILYPOND) $(LILYPOND_BOOK_INCLUDES)' --output=$(outdir) --format=$(LILYPOND_BOOK_FORMAT) --verbose $(LILYPOND_BOOK_FLAGS) $< + time $(PYTHON) $(LILYPOND_BOOK) $(LILYPOND_BOOK_INCLUDES) --process='$(LILYPOND) $(LILYPOND_BOOK_INCLUDES)' --output=$(outdir) --format=$(LILYPOND_BOOK_FORMAT) --verbose $(LILYPOND_BOOK_FLAGS) $< chmod -w $@ $(outdir)/%.texi: $(outdir)/%.tely @@ -27,7 +27,7 @@ $(outdir)/%.texi: $(outdir)/%.tely # for plain info doco: don't run lily $(outdir)/%.nexi: %.tely if [ -f $@ ]; then chmod a+w $@; fi - $(PYTHON) $(LILYPOND_BOOK) $(LILYPOND_BOOK_INCLUDES) --output=$(outdir) --format=$(LILYPOND_BOOK_FORMAT) --verbose $(LILYPOND_BOOK_FLAGS) --process='true' $< + time $(PYTHON) $(LILYPOND_BOOK) $(LILYPOND_BOOK_INCLUDES) --output=$(outdir) --format=$(LILYPOND_BOOK_FORMAT) --verbose $(LILYPOND_BOOK_FLAGS) --process='true' $< mv $(outdir)/$*.texinfo $@ 2>/dev/null || mv $(outdir)/$*.texi $@ chmod -w $@ diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 61943d67d4..e7db3fdac9 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -508,48 +508,57 @@ class Snippet: pass # todo +def find_toplevel_snippets (infile, outfile, types): + s = infile.read () + res = {} + for i in types: + res[i] = ly.re.compile (snippet_res[format][i]) + + snippets = [] + index = 0 + found = dict ([(t, None) for t in types] ) + + # + # We want to search for multiple regexes, + # without searching the string multiple times for one regex. + # + # Hence, we use earlier results to limit the string portion + # where we search. We're hosed if the first type only occurs + # at the end of the string, since it will then use quadratic + # time. + # + + while 1: + first = None + endex = 1 << 30 + for type in types: + if not found[type] or found[type].start (0) < index: + found[type] = None + m = res[type].search (s[index:endex]) + if m: + found[type] = Snippet (type, m) + + if found[type] \ + and (first == None \ + or found[type].start (0) < found[first].start (0)): + + first = type + endex = found[first].start (0) + + if not first: + break + + snippets.append (found[first]) -def simple_find_toplevel_snippets (str, types): - "return: (new string, snippets)" - snippets = [] - for t in types: - regex = re.compile (snippet_res[format][t]) + outfile.write (s[index:index + found[first].start (0)]) + outfile.write (found[first].replacement_text ()) + + index += found[first].end (0) - # ugh, this can be done nicer in python 2.x - def notice_snippet (match, snippets = snippets, - t = t, str = str): - s = Snippet (t, str, match) - snippets.append (s) + return snippets - - return s.replacement_text (format) - 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): @@ -670,7 +679,6 @@ def do_file (input_filename): ly.progress ('\n') ly.progress (_ ("Dissecting...")) - #snippets = find_toplevel_snippets (source, snippet_res[format].keys ()) snippet_types = ( 'lilypond_block', 'verb',