X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=src%2Fparser.re;h=e7787fc6cd47d64d32f0592f9f6cb5d0ea185308;hb=ef5079cd02c9d8666f6b9336853d2ab393e33467;hp=50d15aadd86d0b9ae7dfb35a1b445277afdbf554;hpb=6a459a08a40a2c243b0211ceb0cb263d29302627;p=m6w6%2Fext-psi diff --git a/src/parser.re b/src/parser.re index 50d15aa..e7787fc 100644 --- a/src/parser.re +++ b/src/parser.re @@ -19,8 +19,10 @@ PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename, psi_error_cb err fp = fopen(filename, "r"); if (!fp) { - error(NULL, PSI_WARNING, "Could not open '%s' for reading: %s", - filename, strerror(errno)); + if (!(flags & PSI_PARSER_SILENT)) { + error(NULL, NULL, PSI_WARNING, "Could not open '%s' for reading: %s", + filename, strerror(errno)); + } return NULL; } @@ -209,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) { @@ -236,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);} @@ -254,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);} @@ -284,6 +287,7 @@ 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);} @@ -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; }