lua-users home
lua-l archive

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


> First, it looks like not all tokens defined in luaX_tokens are really
> used in the parsing. For example I wanted to translate "==" with
> "egalas"[1][2]. But replacing the token in luaX_tokens won't do the job :
> 
> lupa> se vera == vera tiam print('ververa') hop
> ververa
> lupa> se vera egalas vera tiam print('ververa') hop
> stdin:1: 'tiam' expected near 'egalas'
> 
> Any hint on what should I do?

luaX_tokens is used mostly for error messages.

If you want to create word aliases for existing tokens, create a new
array of words named luaX_alias, indexed by all tokens. Then set their
ts->extra in luaX_init and map words back to tokens in the default
case in llex. Note that you'll be able to create word aliases even for
single-byte symbols.

All error messages will use the original text for tokens. You can change
the text in luaX_tokens for multi-byte tokens such as "==" but not for
single-byte tokens. For that, you'll have to change luaX_token2str.

If you don't want symbol tokens at all, you'll need to remove the
corresponding code in llex.

You need to be careful with the details but it should work. I suggest
you start with setting up an alias "egalas" for "==" to see how it works.

If you want to prototype your translation, without touching the Lua
source code, consider using ltokenp:
	http://lua-users.org/lists/lua-l/2016-05/msg00028.html
You'll be able to map new reserved words to arbitrary text using a Lua table.
You'll also be able to reject symbolic tokens, such as "==".
And do all this coding in Lua, not in C.  
You can use ltokenp as a preprocessor for your dialect of Lua and feed
its output to lua or luac.

Have fun!