From 9b2680ad6fe4b76112457476cb7a7a0f7b6c031a Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 16 Jul 2014 14:46:38 +0100 Subject: [PATCH] eolian: simplify the lexer (remove custom ident chars) --- src/lib/eolian/eo_lexer.c | 39 +++++++++++++-------------------------- src/lib/eolian/eo_lexer.h | 4 ---- 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index 719ebc9753..aae2aaaaf1 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -197,7 +197,7 @@ read_long_comment(Eo_Lexer *ls, const char **value) } static int -lex(Eo_Lexer *ls, const char **value, int *kwid, const char *chars) +lex(Eo_Lexer *ls, const char **value, int *kwid) { eina_strbuf_reset(ls->buff); for (;;) switch (ls->current) @@ -235,8 +235,7 @@ lex(Eo_Lexer *ls, const char **value, int *kwid, const char *chars) continue; } if (ls->current && (isalnum(ls->current) - || ls->current == '@' - || strchr(chars, ls->current))) + || ls->current == '@' || ls->current == '_')) { int col = ls->column; Eina_Bool at_kw = (ls->current == '@'); @@ -248,7 +247,7 @@ lex(Eo_Lexer *ls, const char **value, int *kwid, const char *chars) next_char(ls); } while (ls->current && (isalnum(ls->current) - || strchr(chars, ls->current))); + || ls->current == '_')); str = eina_strbuf_string_get(ls->buff); *kwid = (int)(uintptr_t)eina_hash_find(keyword_map, str); @@ -405,27 +404,6 @@ eo_lexer_get_until(Eo_Lexer *ls, char end) int eo_lexer_get(Eo_Lexer *ls) -{ - return eo_lexer_get_ident(ls, "_"); -} - -int -eo_lexer_lookahead(Eo_Lexer *ls) -{ - return eo_lexer_lookahead_ident(ls, "_"); -} - -int -eo_lexer_lookahead_ident(Eo_Lexer *ls, const char *chars) -{ - assert (ls->lookahead.token == TOK_EOF); - ls->lookahead.kw = 0; - return (ls->lookahead.token = lex(ls, &ls->lookahead.value, - &ls->lookahead.kw, chars)); -} - -int -eo_lexer_get_ident(Eo_Lexer *ls, const char *chars) { if (ls->lookahead.token != TOK_EOF) { @@ -434,7 +412,16 @@ eo_lexer_get_ident(Eo_Lexer *ls, const char *chars) return ls->t.token; } ls->t.kw = 0; - return (ls->t.token = lex(ls, &ls->t.value, &ls->t.kw, chars)); + return (ls->t.token = lex(ls, &ls->t.value, &ls->t.kw)); +} + +int +eo_lexer_lookahead(Eo_Lexer *ls) +{ + assert (ls->lookahead.token == TOK_EOF); + ls->lookahead.kw = 0; + return (ls->lookahead.token = lex(ls, &ls->lookahead.value, + &ls->lookahead.kw)); } void diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h index 619aa89e35..117ac0b4b8 100644 --- a/src/lib/eolian/eo_lexer.h +++ b/src/lib/eolian/eo_lexer.h @@ -148,12 +148,8 @@ int eo_lexer_get_balanced (Eo_Lexer *ls, char beg, char end); int eo_lexer_get_until (Eo_Lexer *ls, char end); /* gets a regular token, singlechar or one of TOK_something */ int eo_lexer_get (Eo_Lexer *ls); -/* like above, but allows you to specify a list of custom characters that can - * be used as part of identifiers */ -int eo_lexer_get_ident (Eo_Lexer *ls, const char *chars); /* lookahead token - see Eo_Lexer */ int eo_lexer_lookahead (Eo_Lexer *ls); -int eo_lexer_lookahead_ident(Eo_Lexer *ls, const char *chars); /* "throws" an error, with a custom message and custom token */ void eo_lexer_lex_error (Eo_Lexer *ls, const char *msg, int token); /* like above, but uses the lexstate->t.token, aka current token */