[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reserved words as table index names. (Was [ANN] Lua BitOp 1.0.1 released)
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 7 Jan 2009 13:04:12 -0200
> I wonder how hard it would be to change the parser so that when a
> table is being indexed with . or :
You can do it easily with token filters. Attached is a token filter written
in C that does that for '.' (but can easily be adapted to handle ':').
--lhf
/*
* proxy.c
* lexer proxy for Lua parser -- allows reserved words as field names
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
* 20 Feb 2008 11:48:00
* This code is hereby placed in the public domain.
* Add <<#include "proxy.c">> just before the definition of luaX_next in llex.c
*/
#define LAST_RESERVED TK_WHILE
static int nexttoken(LexState *ls, SemInfo *seminfo)
{
static int last=TK_EOS;
int t=llex(ls,seminfo);
if (last=='.' && t>=FIRST_RESERVED && t<=LAST_RESERVED) {
seminfo->ts = luaS_new(ls->L, luaX_tokens[t-FIRST_RESERVED]);
return TK_NAME;
}
last=t;
return t;
}
#define llex nexttoken