X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fparser.re;h=e7787fc6cd47d64d32f0592f9f6cb5d0ea185308;hb=f4874db385a345217df8d1d31f55ab2f2b36dac3;hp=70ab698ab88bf1b69f0a209c4eb333f4033181d2;hpb=39831a9cf4a4aa9f126bc9a949f03ae232e3794b;p=m6w6%2Fext-psi diff --git a/src/parser.re b/src/parser.re index 70ab698..e7787fc 100644 --- a/src/parser.re +++ b/src/parser.re @@ -1,5 +1,8 @@ +#include #include #include +#include +#include #include "parser.h" #include "parser_proc.h" @@ -13,15 +16,13 @@ PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename, psi_error_cb err { FILE *fp; - if (!P) { - P = malloc(sizeof(*P)); - } - memset(P, 0, sizeof(*P)); - fp = fopen(filename, "r"); if (!fp) { - perror(filename); + if (!(flags & PSI_PARSER_SILENT)) { + error(NULL, NULL, PSI_WARNING, "Could not open '%s' for reading: %s", + filename, strerror(errno)); + } return NULL; } @@ -210,10 +211,10 @@ void PSI_ParserFree(PSI_Parser **P) #define ADDCOLS \ P->col += P->cur - P->tok -#define NEWLINE \ +#define NEWLINE(label) \ P->col = 1; \ ++P->line; \ - goto nextline + goto label token_t PSI_ParserScan(PSI_Parser *P) { @@ -237,7 +238,8 @@ token_t PSI_ParserScan(PSI_Parser *P) QUOTED_STRING = "\"" ([^\"])+ "\""; NUMBER = [+-]? [0-9]* "."? [0-9]+ ([eE] [+-]? [0-9]+)?; - ("#"|"//") .* "\n" { NEWLINE; } + "/*" { goto comment; } + ("#"|"//") .* "\n" { NEWLINE(nextline); } "(" {RETURN(PSI_T_LPAREN);} ")" {RETURN(PSI_T_RPAREN);} ";" {RETURN(PSI_T_EOS);} @@ -255,7 +257,7 @@ token_t PSI_ParserScan(PSI_Parser *P) "-" {RETURN(PSI_T_MINUS);} "/" {RETURN(PSI_T_SLASH);} "..." {RETURN(PSI_T_ELLIPSIS);} - [\r\n] { NEWLINE; } + [\r\n] { NEWLINE(nextline); } [\t ]+ { continue; } 'TRUE' {RETURN(PSI_T_TRUE);} 'FALSE' {RETURN(PSI_T_FALSE);} @@ -285,6 +287,8 @@ token_t PSI_ParserScan(PSI_Parser *P) 'FUNCTION' {RETURN(PSI_T_FUNCTION);} 'TYPEDEF' {RETURN(PSI_T_TYPEDEF);} 'STRUCT' {RETURN(PSI_T_STRUCT);} + 'UNION' {RETURN(PSI_T_UNION);} + 'ENUM' {RETURN(PSI_T_ENUM);} 'CONST' {RETURN(PSI_T_CONST);} 'LIB' {RETURN(PSI_T_LIB);} 'LET' {RETURN(PSI_T_LET);} @@ -313,6 +317,14 @@ token_t PSI_ParserScan(PSI_Parser *P) QUOTED_STRING {RETURN(PSI_T_QUOTED_STRING);} [^] {break;} */ + + comment: + P->tok = P->cur; + /*!re2c + "\n" { NEWLINE(comment); } + "*" "/" { continue; } + [^] { goto comment; } + */ } return -1; }