]> git.lizzy.rs Git - rust.git/commitdiff
tests: Tidy and allows multi-line htmldocck commands.
authorKang Seonghoon <public+git@mearie.org>
Sat, 17 Jan 2015 18:23:52 +0000 (03:23 +0900)
committerKang Seonghoon <public+git@mearie.org>
Sat, 17 Jan 2015 18:23:52 +0000 (03:23 +0900)
src/etc/htmldocck.py
src/test/run-make/rustdoc-where/foo.rs

index 9693129db3b6130fd90b50fea765d2b302f99685..2573421758972fa73c6723cfc37d9536996f008e 100644 (file)
@@ -148,11 +148,43 @@ class CustomHTMLParser(HTMLParser):
 
 Command = namedtuple('Command', 'negated cmd args lineno')
 
-LINE_PATTERN = re.compile(r'(?<=(?<!\S)@)(?P<negated>!?)(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)(?P<args>.*)$')
+# returns a generator out of the file object, which
+# - removes `\\` then `\n` then a shared prefix with the previous line then optional whitespace;
+# - keeps a line number (starting from 0) of the first line being concatenated.
+def concat_multi_lines(f):
+    lastline = None # set to the last line when the last line has a backslash
+    firstlineno = None
+    catenated = ''
+    for lineno, line in enumerate(f):
+        line = line.rstrip('\r\n')
+
+        # strip the common prefix from the current line if needed
+        if lastline is not None:
+            maxprefix = 0
+            for i in xrange(min(len(line), len(lastline))):
+                if line[i] != lastline[i]: break
+                maxprefix += 1
+            line = line[maxprefix:].lstrip()
+
+        firstlineno = firstlineno or lineno
+        if line.endswith('\\'):
+            lastline = line[:-1]
+            catenated += line[:-1]
+        else:
+            yield firstlineno, catenated + line
+            lastline = None
+            firstlineno = None
+            catenated = ''
+
+LINE_PATTERN = re.compile(r'''
+    (?<=(?<!\S)@)(?P<negated>!?)
+    (?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
+    (?P<args>.*)$
+''', re.X)
 def get_commands(template):
     with open(template, 'rUb') as f:
-        for lineno, line in enumerate(f):
-            m = LINE_PATTERN.search(line.rstrip('\r\n'))
+        for lineno, line in concat_multi_lines(f):
+            m = LINE_PATTERN.search(line)
             if not m: continue
 
             negated = (m.group('negated') == '!')
index 286d101f164742775d45192872d68bc32ceb1e22..9f38ff138051c81a39da2a24e25158e087d196e4 100644 (file)
@@ -24,11 +24,15 @@ pub fn delta() {}
 }
 
 pub struct Echo<E>;
-// @matches foo/struct.Echo.html '//*[@class="impl"]//code' "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait" 
-// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
+// @matches foo/struct.Echo.html '//*[@class="impl"]//code' \
+//          "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
+// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
+//          "impl.*MyTrait.*for.*Echo.*where.*E:.*MyTrait"
 impl<E> MyTrait for Echo<E> where E: MyTrait {}
 
 pub enum Foxtrot<F> {}
-// @matches foo/enum.Foxtrot.html '//*[@class="impl"]//code' "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait" 
-// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
+// @matches foo/enum.Foxtrot.html '//*[@class="impl"]//code' \
+//          "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
+// @matches foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
+//          "impl.*MyTrait.*for.*Foxtrot.*where.*F:.*MyTrait"
 impl<F> MyTrait for Foxtrot<F> where F: MyTrait {}