#include "parser.h"
-void *psi_parser_proc_Alloc(void*(unsigned long));
-void psi_parser_proc_Free(void*, void(*)(void*));
-void psi_parser_proc_(void *, token_t, struct psi_token *, struct psi_parser *);
-void psi_parser_proc_Trace(FILE *, const char*);
+void *psi_parser_proc_init(void);
+void psi_parser_proc_free(void **parser_proc);
+void psi_parser_proc_parse(void *parser_proc, token_t r, struct psi_token *token, struct psi_parser *parser);
+void psi_parser_proc_trace(FILE *out, char *prefix);
struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, unsigned flags)
{
P->col = 1;
P->line = 1;
- P->proc = psi_parser_proc_Alloc(malloc);
+ P->proc = psi_parser_proc_init();
if (flags & PSI_DEBUG) {
- psi_parser_proc_Trace(stderr, "PSI> ");
+ psi_parser_proc_trace(stderr, "PSI> ");
}
return P;
static ssize_t psi_parser_fill(struct psi_parser *P, size_t n)
{
- PSI_DEBUG_PRINT(P, "PSI> Fill: n=%zu (input.type=%d)\n", n, P->input.type);
+ PSI_DEBUG_PRINT(P, "PSI< Fill: n=%zu (input.type=%d)\n", n, P->input.type);
/* init if n==0 */
if (!n) {
break;
}
- PSI_DEBUG_PRINT(P, "PSI> Fill: cur=%p lim=%p eof=%p\n", P->cur, P->lim, P->eof);
+ PSI_DEBUG_PRINT(P, "PSI< Fill: cur=%p lim=%p eof=%p\n", P->cur, P->lim, P->eof);
}
switch (P->input.type) {
if (didread < available) {
P->eof = P->lim;
}
- PSI_DEBUG_PRINT(P, "PSI> Fill: consumed=%zu reserved=%zu available=%zu didread=%zu\n",
+ PSI_DEBUG_PRINT(P, "PSI< Fill: consumed=%zu reserved=%zu available=%zu didread=%zu\n",
consumed, reserved, available, didread);
}
#endif
break;
}
- PSI_DEBUG_PRINT(P, "PSI> Fill: avail=%td\n", P->lim - P->cur);
+ PSI_DEBUG_PRINT(P, "PSI< Fill: avail=%td\n", P->lim - P->cur);
return P->lim - P->cur;
}
void psi_parser_parse(struct psi_parser *P, struct psi_token *T)
{
if (T) {
- psi_parser_proc_(P->proc, T->type, T, P);
+ psi_parser_proc_parse(P->proc, T->type, T, P);
} else {
- psi_parser_proc_(P->proc, 0, NULL, P);
+ psi_parser_proc_parse(P->proc, 0, NULL, P);
}
}
void psi_parser_dtor(struct psi_parser *P)
{
- psi_parser_proc_Free(P->proc, free);
+ psi_parser_proc_free(&P->proc);
switch (P->input.type) {
case PSI_PARSE_FILE:
#define RETURN(t) do { \
P->num = t; \
- PSI_DEBUG_PRINT(P, "PSI> TOKEN: %d %.*s (EOF=%d %s:%u:%u)\n", \
+ PSI_DEBUG_PRINT(P, "PSI< TOKEN: %d %.*s (EOF=%d %s:%u:%u)\n", \
P->num, (int) (P->cur-P->tok), P->tok, P->num == PSI_T_EOF, \
P->file.fn, P->line, P->col); \
return t; \
"]" {RETURN(PSI_T_RBRACKET);}
"=" {RETURN(PSI_T_EQUALS);}
"*" {RETURN(PSI_T_ASTERISK);}
+ "~" {RETURN(PSI_T_TILDE);}
+ "!" {RETURN(PSI_T_NOT);}
+ "%" {RETURN(PSI_T_MODULO);}
"&" {RETURN(PSI_T_AMPERSAND);}
"+" {RETURN(PSI_T_PLUS);}
"-" {RETURN(PSI_T_MINUS);}
"/" {RETURN(PSI_T_SLASH);}
+ "|" {RETURN(PSI_T_PIPE);}
+ "^" {RETURN(PSI_T_CARET);}
+ "<<" {RETURN(PSI_T_LSHIFT);}
+ ">>" {RETURN(PSI_T_RSHIFT);}
"..." {RETURN(PSI_T_ELLIPSIS);}
[\r\n] { NEWLINE(nextline); }
[\t ]+ { continue; }