summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShevek <[email protected]>2011-01-19 20:14:58 +0000
committerShevek <[email protected]>2011-01-19 20:14:58 +0000
commit3efdabfcc5c9b8253b1ecadcc987950abf6f1177 (patch)
treec7f5d68f492af447d0a2419c45c51f5d6580c87d /src
parentaae974e849d5e4026f9d5a0b2ff37c6f604c94d9 (diff)
Fix some lexer bugs
Diffstat (limited to 'src')
-rw-r--r--src/java/org/anarres/cpp/LexerSource.java16
-rw-r--r--src/tests/org/anarres/cpp/LexerSourceTestCase.java16
2 files changed, 26 insertions, 6 deletions
diff --git a/src/java/org/anarres/cpp/LexerSource.java b/src/java/org/anarres/cpp/LexerSource.java
index 90869bc..c38ff6a 100644
--- a/src/java/org/anarres/cpp/LexerSource.java
+++ b/src/java/org/anarres/cpp/LexerSource.java
@@ -318,14 +318,18 @@ public class LexerSource extends Source {
return val;
case 'x':
+ text.append((char)d);
len = 0;
val = 0;
- do {
+ while (len++ < 2) {
+ d = read();
+ if (Character.digit(d, 16) == -1) {
+ unread(d);
+ break;
+ }
val = (val << 4) + Character.digit(d, 16);
text.append((char)d);
- d = read();
- } while (++len < 2 && Character.digit(d, 16) != -1);
- unread(d);
+ }
return val;
/* Exclude two cases from the warning. */
@@ -444,14 +448,14 @@ public class LexerSource extends Source {
}
else if (d == 'L' || d == 'l') {
if ((bits & 4) != 0)
- /* XXX warn */ ;
+ warning("Conflicting numeric suffices: I and L.");
bits |= 2;
text.append((char)d);
d = read();
}
else if (d == 'I' || d == 'i') {
if ((bits & 2) != 0)
- /* XXX warn */ ;
+ warning("Conflicting numeric suffices: L and I.");
bits |= 4;
text.append((char)d);
d = read();
diff --git a/src/tests/org/anarres/cpp/LexerSourceTestCase.java b/src/tests/org/anarres/cpp/LexerSourceTestCase.java
index 7fa788c..828ee9c 100644
--- a/src/tests/org/anarres/cpp/LexerSourceTestCase.java
+++ b/src/tests/org/anarres/cpp/LexerSourceTestCase.java
@@ -60,6 +60,22 @@ public class LexerSourceTestCase extends BaseTestCase implements Test {
XOR_EQ, WHITESPACE,
IDENTIFIER);
+ testLexerSource("/**/", CCOMMENT);
+ testLexerSource("/** ** **/", CCOMMENT);
+ testLexerSource("//* ** **/", CPPCOMMENT);
+ testLexerSource("'\\r' '\\xf' '\\xff' 'x' 'aa' ''",
+ CHARACTER, WHITESPACE,
+ CHARACTER, WHITESPACE,
+ CHARACTER, WHITESPACE,
+ CHARACTER, WHITESPACE,
+ INVALID, WHITESPACE,
+ INVALID);
+
+ testLexerSource("1i1I1l1L1ui1ul",
+ INTEGER, INTEGER,
+ INTEGER, INTEGER,
+ INTEGER, INTEGER);
+
}
}