Added fix for text/TEX/multi-line_include_options.py.
authorW. Trevor King <wking@drexel.edu>
Fri, 23 Apr 2010 00:29:06 +0000 (20:29 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 23 Apr 2010 00:29:06 +0000 (20:29 -0400)
By removing comments from the source file, we produce a "canonical"
form of the input TeX that LaTeX.cre, the input regexp, can handle.

src/engine/SCons/Scanner/LaTeX.py

index 622f2a3c53ce5a11dc769571fdcbc3ccf67f4368..f43b19cf4360a86a10139d74e7a7a87b20ba0b1a 100644 (file)
@@ -175,6 +175,8 @@ class LaTeX(SCons.Scanner.Base):
         # lines), interfering with a match on the next line.
         regex = r'^[^%\n]*\\(include|includegraphics(?:\[[^\]]+\])?|lstinputlisting(?:\[[^\]]+\])?|input|bibliography|usepackage){([^}]*)}'
         self.cre = re.compile(regex, re.M)
+        self.comment_re = re.compile(r'^([^%\n]*)(.*)$', re.M)
+
         self.graphics_extensions = graphics_extensions
 
         def _scan(node, env, path=(), self=self):
@@ -278,6 +280,18 @@ class LaTeX(SCons.Scanner.Base):
                 return i, include
         return i, include
 
+    def canonical_text(self, text):
+        out = []
+        line_continues_a_comment = False
+        for line in text.splitlines():
+            line,comment = self.comment_re.findall(line)[0]
+            if line_continues_a_comment == True:
+                out[-1] = out[-1] + ' ' + line.lstrip()
+            else:
+                out.append(line)
+            line_continues_a_comment = len(comment) > 0
+        return '\n'.join(out).rstrip()+'\n'
+
     def scan(self, node):
         # Modify the default scan function to allow for the regular
         # expression to return a comma separated list of file names
@@ -289,7 +303,8 @@ class LaTeX(SCons.Scanner.Base):
         if node.includes != None:
             includes = node.includes
         else:
-            includes = self.cre.findall(node.get_text_contents())
+            text = self.canonical_text(node.get_text_contents())
+            includes = self.cre.findall(text)
             # 1. Split comma-separated lines, e.g.
             #      ('bibliography', 'phys,comp')
             #    should become two entries