summaryrefslogtreecommitdiff
path: root/engine/SCons/Scanner/LaTeX.py
diff options
context:
space:
mode:
authorLuca Falavigna <dktrkranz@debian.org>2011-02-10 23:06:43 +0100
committerLuca Falavigna <dktrkranz@debian.org>2011-02-10 23:06:43 +0100
commit8974746208953bcf6ed03be30329c03445dc0706 (patch)
treec3215c5a3bef68871b5fc1a1cea8de708a236d41 /engine/SCons/Scanner/LaTeX.py
parentd474b34e869c73f7dfae5300e81e1721f005ac9b (diff)
parent8344b122eb4ee8818cde6ef2bb07726a672a2d23 (diff)
Merge commit 'upstream/2.0.1'
Diffstat (limited to 'engine/SCons/Scanner/LaTeX.py')
-rw-r--r--engine/SCons/Scanner/LaTeX.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/engine/SCons/Scanner/LaTeX.py b/engine/SCons/Scanner/LaTeX.py
index 77be34c..ae542cf 100644
--- a/engine/SCons/Scanner/LaTeX.py
+++ b/engine/SCons/Scanner/LaTeX.py
@@ -27,7 +27,7 @@ This module implements the dependency scanner for LaTeX code.
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Scanner/LaTeX.py 5023 2010/06/14 22:05:46 scons"
+__revision__ = "src/engine/SCons/Scanner/LaTeX.py 5134 2010/08/16 23:02:40 bdeegan"
import os.path
import re
@@ -168,8 +168,11 @@ class LaTeX(SCons.Scanner.Base):
# Without the \n, the ^ could match the beginning of a *previous*
# line followed by one or more newline characters (i.e. blank
# lines), interfering with a match on the next line.
- regex = r'^[^%\n]*\\(include|includegraphics(?:\[[^\]]+\])?|lstinputlisting(?:\[[^\]]+\])?|input|bibliography|usepackage){([^}]*)}'
+ # add option for whitespace before the '[options]' or the '{filename}'
+ regex = r'^[^%\n]*\\(include|includegraphics(?:\s*\[[^\]]+\])?|lstinputlisting(?:\[[^\]]+\])?|input|bibliography|usepackage)\s*{([^}]*)}'
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):
@@ -274,6 +277,23 @@ class LaTeX(SCons.Scanner.Base):
return i, include
return i, include
+ def canonical_text(self, text):
+ """Standardize an input TeX-file contents.
+
+ Currently:
+ * removes comments, unwrapping comment-wrapped lines.
+ """
+ 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
@@ -281,11 +301,13 @@ class LaTeX(SCons.Scanner.Base):
# Cache the includes list in node so we only scan it once:
# path_dict = dict(list(path))
- noopt_cre = re.compile('\[.*$')
+ # add option for whitespace (\s) before the '['
+ noopt_cre = re.compile('\s*\[.*$')
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