strange structs
[cparser] / lexer.c
diff --git a/lexer.c b/lexer.c
index 9ff748a..cbdb783 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -17,6 +17,7 @@
 
 static int         c;
 token_t            lexer_token;
+symbol_t          *symbol_L;
 static FILE       *input;
 static char        buf[1024 + MAX_PUTBACK];
 static const char *bufend;
@@ -475,16 +476,21 @@ static void parse_number(void)
        }
 }
 
-static int parse_octal_sequence(void)
+static inline int is_octal_digit(int chr)
 {
-       int value = 0;
-       while(1) {
-               if(c < '0' || c > '7')
-                       break;
-               value = 8 * value + c - '0';
-               next_char();
-       }
+       return '0' <= chr && chr <= '7';
+}
 
+static int parse_octal_sequence(const int first_digit)
+{
+       assert(is_octal_digit(first_digit));
+       int value = first_digit - '0';
+       if (!is_octal_digit(c)) return value;
+       value = 8 * value + c - '0';
+       next_char();
+       if (!is_octal_digit(c)) return value;
+       value = 8 * value + c - '0';
+       next_char();
        return value;
 }
 
@@ -516,7 +522,7 @@ static int parse_escape_sequence(void)
 
        switch(ec) {
        case '"':  return '"';
-       case '\'': return'\'';
+       case '\'': return '\'';
        case '\\': return '\\';
        case '?': return '\?';
        case 'a': return '\a';
@@ -536,7 +542,7 @@ static int parse_escape_sequence(void)
        case '5':
        case '6':
        case '7':
-               return parse_octal_sequence();
+               return parse_octal_sequence(ec);
        case EOF:
                parse_error("reached end of file while parsing escape sequence");
                return EOF;
@@ -804,7 +810,7 @@ static void parse_preprocessor_identifier(void)
        }
 }
 
-static void parse_preprocessor_directive()
+static void parse_preprocessor_directive(void)
 {
        next_pp_token();
 
@@ -862,6 +868,12 @@ void lexer_next_preprocessing_token(void)
 
                SYMBOL_CHARS
                        parse_symbol();
+                       /* might be a wide string ( L"string" ) */
+                       if(c == '"' && (lexer_token.type == T_IDENTIFIER &&
+                          lexer_token.v.symbol == symbol_L)) {
+                               parse_string_literal();
+                               return;
+                       }
                        return;
 
                DIGITS
@@ -1040,6 +1052,8 @@ void lexer_open_stream(FILE *stream, const char *input_name)
        lexer_token.source_position.linenr     = 0;
        lexer_token.source_position.input_name = input_name;
 
+       symbol_L = symbol_table_insert("L");
+
        /* place a virtual \n at the beginning so the lexer knows that we're
         * at the beginning of a line */
        c = '\n';