[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Begin/End Proposal
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sat, 3 Oct 2009 00:04:07 -0300
> In a recent thread [1], I brought up the concept of a 'begin' keyword
> that can be used to create anonymous, argument-less functions.
Here a token filter in C that does that. Enjoy.
/*
* proxy.c
* lexer proxy for Lua parser -- implements 'begin' as sugar for 'function ()'.
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
* 02 Oct 2009 23:59:54
* 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)
{
static int state=0;
int t;
if (state==1) {
state=2;
return '(';
}
else if (state==2) {
state=0;
return ')';
}
t=llex(ls,seminfo);
if (t==TK_NAME && strcmp(getstr(seminfo->ts),"begin")==0) {
t=TK_FUNCTION;
state=1;
}
return t;
}
#define llex nexttoken