lexer.h

00001 /*
00002  * Copyright (c) 2005-2012 by KoanLogic s.r.l. - All rights reserved.
00003  */
00004 
00005 #ifndef _U_LEXER_H_
00006 #define _U_LEXER_H_
00007 
00008 #ifdef __cplusplus
00009 extern "C" {
00010 #endif
00011 
00012 #ifndef U_LEXER_ERR_SZ
00013   #define U_LEXER_ERR_SZ    512
00014 #endif  /* !U_LEXER_ERR_SZ */
00015 
00016 struct u_lexer_s;
00017 
00024 typedef struct u_lexer_s u_lexer_t;
00025 
00028 #ifndef U_TOKEN_SZ
00029   #define U_TOKEN_SZ    128
00030 #endif  /* !U_TOKEN_SZ */
00031 
00032 /*
00033  * All the following U_LEXER_ macros need the "err" label in scope.
00034  */
00035 
00037 #define U_LEXER_ERR(l, ...)                                         \
00038     do {                                                            \
00039         (void) u_lexer_seterr(l, __VA_ARGS__);                      \
00040         goto err;                                                   \
00041     } while (0)
00042 
00044 #define U_LEXER_SKIP(l, pc)                                         \
00045     do {                                                            \
00046         if (u_lexer_skip(l, pc))                                    \
00047             U_LEXER_ERR(l, "EOT at offset %zu", u_lexer_pos(l));    \
00048     } while (0)
00049 
00051 #define U_LEXER_NEXT(l, pc)                                         \
00052     do {                                                            \
00053         if (u_lexer_next(l, pc))                                    \
00054             U_LEXER_ERR(l, "EOT at offset %zu", u_lexer_pos(l));    \
00055     } while (0)
00056 
00057 int u_lexer_new (const char *s, u_lexer_t **pl);
00058 void u_lexer_free (u_lexer_t *l);
00059 const char *u_lexer_geterr (u_lexer_t *l);
00060 
00061 int u_lexer_next (u_lexer_t *l, char *pb);
00062 int u_lexer_skip (u_lexer_t *l, char *pb);
00063 char u_lexer_peek (u_lexer_t *l);
00064 int u_lexer_seterr (u_lexer_t *l, const char *fmt, ...);
00065 void u_lexer_record_lmatch (u_lexer_t *l);
00066 void u_lexer_record_rmatch (u_lexer_t *l);
00067 char *u_lexer_get_match (u_lexer_t *l, char match[U_TOKEN_SZ]);
00068 int u_lexer_eot (u_lexer_t *l);
00069 int u_lexer_eat_ws (u_lexer_t *l);
00070 int u_lexer_expect_char (u_lexer_t *l, char expected);
00071 size_t u_lexer_pos (u_lexer_t *l);
00072 const char *u_lexer_lookahead (u_lexer_t *l);
00073 
00078 #ifdef __cplusplus
00079 }
00080 #endif
00081 
00082 #endif  /* !_U_LEXER_H_ */

←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved