From 96f360a7d131a3a0c581e8b8568e5da00a4f42a1 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 18 Jul 2014 11:48:40 +0100 Subject: [PATCH] eolian: lexing of multichar binary operators --- src/lib/eolian/eo_lexer.c | 52 +++++++++++++++++++++++++++++++++++--- src/lib/eolian/eo_lexer.h | 2 +- src/lib/eolian/eo_parser.c | 4 +-- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index 80ee15a3c3..74b5ac093e 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -44,7 +44,7 @@ next_char(Eo_Lexer *ls) static const char * const tokens[] = { - "==", "!=", ">", "<", ">=", "<=", "&&", "||", "<<", ">>", + "==", "!=", ">=", "<=", "&&", "||", "<<", ">>", "", "", "", "", @@ -106,7 +106,7 @@ init_hash(void) unsigned int i, u; if (keyword_map) return; keyword_map = eina_hash_string_superfast_new(NULL); - for (i = u = 14; i < (sizeof(tokens) / sizeof(const char*)); ++i) + for (i = u = 12; i < (sizeof(tokens) / sizeof(const char*)); ++i) { eina_hash_add(keyword_map, tokens[i], (void*)(size_t)(i - u + 1)); } @@ -484,6 +484,52 @@ lex(Eo_Lexer *ls, Eo_Token *tok) continue; case '\0': return -1; + case '=': + next_char(ls); + if (ls->current != '=') return '='; + next_char(ls); + return TOK_EQ; + case '!': + next_char(ls); + if (ls->current != '=') return '!'; + next_char(ls); + return TOK_NQ; + case '>': + next_char(ls); + if (ls->current == '=') + { + next_char(ls); + return TOK_GE; + } + else if (ls->current == '>') + { + next_char(ls); + return TOK_RSH; + } + return '>'; + case '<': + next_char(ls); + if (ls->current == '=') + { + next_char(ls); + return TOK_LE; + } + else if (ls->current == '<') + { + next_char(ls); + return TOK_LSH; + } + return '<'; + case '&': + next_char(ls); + if (ls->current != '&') return '&'; + next_char(ls); + return TOK_AND; + case '|': + next_char(ls); + if (ls->current != '|') return '|'; + next_char(ls); + return TOK_OR; case '"': case '\'': read_string(ls, tok); return TOK_STRING; @@ -716,7 +762,7 @@ eo_lexer_token_to_str(int token, char *buf) const char * eo_lexer_keyword_str_get(int kw) { - return tokens[kw + 13]; + return tokens[kw + 11]; } Eina_Bool diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h index 95abb90b2f..67ea76f11e 100644 --- a/src/lib/eolian/eo_lexer.h +++ b/src/lib/eolian/eo_lexer.h @@ -13,7 +13,7 @@ enum Tokens { - TOK_EQ = START_CUSTOM, TOK_NQ, TOK_GT, TOK_LT, TOK_GE, TOK_LE, + TOK_EQ = START_CUSTOM, TOK_NQ, TOK_GE, TOK_LE, TOK_AND, TOK_OR, TOK_LSH, TOK_RSH, TOK_COMMENT, TOK_STRING, TOK_NUMBER, TOK_VALUE diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index f5422c1e09..ecb6d86480 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -250,8 +250,8 @@ get_binop_id(int tok) case TOK_EQ: return EOLIAN_BINOP_EQ; case TOK_NQ: return EOLIAN_BINOP_NQ; - case TOK_GT: return EOLIAN_BINOP_GT; - case TOK_LT: return EOLIAN_BINOP_LT; + case '>' : return EOLIAN_BINOP_GT; + case '<' : return EOLIAN_BINOP_LT; case TOK_GE: return EOLIAN_BINOP_GE; case TOK_LE: return EOLIAN_BINOP_LE;