lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


A bug fix to the published lexer proxy:

On Fri, 11 May 2007 11:28:17 -0300, Luiz Henrique de Figueiredo wrote:
Find attached a simple proxy.c that removes all calls to assert,
but only calls to assert.
...
static int nexttoken(LexState *ls, SemInfo *seminfo)
{
 for (;;) {
	int n;
	int t=llex(ls,seminfo);
	if (t!=TK_NAME) return t;
	if (strcmp(getstr(seminfo->ts),"assert")!=0) return t;
	t=llex(ls,&ls->lookahead.seminfo);
	if (t!='(') {
		ls->lookahead.token = t;
		return TK_NAME;
	}
	for (n=1; n>0; ) {
		t=llex(ls,seminfo);
		if (t==TK_EOS) return t;
		if (t=='(') n++;
		if (t==')') n--;
	}
 }

This proxy fails on:

x = assert
assert()

because it does not recursively check for "assert" statements.
The fix is simple and straight forward:

...
    if (strcmp(getstr(seminfo->ts),"assert")!=0) return t;
    t=nexttoken(ls,&ls->lookahead.seminfo);
    if (t!='(') {
...

Thanks for this useful lexer proxy,

Ronald