EOF
[m6w6/ext-psi] / src / parser.re
index 0782b8fe3a09d88e841e7e4a39f16ff9beda71b8..d4a25d2a5592e901881d18a56022a59edda168b3 100644 (file)
@@ -30,8 +30,8 @@ PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename, psi_error_cb err
        }
        memset(P, 0, sizeof(*P));
 
+       P->psi.file.fn = strdup(filename);
        P->fp = fp;
-       P->fn = strdup(filename);
        P->line = 1;
        P->error = error;
        P->flags = flags;
@@ -141,24 +141,12 @@ void PSI_ParserFree(PSI_Parser **P)
 
 #define RETURN(t) do { \
        P->num = t; \
+       if (P->flags & PSI_PARSER_DEBUG) { \
+               fprintf(stderr, "PSI> TOKEN: %d %.*s (EOF=%d)\n", P->num, (int) (P->cur-P->tok), P->tok, P->num == PSI_T_EOF); \
+       } \
        return t; \
 } while(1)
 
-/*             DIGIT = [0-9]
-               DIGITS = DIGIT+
-               DECIMALS = (+|-)? DIGIT* "."
-               digits ::= digits DIGIT.
-               decimals ::= digits DOT digits.
-               decimals ::= DOT digits.
-               decimals ::= digits DOT.
-               number ::= digits.
-               number ::= PLUS digits.
-               number ::= MINUS digits.
-               number ::= decimals.
-               number ::= MINUS decimals.
-               number ::= PLUS decimals.
-
-*/
 token_t PSI_ParserScan(PSI_Parser *P)
 {
        for (;;) {
@@ -169,7 +157,7 @@ token_t PSI_ParserScan(PSI_Parser *P)
                re2c:define:YYCURSOR = P->cur;
                re2c:define:YYLIMIT = P->lim;
                re2c:define:YYMARKER = P->mrk;
-               re2c:define:YYFILL = "{ if (!PSI_ParserFill(P,@@)) RETURN(-1); }";
+               re2c:define:YYFILL = "{ if (!PSI_ParserFill(P,@@)) RETURN(PSI_T_EOF); }";
                re2c:yyfill:parameter = 0;
 
                B = [^a-zA-Z0-9_];
@@ -179,7 +167,7 @@ token_t PSI_ParserScan(PSI_Parser *P)
                QUOTED_STRING = "\"" ([^\"])+ "\"";
                NUMBER = [+-]? [0-9]* "."? [0-9]+ ([eE] [+-]? [0-9]+)?;
 
-               "#" .* "\n" { ++P->line; RETURN(PSI_T_COMMENT);}
+               ("#"|"//") .* "\n" { ++P->line; continue;}
                "(" {RETURN(PSI_T_LPAREN);}
                ")" {RETURN(PSI_T_RPAREN);}
                ";" {RETURN(PSI_T_EOS);}
@@ -204,14 +192,15 @@ token_t PSI_ParserScan(PSI_Parser *P)
                'INT' {RETURN(PSI_T_INT);}
                'FLOAT' {RETURN(PSI_T_FLOAT);}
                'DOUBLE' {RETURN(PSI_T_DOUBLE);}
-               'INT8_T' {RETURN(PSI_T_SINT8);}
+               'INT8_T' {RETURN(PSI_T_INT8);}
                'UINT8_T' {RETURN(PSI_T_UINT8);}
-               'INT16_T' {RETURN(PSI_T_SINT16);}
+               'INT16_T' {RETURN(PSI_T_INT16);}
                'UINT16_T' {RETURN(PSI_T_UINT16);}
-               'INT32_T' {RETURN(PSI_T_SINT32);}
+               'INT32_T' {RETURN(PSI_T_INT32);}
                'UINT32_T' {RETURN(PSI_T_UINT32);}
-               'INT64_T' {RETURN(PSI_T_SINT64);}
+               'INT64_T' {RETURN(PSI_T_INT64);}
                'UINT64_T' {RETURN(PSI_T_UINT64);}
+               'UNSIGNED' {RETURN(PSI_T_UNSIGNED);}
                'STRING' {RETURN(PSI_T_STRING);}
                'ARRAY' {RETURN(PSI_T_ARRAY);}
                'FUNCTION' {RETURN(PSI_T_FUNCTION);}