diff options
author | Shevek <[email protected]> | 2012-09-04 01:01:06 -0700 |
---|---|---|
committer | Shevek <[email protected]> | 2012-09-04 01:01:06 -0700 |
commit | 83c866c1ecdbb701a48f57d7eb104a0d9d156bc6 (patch) | |
tree | 56e5e1b45345493f4f9f70a57d94bc1fe83f9aff | |
parent | 943775515e684e1845abbdd6be52678028272399 (diff) |
Support single-quoted strings properly, as a variant of 'character'.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/java/org/anarres/cpp/LexerSource.java | 19 | ||||
-rw-r--r-- | src/java/org/anarres/cpp/Token.java | 2 |
3 files changed, 19 insertions, 3 deletions
@@ -1 +1,2 @@ build +.*.swp diff --git a/src/java/org/anarres/cpp/LexerSource.java b/src/java/org/anarres/cpp/LexerSource.java index b696c9c..5f3bfc7 100644 --- a/src/java/org/anarres/cpp/LexerSource.java +++ b/src/java/org/anarres/cpp/LexerSource.java @@ -431,8 +431,23 @@ public class LexerSource extends Source { } } text.append(close); - return new Token(close == '>' ? HEADER : STRING, + switch (close) { + case '"': + return new Token(STRING, + text.toString(), buf.toString()); + case '>': + return new Token(HEADER, + text.toString(), buf.toString()); + case '\'': + if (buf.length() == 1) + return new Token(CHARACTER, text.toString(), buf.toString()); + return new Token(SQSTRING, + text.toString(), buf.toString()); + default: + throw new IllegalStateException( + "Unknown closing character " + (char)close); + } } private Token _number_suffix(StringBuilder text, NumericValue value, int d) @@ -819,7 +834,7 @@ public class LexerSource extends Source { break; case '\'': - tok = character(); + tok = string('\'', '\''); break; case '"': diff --git a/src/java/org/anarres/cpp/Token.java b/src/java/org/anarres/cpp/Token.java index 9112c25..a2cac39 100644 --- a/src/java/org/anarres/cpp/Token.java +++ b/src/java/org/anarres/cpp/Token.java @@ -151,7 +151,7 @@ public final class Token { } #set ($i = 257) -#set ($tokens = [ "AND_EQ", "ARROW", "CHARACTER", "CCOMMENT", "CPPCOMMENT", "DEC", "DIV_EQ", "ELLIPSIS", "EOF", "EQ", "GE", "HASH", "HEADER", "IDENTIFIER", "INC", "NUMBER", "LAND", "LAND_EQ", "LE", "LITERAL", "LOR", "LOR_EQ", "LSH", "LSH_EQ", "MOD_EQ", "MULT_EQ", "NE", "NL", "OR_EQ", "PASTE", "PLUS_EQ", "RANGE", "RSH", "RSH_EQ", "STRING", "SUB_EQ", "WHITESPACE", "XOR_EQ", "M_ARG", "M_PASTE", "M_STRING", "P_LINE", "INVALID" ]) +#set ($tokens = [ "AND_EQ", "ARROW", "CHARACTER", "CCOMMENT", "CPPCOMMENT", "DEC", "DIV_EQ", "ELLIPSIS", "EOF", "EQ", "GE", "HASH", "HEADER", "IDENTIFIER", "INC", "NUMBER", "LAND", "LAND_EQ", "LE", "LITERAL", "LOR", "LOR_EQ", "LSH", "LSH_EQ", "MOD_EQ", "MULT_EQ", "NE", "NL", "OR_EQ", "PASTE", "PLUS_EQ", "RANGE", "RSH", "RSH_EQ", "SQSTRING", "STRING", "SUB_EQ", "WHITESPACE", "XOR_EQ", "M_ARG", "M_PASTE", "M_STRING", "P_LINE", "INVALID" ]) #foreach ($token in $tokens) /** The token type $token. */ public static final int $token = $i; |