Revision: 3714
Author: mikesamuel
Date: Wed Sep 9 13:58:42 2009
Log: Improves the error message produced when EOF is unexpectedly
encountered
http://codereview.appspot.com/116061
[email protected]
http://code.google.com/p/google-caja/source/detail?r=3714
Modified:
/trunk/src/com/google/caja/lexer/TokenQueue.java
=======================================
--- /trunk/src/com/google/caja/lexer/TokenQueue.java Mon Feb 23 20:15:55
2009
+++ /trunk/src/com/google/caja/lexer/TokenQueue.java Wed Sep 9 13:58:42
2009
@@ -234,7 +234,20 @@
* raises a ParseException otherwise.
*/
public void expectToken(String text) throws ParseException {
- Token<T> t = peek();
+ Token<T> t;
+ try {
+ t = peek();
+ } catch (ParseException ex) {
+ if (prev != null
+ && ex.getCajaMessage().getMessageType() ==
MessageType.END_OF_FILE) {
+ throw new ParseException(
+ new Message(MessageType.EXPECTED_TOKEN,
+ FilePosition.endOf(prev.t.pos),
+ MessagePart.Factory.valueOf(text),
+ MessagePart.Factory.valueOf("EOF")));
+ }
+ throw ex;
+ }
if (t.text.equals(text)) {
advance();
return;