projects
/
m6w6
/
ext-psi
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
flush
[m6w6/ext-psi]
/
src
/
parser.re
diff --git
a/src/parser.re
b/src/parser.re
index 0922ba1b0f23f6ceb3debb4b9ffbe8c058aa77ae..e7787fc6cd47d64d32f0592f9f6cb5d0ea185308 100644
(file)
--- a/
src/parser.re
+++ b/
src/parser.re
@@
-1,6
+1,8
@@
#include <stddef.h>
#include <stdio.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <assert.h>
+#include <errno.h>
+#include <string.h>
#include "parser.h"
#include "parser_proc.h"
#include "parser.h"
#include "parser_proc.h"
@@
-14,15
+16,13
@@
PSI_Parser *PSI_ParserInit(PSI_Parser *P, const char *filename, psi_error_cb err
{
FILE *fp;
{
FILE *fp;
- if (!P) {
- P = malloc(sizeof(*P));
- }
- memset(P, 0, sizeof(*P));
-
fp = fopen(filename, "r");
if (!fp) {
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;
}
return NULL;
}
@@
-211,10
+211,10
@@
void PSI_ParserFree(PSI_Parser **P)
#define ADDCOLS \
P->col += P->cur - P->tok
#define ADDCOLS \
P->col += P->cur - P->tok
-#define NEWLINE \
+#define NEWLINE
(label)
\
P->col = 1; \
++P->line; \
P->col = 1; \
++P->line; \
- goto
nextline
+ goto
label
token_t PSI_ParserScan(PSI_Parser *P)
{
token_t PSI_ParserScan(PSI_Parser *P)
{
@@
-238,7
+238,8
@@
token_t PSI_ParserScan(PSI_Parser *P)
QUOTED_STRING = "\"" ([^\"])+ "\"";
NUMBER = [+-]? [0-9]* "."? [0-9]+ ([eE] [+-]? [0-9]+)?;
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);}
"(" {RETURN(PSI_T_LPAREN);}
")" {RETURN(PSI_T_RPAREN);}
";" {RETURN(PSI_T_EOS);}
@@
-256,7
+257,7
@@
token_t PSI_ParserScan(PSI_Parser *P)
"-" {RETURN(PSI_T_MINUS);}
"/" {RETURN(PSI_T_SLASH);}
"..." {RETURN(PSI_T_ELLIPSIS);}
"-" {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);}
[\t ]+ { continue; }
'TRUE' {RETURN(PSI_T_TRUE);}
'FALSE' {RETURN(PSI_T_FALSE);}
@@
-286,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);}
'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);}
'CONST' {RETURN(PSI_T_CONST);}
'LIB' {RETURN(PSI_T_LIB);}
'LET' {RETURN(PSI_T_LET);}
@@
-314,6
+317,14
@@
token_t PSI_ParserScan(PSI_Parser *P)
QUOTED_STRING {RETURN(PSI_T_QUOTED_STRING);}
[^] {break;}
*/
QUOTED_STRING {RETURN(PSI_T_QUOTED_STRING);}
[^] {break;}
*/
+
+ comment:
+ P->tok = P->cur;
+ /*!re2c
+ "\n" { NEWLINE(comment); }
+ "*" "/" { continue; }
+ [^] { goto comment; }
+ */
}
return -1;
}
}
return -1;
}