diff options
author | Shevek <[email protected]> | 2008-06-13 21:53:52 +0000 |
---|---|---|
committer | Shevek <[email protected]> | 2008-06-13 21:53:52 +0000 |
commit | 282706bd6ddf2d2b6279683ab65c5c5b4df92046 (patch) | |
tree | 34144b05e5d78b85d5de69a0b99fd57c9a4215ae /src/java/org/anarres/cpp/LexerSource.java | |
parent | 93808fc91f990dbc17a2bc2b350552d9dde89692 (diff) |
handle errors better, using features
Diffstat (limited to 'src/java/org/anarres/cpp/LexerSource.java')
-rw-r--r-- | src/java/org/anarres/cpp/LexerSource.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/java/org/anarres/cpp/LexerSource.java b/src/java/org/anarres/cpp/LexerSource.java index 44c6224..0eea1c3 100644 --- a/src/java/org/anarres/cpp/LexerSource.java +++ b/src/java/org/anarres/cpp/LexerSource.java @@ -235,6 +235,19 @@ public class LexerSource extends Source { } } + /* Consumes the rest of the current line into an invalid. */ + private Token invalid(StringBuilder text, String reason) + throws IOException, + LexerException { + int d = read(); + while (!isLineSeparator(d)) { + text.append((char)d); + d = read(); + } + unread(d); + return new Token(INVALID, text.toString(), reason); + } + private Token ccomment() throws IOException, LexerException { @@ -325,19 +338,17 @@ public class LexerSource extends Source { } else if (isLineSeparator(d)) { unread(d); - // error("Unterminated character literal"); return new Token(INVALID, text.toString(), "Unterminated character literal"); } else if (d == '\'') { text.append('\''); - // error("Empty character literal"); return new Token(INVALID, text.toString(), "Empty character literal"); } else if (!Character.isDefined(d)) { text.append('?'); - error("Illegal unicode character literal"); + return invalid(text, "Illegal unicode character literal"); } else { text.append((char)d); @@ -348,17 +359,17 @@ public class LexerSource extends Source { // error("Illegal character constant"); /* We consume up to the next ' or the rest of the line. */ for (;;) { - if (e == '\'') - break; if (isLineSeparator(e)) { unread(e); break; } text.append((char)e); + if (e == '\'') + break; e = read(); } return new Token(INVALID, text.toString(), - "Illegal character constant"); + "Illegal character constant " + text); } text.append('\''); /* XXX It this a bad cast? */ |