]> git.donarmstrong.com Git - lilypond.git/commitdiff
(Snippet.output_print_filename): new
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 6 Feb 2004 19:19:39 +0000 (19:19 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 6 Feb 2004 19:19:39 +0000 (19:19 +0000)
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.

ChangeLog
make/ly-rules.make
scripts/lilypond-book.py

index 02dab38493b5e9615b2d6481bb01c245740eccb3..6d8affe3e82a01a67db207708322aa0d12f18470 100644 (file)
--- 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.
        
index 15069294f02be6a4505a947a6a9a0af9151870ec..8eef1448100cfcc859a5ff307c7a2efbc71a852e 100644 (file)
@@ -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 $@
 
index 61943d67d45400d984515767dd2b1d978bc32751..e7db3fdac9269e0ca19804794aac090ac2070a5d 100644 (file)
@@ -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<regex%s>%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',