Skip to content

Commit 5b0e304

Browse files
committed
add some more parse error messages and make parser.py use gettext as well
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40395
1 parent 001f783 commit 5b0e304

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

src/parser.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# Import from the sets module for python 2.3
1818
from sets import Set as set
1919
from sets import ImmutableSet as frozenset
20+
import gettext
21+
_ = gettext.gettext
2022

2123
import tokenizer
2224

@@ -214,7 +216,7 @@ class InitialPhase(Phase):
214216
# "quirks mode". It is expected that a future version of HTML5 will defin
215217
# this.
216218
def processEOF(self):
217-
self.parser.parseError("No DOCTYPE seen.")
219+
self.parser.parseError(_("No DOCTYPE seen."))
218220
self.parser.phase = self.parser.phases["rootElement"]
219221
self.parser.phase.processEOF()
220222

@@ -223,25 +225,25 @@ def processComment(self, data):
223225

224226
def processDoctype(self, name, error):
225227
if error:
226-
self.parser.parseError("DOCTYPE is in error.")
228+
self.parser.parseError(_("DOCTYPE is in error."))
227229
self.tree.insertDoctype(name)
228230
self.parser.phase = self.parser.phases["rootElement"]
229231

230232
def processSpaceCharacters(self, data):
231233
self.tree.insertText(data, self.tree.document)
232234

233235
def processCharacters(self, data):
234-
self.parser.parseError("No DOCTYPE seen.")
236+
self.parser.parseError(_("No DOCTYPE seen."))
235237
self.parser.phase = self.parser.phases["rootElement"]
236238
self.parser.phase.processCharacters(data)
237239

238240
def processStartTag(self, name, attributes):
239-
self.parser.parseError("No DOCTYPE seen.")
241+
self.parser.parseError(_("No DOCTYPE seen."))
240242
self.parser.phase = self.parser.phases["rootElement"]
241243
self.parser.phase.processStartTag(name, attributes)
242244

243245
def processEndTag(self, name):
244-
self.parser.parseError("No DOCTYPE seen.")
246+
self.parser.parseError(_("No DOCTYPE seen."))
245247
self.parser.phase = self.parser.phases["rootElement"]
246248
self.parser.phase.processEndTag(name)
247249

@@ -315,8 +317,8 @@ def endTagHtml(self, name):
315317
self.parser.phase.processEndTag(name)
316318

317319
def endTagOther(self, name):
318-
self.parser.parseError("Unexpected end tag (" + name +\
319-
") after the root element.")
320+
self.parser.parseError(_("Unexpected end tag (" + name +\
321+
") after the root element."))
320322

321323
class InHeadPhase(Phase):
322324
def __init__(self, parser, tree):
@@ -409,10 +411,11 @@ def endTagTitleStyleScript(self, name):
409411
if self.tree.openElements[-1].name == name:
410412
self.tree.openElements.pop()
411413
else:
412-
self.parser.parseError()
414+
self.parser.parseError(_("Unexpected end tag " + name +\
415+
". Ignored."))
413416

414417
def endTagOther(self, name):
415-
self.parser.parseError()
418+
self.parser.parseError(_("Unexpected end tag " + name + ". Ignored."))
416419

417420
def anythingElse(self):
418421
if self.tree.openElements[-1].name == "head":
@@ -551,11 +554,12 @@ def startTagScript(self, name, attributes):
551554
self.parser.phases["inHead"].processStartTag(name, attributes)
552555

553556
def startTagFromHead(self, name, attributes):
554-
self.parser.parseError()
557+
self.parser.parseError(_("Unexpected start tag " + name +\
558+
" that belongs in the head. Moved."))
555559
self.parser.phases["inHead"].processStartTag(name, attributes)
556560

557561
def startTagBody(self, name, attributes):
558-
self.parser.parseError()
562+
self.parser.parseError(_("Unexpected start tag body"))
559563
if len(self.tree.openElements) == 1 \
560564
or self.tree.openElements[1].name != "body":
561565
assert self.parser.innerHTML
@@ -634,7 +638,8 @@ def startTagFormatting(self, name, attributes):
634638

635639
def startTagButton(self, name, attributes):
636640
if self.tree.elementInScope("button"):
637-
self.parser.parseError()
641+
self.parser.parseError(_("Unexpected start tag button. Implying"
642+
"button end tag."))
638643
self.processEndTag("button")
639644
self.parser.phase.processStartTag(name, attributes)
640645
else:
@@ -671,7 +676,8 @@ def startTagHr(self, name, attributes):
671676

672677
def startTagImage(self, name, attributes):
673678
# No really...
674-
self.parser.parseError()
679+
self.parser.parseError(_("Unexpected start tag image. Use img "
680+
"instead"))
675681
self.processStartTag("img", attributes)
676682

677683
def startTagInput(self, name, attributes):
@@ -683,7 +689,7 @@ def startTagInput(self, name, attributes):
683689
self.tree.openElements.pop()
684690

685691
def startTagIsIndex(self, name, attributes):
686-
self.parser.parseError()
692+
self.parser.parseError("Unexpected start tag isindex. Don't use it!")
687693
if self.tree.formPointer:
688694
return
689695
self.processStartTag("form", {})
@@ -743,6 +749,9 @@ def endTagP(self, name):
743749
self.tree.openElements.pop()
744750

745751
def endTagBody(self, name):
752+
# XXX Need to take open <p> tags into account here. We shouldn't imply
753+
# </p> but we should not throw a parse error either. Specification is
754+
# likely to be updated.
746755
if self.tree.openElements[1].name != "body":
747756
# innerHTML case
748757
self.parser.parseError()
@@ -941,7 +950,8 @@ def endTagCdataTextAreaXmp(self, name):
941950
if self.tree.openElements[-1].name == name:
942951
self.tree.openElements.pop()
943952
else:
944-
self.parser.parseError()
953+
self.parser.parseError(_("Unexpected end tag " + name +\
954+
". Ignored."))
945955

946956
def endTagNew(self, name):
947957
"""New HTML5 elements, "event-source", "section", "nav",
@@ -956,7 +966,8 @@ def endTagOther(self, name):
956966
if node.name == name:
957967
self.tree.generateImpliedEndTags()
958968
if self.tree.openElements[-1].name != name:
959-
self.parser.parseError()
969+
self.parser.parseError(_("Unexpected end tag " + name +\
970+
"."))
960971
while self.tree.openElements.pop() != node:
961972
pass
962973
break
@@ -1553,8 +1564,8 @@ def __init__(self, parser, tree):
15531564
self.endTagHandler.default = self.endTagOther
15541565

15551566
def processCharacters(self, data):
1556-
self.parser.parseError("Unepxected characters in the frameset phase. "
1557-
"Characters ignored.")
1567+
self.parser.parseError(_("Unepxected characters in the frameset phase. "
1568+
"Characters ignored."))
15581569

15591570
def startTagFrameset(self, name, attributes):
15601571
self.tree.insertElement(name, attributes)
@@ -1567,14 +1578,14 @@ def startTagNoframes(self, name, attributes):
15671578
self.parser.phases["inBody"].processStartTag(name, attributes)
15681579

15691580
def startTagOther(self, name, attributes):
1570-
self.parser.parseError("Unexpected start tag token (" + name +\
1571-
") in the frameset phase.")
1581+
self.parser.parseError(_("Unexpected start tag token (" + name +\
1582+
") in the frameset phase."))
15721583

15731584
def endTagFrameset(self, name):
15741585
if self.tree.openElements[-1].name == "html":
15751586
# innerHTML case
1576-
self.parser.parseError("Unexpected end tag token (frameset) in the"
1577-
"frameset phase (innerHTML)")
1587+
self.parser.parseError(_("Unexpected end tag token (frameset) in the"
1588+
"frameset phase (innerHTML)"))
15781589
else:
15791590
self.tree.openElements.pop()
15801591
if not self.parser.innerHTML and\
@@ -1587,8 +1598,8 @@ def endTagNoframes(self, name):
15871598
self.parser.phases["inBody"].processEndTag(name)
15881599

15891600
def endTagOther(self, name):
1590-
self.parser.parseError("Unexpected end tag token (" + name +
1591-
") in the frameset phase.")
1601+
self.parser.parseError(_("Unexpected end tag token (" + name +
1602+
") in the frameset phase."))
15921603

15931604

15941605
class AfterFramesetPhase(Phase):

0 commit comments

Comments
 (0)