[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua AST and Parsing a "C" Like language
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Tue, 23 Aug 2011 09:49:41 +0200
On 23/08/2011 0.15, HyperHacker wrote:
On Mon, Aug 22, 2011 at 16:07, Axel Kittenberger<axkibe@gmail.com> wrote:
[...]
IMPORT WIDGET mywidget
{
REFINE widget_name{
REDEFINE TITLE "Your widget";
}
}
[...]
....how exactly are statements like "IMPORT WIDGET" made into valid Lua code?
It is not valid, to my knowledge. The closer I can come is:
-----------------------------------------------
local function data_handler( data_table )
print( "data " .. tostring( data_table ) )
end
-- action marker tables:
WIDGET = {}
ACTIONS = {
[ WIDGET ] = function( widget_id )
print( "importing widget: " .. widget_id )
return data_handler
end
}
function IMPORT( action_marker )
local action = ACTIONS[ action_marker ]
if not action then error "unknown action!" end
return action
end
-- Here comes the content of the "config files"
IMPORT(WIDGET) "mywidget"
{
-- do the same for the inner stuff
}
IMPORT(STUFF) "great stuff!" { } --> error! unknown action!
---------------------------------------------------------------------
But it seems a bit overcomplicated. For simple configuration needs I
find Lua syntax already powerful as it is, without too much magic. Of
course it depends on the level of expertise of who will be editing those
files: if users are non-programmers more safety-nets and "syntax
simplification layers" may be useful.
cheers.
-- Lorenzo