Skip to content

Commit 930e145

Browse files
committed
add an easy way to count parse errors in parser.py; use that in parse.py; strip trailing spaces in parse.py
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40382
1 parent 0da2aa1 commit 930e145

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

parse.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ def parse():
5151
else:
5252
document = p.parse(f)
5353
print convertTreeDump(document.printTree())
54+
print "\nParse errors:", len(p.errors)
5455

5556
def getOptParser():
5657
parser = OptionParser(usage=__doc__)
57-
58+
5859
parser.add_option("-p", "--profile", action="store_true", default=False,
5960
dest="profile", help="Use the hotdhot profiler to "
6061
"produce a detailed log of the run")
61-
62+
6263
parser.add_option("-t", "--time",
63-
action="store_true", default=False, dest="time",
64+
action="store_true", default=False, dest="time",
6465
help="Time the run using time.time (may not be accurate on all platforms, especially for short runs)")
65-
66+
6667
return parser
6768

6869
if __name__ == "__main__":

src/parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class HTMLParser(object):
3535
def __init__(self, strict = False, tree=DOMlite.TreeBuilder):
3636
# Raise an exception on the first error encountered
3737
self.strict = strict
38+
self.errors = []
3839

3940
self.tree = tree()
4041

@@ -87,7 +88,7 @@ def parse(self, stream, innerHTML=False):
8788
elif type == "EndTag":
8889
method(token["name"])
8990
elif type == "ParseError":
90-
self.parseError()
91+
self.parseError(token["data"])
9192
else:
9293
self.atheistParseError()
9394

@@ -96,7 +97,8 @@ def parse(self, stream, innerHTML=False):
9697

9798
return self.tree.getDocument()
9899

99-
def parseError(self):
100+
def parseError(self, data=None):
101+
self.errors.append(data)
100102
if self.strict:
101103
raise ParseError
102104

0 commit comments

Comments
 (0)