[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: What would you recommend as best way to translate Lua to Esperanto
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 20 Jun 2016 10:50:39 -0300
> 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". But replacing the token in luaX_tokens won't do the job :
> lupa> se vera == vera tiam print('ververa') hop
> 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
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:
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.