forked from enlightenment/efl
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.
This commit is contained in:
parent
ed28ee6aff
commit
1be7656af6
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue