lex
static int lex_init(struct lexer *lex, const char *in, size_t in_len)
lex->p = in;
lex->term_end = in;
lex->end = in + in_len;
static int lex_do(struct lexer *lex)
const char *p = lex->term_end, *end = lex->end, *term_end;
lex->p = end;
lex->term_end = end;
lex->p = p;
lex->term_end = term_end;
static int lex_eot(struct lexer *lex)
return lex->p == lex->term_end;
static int lex_peek_char(struct lexer *lex)
return lex_eot(lex) ? -1 : *lex->p;
static int lex_skip_char(struct lexer *lex)
if (lex_eot(lex))
++lex->p;
static int lex_match(struct lexer *lex, const char *s, size_t s_len)
if ((size_t)(lex->term_end - lex->p) != s_len)
if (memcmp(lex->p, s, s_len))
static void lex_get_rest(struct lexer *lex, const char **str, size_t *str_l)
*str = lex->p;
*str_l = lex->term_end - lex->p;
static int lex_extract_to(struct lexer *lex, char c,
const char *p = lex->p, *term_end = lex->term_end, *s;
lex->p = ++s;
static int lex_fail(struct lexer *lex, const char *msg)
lex->p = lex->term_end = lex->end;
struct lexer lex = { 0 };
if (!lex_init(&lex, filter, strlen(filter)))
while (lex_do(&lex)) {
c = lex_peek_char(&lex);
lex_skip_char(&lex);
c = lex_peek_char(&lex);
return lex_fail(&lex, "expected alphanumeric name or '*'"
return lex_fail(&lex, "expected +/- or alphanumeric name or '*'");
if (lex_match(&lex, "*", 1)) {
if (!lex_extract_to(&lex, ':', &cat, &cat_l))
return lex_fail(&lex, "expected ':' after category name");
lex_get_rest(&lex, &event, &event_l);
return lex_fail(&lex, "expected alphanumeric category name or '*'");
return lex_fail(&lex, "expected alphanumeric event name or '*'");
http_header_lex_t lex;
lex = http_header_lex(&cp, key);
if (lex != HTTPHL_WORD)
lex = http_header_lex(&cp, key);
if (lex != HTTPHL_WORD)
lex = http_header_lex(&cp, buf);
if (lex != '=')
lex = http_header_lex(&cp, value);
if (lex != HTTPHL_WORD && lex != HTTPHL_STRING)
lex = http_header_lex(&cp, key);
if (lex == HTTPHL_WORD)
if (lex == HTTPHL_END) {
if (lex != ',')
lex(char *);
com = lex(word);
struct lex *lp;