From: Michael Wallner Date: Fri, 27 Nov 2015 14:20:13 +0000 (+0100) Subject: EOF X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=14c98cac21b8102d1d4c2a57744f6976ea3a0849;p=m6w6%2Fext-psi EOF --- diff --git a/Makefile.frag b/Makefile.frag index e5e4608..e1aecfe 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -6,7 +6,7 @@ PHP_PSI_SOURCES := $(addprefix $(PHP_PSI_SRCDIR)/,$(PHP_PSI_SOURCES)) $(PHP_PSI_BUILDDIR)/%.h: $(PHP_PSI_SRCDIR)/src/%.h @cat >$@ <$< -all: psi-build-headers +install-headers: psi-build-headers clean: psi-clean-headers .PHONY: psi-build-headers @@ -25,18 +25,16 @@ lemon.c: ./lemon: lemon.c | lempar.c $(CC) -o $@ $< -$(PHP_PSI_SRCDIR)/src/context.c: $(PHP_PSI_SRCDIR)/config.m4 +$(PHP_PSI_SRCDIR)/src/parser_proc.h: $(PHP_PSI_SRCDIR)/src/parser_proc.y + +$(PHP_PSI_SRCDIR)/src/%.c: $(PHP_PSI_SRCDIR)/src/parser.h $(PHP_PSI_SRCDIR)/src/parser_proc.h touch $@ -$(PHP_PSI_BUILDDIR)/parser.h: $(PHP_PSI_BUILDDIR)/parser_proc.h - touch $@ -$(PHP_PSI_SRCDIR)/src/%.c: $(PHP_PSI_BUILDDIR)/parser.h - touch $@ -$(PHP_PSI_SRCDIR)/src/parser_proc.y: $(PHP_PSI_BUILDDIR)/parser.h +$(PHP_PSI_SRCDIR)/src/parser_proc.y: $(PHP_PSI_SRCDIR)/src/parser.h touch $@ $(PHP_PSI_SRCDIR)/src/parser_proc.c: $(PHP_PSI_SRCDIR)/src/parser_proc.y $(LEMON) $(LEMON) -c $< -$(PHP_PSI_SRCDIR)/src/parser.re: $(PHP_PSI_BUILDDIR)/parser.h $(PHP_PSI_BUILDDIR)/parser_proc.h +$(PHP_PSI_SRCDIR)/src/parser.re: $(PHP_PSI_SRCDIR)/src/parser.h $(PHP_PSI_SRCDIR)/src/parser_proc.h touch $@ $(PHP_PSI_SRCDIR)/src/parser.c: $(PHP_PSI_SRCDIR)/src/parser.re $(RE2C) -o $@ $< diff --git a/src/context.c b/src/context.c index 05d5aac..cbcfbc6 100644 --- a/src/context.c +++ b/src/context.c @@ -960,9 +960,13 @@ void PSI_ContextBuild(PSI_Context *C, const char *paths) continue; } - while (-1 != PSI_ParserScan(&P)) { + while (0 < PSI_ParserScan(&P)) { PSI_ParserParse(&P, PSI_TokenAlloc(&P)); - }; + if (P.num == PSI_T_EOF) { + break; + } + } + PSI_ParserParse(&P, NULL); PSI_ContextValidate(C, &P); PSI_ParserDtor(&P); diff --git a/src/parser.h b/src/parser.h index 0f2b4a0..5ec0b95 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1065,7 +1065,7 @@ static inline PSI_Token *PSI_TokenAlloc(PSI_Parser *P) { PSI_Token *T; size_t token_len; - if (P->cur <= P->tok) { + if (P->cur < P->tok) { return NULL; } diff --git a/src/parser.re b/src/parser.re index 08478bc..d4a25d2 100644 --- a/src/parser.re +++ b/src/parser.re @@ -141,6 +141,9 @@ 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) @@ -154,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_]; diff --git a/src/parser_proc.h b/src/parser_proc.h index f5bea57..62530ca 100644 --- a/src/parser_proc.h +++ b/src/parser_proc.h @@ -5,54 +5,55 @@ #define PSI_T_RETURN 5 #define PSI_T_LIB 6 #define PSI_T_INT 7 -#define PSI_T_QUOTED_STRING 8 -#define PSI_T_EOS 9 -#define PSI_T_STRUCT 10 -#define PSI_T_LBRACE 11 -#define PSI_T_RBRACE 12 -#define PSI_T_COLON 13 -#define PSI_T_LPAREN 14 -#define PSI_T_NUMBER 15 -#define PSI_T_RPAREN 16 -#define PSI_T_BOOL 17 -#define PSI_T_FLOAT 18 -#define PSI_T_STRING 19 -#define PSI_T_CONST 20 -#define PSI_T_NSNAME 21 -#define PSI_T_EQUALS 22 -#define PSI_T_TYPEDEF 23 -#define PSI_T_VOID 24 -#define PSI_T_LBRACKET 25 -#define PSI_T_RBRACKET 26 -#define PSI_T_COMMA 27 -#define PSI_T_DOUBLE 28 -#define PSI_T_INT8 29 -#define PSI_T_UINT8 30 -#define PSI_T_INT16 31 -#define PSI_T_UINT16 32 -#define PSI_T_INT32 33 -#define PSI_T_UINT32 34 -#define PSI_T_INT64 35 -#define PSI_T_UINT64 36 -#define PSI_T_UNSIGNED 37 -#define PSI_T_FUNCTION 38 -#define PSI_T_REFERENCE 39 -#define PSI_T_NULL 40 -#define PSI_T_TRUE 41 -#define PSI_T_FALSE 42 -#define PSI_T_DOLLAR 43 -#define PSI_T_CALLOC 44 -#define PSI_T_ARRVAL 45 -#define PSI_T_STRLEN 46 -#define PSI_T_STRVAL 47 -#define PSI_T_FLOATVAL 48 -#define PSI_T_INTVAL 49 -#define PSI_T_BOOLVAL 50 -#define PSI_T_TO_ARRAY 51 -#define PSI_T_TO_STRING 52 -#define PSI_T_TO_INT 53 -#define PSI_T_TO_FLOAT 54 -#define PSI_T_TO_BOOL 55 -#define PSI_T_MIXED 56 -#define PSI_T_ARRAY 57 -#define PSI_T_POINTER 58 +#define PSI_T_UNSIGNED 8 +#define PSI_T_EOF 9 +#define PSI_T_QUOTED_STRING 10 +#define PSI_T_EOS 11 +#define PSI_T_STRUCT 12 +#define PSI_T_LBRACE 13 +#define PSI_T_RBRACE 14 +#define PSI_T_COLON 15 +#define PSI_T_LPAREN 16 +#define PSI_T_NUMBER 17 +#define PSI_T_RPAREN 18 +#define PSI_T_BOOL 19 +#define PSI_T_FLOAT 20 +#define PSI_T_STRING 21 +#define PSI_T_CONST 22 +#define PSI_T_NSNAME 23 +#define PSI_T_EQUALS 24 +#define PSI_T_TYPEDEF 25 +#define PSI_T_VOID 26 +#define PSI_T_LBRACKET 27 +#define PSI_T_RBRACKET 28 +#define PSI_T_COMMA 29 +#define PSI_T_DOUBLE 30 +#define PSI_T_INT8 31 +#define PSI_T_UINT8 32 +#define PSI_T_INT16 33 +#define PSI_T_UINT16 34 +#define PSI_T_INT32 35 +#define PSI_T_UINT32 36 +#define PSI_T_INT64 37 +#define PSI_T_UINT64 38 +#define PSI_T_FUNCTION 39 +#define PSI_T_REFERENCE 40 +#define PSI_T_NULL 41 +#define PSI_T_TRUE 42 +#define PSI_T_FALSE 43 +#define PSI_T_DOLLAR 44 +#define PSI_T_CALLOC 45 +#define PSI_T_ARRVAL 46 +#define PSI_T_STRLEN 47 +#define PSI_T_STRVAL 48 +#define PSI_T_FLOATVAL 49 +#define PSI_T_INTVAL 50 +#define PSI_T_BOOLVAL 51 +#define PSI_T_TO_ARRAY 52 +#define PSI_T_TO_STRING 53 +#define PSI_T_TO_INT 54 +#define PSI_T_TO_FLOAT 55 +#define PSI_T_TO_BOOL 56 +#define PSI_T_MIXED 57 +#define PSI_T_ARRAY 58 +#define PSI_T_POINTER 59 diff --git a/src/parser_proc.y b/src/parser_proc.y index 99054b6..ac7c117 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -23,13 +23,15 @@ } %nonassoc NAME. -%fallback NAME FREE SET LET RETURN LIB INT. +%fallback NAME FREE SET LET RETURN LIB INT UNSIGNED. file ::= blocks. blocks ::= block. blocks ::= blocks block. +block ::= EOF. + block ::= LIB(T) QUOTED_STRING(libname) EOS. { if (P->psi.file.ln) { PSI_ParserSyntaxError(P, P->psi.file.ln, T->line, "Extra 'lib %s' statement has no effect", libname->text);