#pragma lib
[m6w6/ext-psi] / src / parser_scan.re
index 043243fd81e12c91052f792a8570c441e288a993..a02fdd0e3d950a17db2ef8e31bd9924d1f9e3a50 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "parser.h"
 #include "plist.h"
+#include "debug.h"
 
 /*!max:re2c*/
 #ifndef YYMAXFILL
@@ -43,17 +44,19 @@ size_t psi_parser_maxfill(void) {
 
 #define NEWLINE() \
        eol = cur; \
-       ++I->lines
+       ++lines
 
 #define NEWTOKEN(t) do { \
        if (t == PSI_T_COMMENT || t == PSI_T_WHITESPACE) { \
-               token = psi_token_init(t, "", 0, tok - eol + 1, I->lines, I->file); \
+               token = psi_token_init(t, "", 0, tok - eol + 1, lines, I->file); \
        } else { \
-               token = psi_token_init(t, tok, cur - tok, tok - eol + 1, I->lines, I->file); \
+               token = psi_token_init(t, tok, cur - tok, tok - eol + 1, lines, I->file); \
        } \
        tokens = psi_plist_add(tokens, &token); \
-       PSI_DEBUG_PRINT(P, "PSI: scanned < "); \
-       PSI_DEBUG_DUMP(P, psi_token_dump, token); \
+       PSI_DEBUG_LOCK(P, \
+                       PSI_DEBUG_PRINT(P, "PSI: scanned < "); \
+                       PSI_DEBUG_DUMP(P, psi_token_dump, token); \
+       ); \
 } while(0)
 
 #define CHECKEOF() if (cur >= lim - YYMAXFILL) goto done
@@ -63,15 +66,13 @@ struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input
        struct psi_plist *tokens;
        struct psi_token *token;
        const char *tok, *cur, *lim, *mrk, *eol, *ctxmrk;
-       unsigned parens;
+       unsigned char_width, parens, lines = 1;
        bool escaped;
-       token_t char_width;
 
        PSI_DEBUG_PRINT(P, "PSI: scanning %s\n", I->file->val);
 
        tok = mrk = eol = cur = I->buffer;
        lim = I->buffer + I->length + YYMAXFILL;
-       I->lines = 1;
        tokens = psi_plist_init((psi_plist_dtor) psi_token_free);
 
        start: ;
@@ -118,8 +119,8 @@ struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input
                INT_CONST / ('llu' | 'ull')     { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_INT | PSI_NUMBER_ULL; cur += 3; goto start; }
 
                FLT_CONST                                       { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT; goto start; }
-               FLT_CONST / 'f'                         { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_F; cur += 1; goto start; }
-               FLT_CONST / 'l'                         { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_L; cur += 1; goto start; }
+               FLT_CONST       / 'f'                   { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_F; cur += 1; goto start; }
+               FLT_CONST       / 'l'                   { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_L; cur += 1; goto start; }
                FLT_CONST       / 'df'                  { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_DF; cur += 2; goto start; }
                FLT_CONST       / 'dd'                  { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_DD; cur += 2; goto start; }
                FLT_CONST       / 'dl'                  { NEWTOKEN(PSI_T_NUMBER); token->flags = PSI_NUMBER_FLT | PSI_NUMBER_DL; cur += 2; goto start; }
@@ -129,7 +130,7 @@ struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input
                "u8" / "\""             { char_width = 1; }
                "u" / ['"]              { char_width = 2; }
                "U" / ['"]              { char_width = 4; }
-               "L" / ['"]              { char_width = sizeof(wchar_t)/8; }
+               "L" / ['"]              { char_width = sizeof(wchar_t); }
 
                "/*"                    { goto comment; }
                "//"                    { goto comment_sl; }
@@ -171,7 +172,6 @@ struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input
                "..."                   { NEWTOKEN(PSI_T_ELLIPSIS); goto start; }
                "?"                             { NEWTOKEN(PSI_T_IIF); goto start; }
                "pragma"                { NEWTOKEN(PSI_T_PRAGMA); goto start; }
-               "pragma" W+ "once"      { NEWTOKEN(PSI_T_PRAGMA_ONCE); goto start; }
                "__"? "inline"  { NEWTOKEN(PSI_T_CPP_INLINE); goto start; }
                "__restrict"    { NEWTOKEN(PSI_T_CPP_RESTRICT); goto start; }
                "__extension__" { NEWTOKEN(PSI_T_CPP_EXTENSION); goto start; }