diff options
author | Daniel Kolesa <d.kolesa@samsung.com> | 2014-08-08 11:32:07 +0100 |
---|---|---|
committer | Tom Hacohen <tom@stosb.com> | 2014-08-11 13:34:54 +0100 |
commit | 930777f8e55f4fc0e9034312e7dccb4afc886006 (patch) | |
tree | b0c3ee8051be9670261740c3d53630ae32af8be0 | |
parent | 0413a524dbc2db8fd71119ba12da97e3aa3d497e (diff) | |
download | efl-930777f8e55f4fc0e9034312e7dccb4afc886006.tar.gz |
eolian: expression mode for lexer
This way we can only lex expr related tokens (operators etc.) when actually
about to parse an expression. That allows stuff like nested complex types
without the lexer treating the endings as right shift.
-rw-r--r-- | src/lib/eolian/eo_lexer.c | 19 | ||||
-rw-r--r-- | src/lib/eolian/eo_lexer.h | 3 | ||||
-rw-r--r-- | src/lib/eolian/eo_parser.c | 2 | ||||
-rw-r--r-- | src/tests/eolian/data/complex_type.eo | 2 |
4 files changed, 20 insertions, 6 deletions
diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index 8a40c64862..10060402dc 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -490,16 +490,17 @@ lex(Eo_Lexer *ls, Eo_Token *tok) return -1; case '=': next_char(ls); - if (ls->current != '=') return '='; + if (!ls->expr_mode || (ls->current != '=')) return '='; next_char(ls); return TOK_EQ; case '!': next_char(ls); - if (ls->current != '=') return '!'; + if (!ls->expr_mode || (ls->current != '=')) return '!'; next_char(ls); return TOK_NQ; case '>': next_char(ls); + if (!ls->expr_mode) return '>'; if (ls->current == '=') { next_char(ls); @@ -513,6 +514,7 @@ lex(Eo_Lexer *ls, Eo_Token *tok) return '>'; case '<': next_char(ls); + if (!ls->expr_mode) return '<'; if (ls->current == '=') { next_char(ls); @@ -526,19 +528,25 @@ lex(Eo_Lexer *ls, Eo_Token *tok) return '<'; case '&': next_char(ls); - if (ls->current != '&') return '&'; + if (!ls->expr_mode || (ls->current != '&')) return '&'; next_char(ls); return TOK_AND; case '|': next_char(ls); - if (ls->current != '|') return '|'; + if (!ls->expr_mode || (ls->current != '|')) return '|'; next_char(ls); return TOK_OR; case '"': + if (!ls->expr_mode) + { + next_char(ls); + return '"'; + } read_string(ls, tok); return TOK_STRING; case '\'': next_char(ls); + if (!ls->expr_mode) return '\''; if (ls->current == '\\') { next_char(ls); @@ -557,6 +565,7 @@ lex(Eo_Lexer *ls, Eo_Token *tok) return TOK_CHAR; case '.': next_char(ls); + if (!ls->expr_mode) return '.'; if (!isdigit(ls->current)) return '.'; eina_strbuf_reset(ls->buff); eina_strbuf_append_char(ls->buff, '.'); @@ -570,7 +579,7 @@ lex(Eo_Lexer *ls, Eo_Token *tok) next_char(ls); continue; } - else if (isdigit(ls->current)) + else if (ls->expr_mode && isdigit(ls->current)) { eina_strbuf_reset(ls->buff); read_number(ls, tok); diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h index c2572b4069..67485ee148 100644 --- a/src/lib/eolian/eo_lexer.h +++ b/src/lib/eolian/eo_lexer.h @@ -145,6 +145,9 @@ typedef struct _Eo_Lexer /* this is jumped to when an error happens */ jmp_buf err_jmp; + /* whether we allow lexing expression related tokens */ + Eina_Bool expr_mode; + /* saved context info */ Eina_List *saved_ctxs; diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index 4e6fb02ef2..3e2f635a66 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -830,8 +830,10 @@ parse_return(Eo_Lexer *ls, Eina_Bool allow_void) if (ls->t.token == '(') { int line = ls->line_number, col = ls->column; + ls->expr_mode = EINA_TRUE; eo_lexer_get(ls); ret->default_ret_val = parse_expr(ls); + ls->expr_mode = EINA_FALSE; check_match(ls, ')', '(', line, col); } if (ls->t.kw == KW_at_warn_unused) diff --git a/src/tests/eolian/data/complex_type.eo b/src/tests/eolian/data/complex_type.eo index 66652e5317..1a9a670b07 100644 --- a/src/tests/eolian/data/complex_type.eo +++ b/src/tests/eolian/data/complex_type.eo @@ -2,7 +2,7 @@ class Complex_Type { properties { a { set { - return: own(Eina.List*)<Eina.Array*<own(Eo**)> >; + return: own(Eina.List*)<Eina.Array*<own(Eo**)>>; } get { } |