lua-users home
lua-l archive

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


> Another option would be token filtering, but that is something of an
> arcane art to me at this point. :-)

Find attached a simple proxy.c that removes all calls to assert,
but only calls to assert. If you want to keep a call to assert,
include it in parentheses, as in 
	x=(assert)(a(),b())

On this input:

 a=1 assert(a(),b()) b=2 assert(a(),b()) assert(a(),b()) c=3 a={assert=0}
 d=4 assert x e=5 assert=8 f=6 a=assert g=7 x=(assert)(a(),b()) z=9

the parser will see this:

 a=1 b=2 c=3 a={assert=0} d=4 assert x e=5 assert=8 f=6 a=assert g=7
 x=(assert)(a(),b()) z=9

To use proxy.c, just put it in the src directory, change 1 line in llex.c
and rebuild. The one line is just <<#include "proxy.c">> before the
definition of luaX_next in llex.c.

proxy.c is an example of token filter written in C. We had a discussion about
this in the past...
--lhf
/*
* proxy.c
* lexer proxy for Lua parser -- implements assert removal
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
* 11 May 2007 11:18:57
* This code is hereby placed in the public domain.
* Add <<#include "proxy.c">> just before the definition of luaX_next in llex.c
*/

#include <string.h>

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--;
	}
 }
}

#define llex nexttoken