From: Yves G. <yc....@wa...> - 2008-08-02 22:25:33
|
I have just added to convert.pl some tools to help the mechanization. They make possible some complex replacements without having to use too much perl. I changed the QVBox/QHBox related code in convert.pl to use these new tools. You can now do what all my perl code was doing only by writing something like : { my $p = Process->new($code); $p->trigger('QHBox * ${hbox} = new QHBox ( ${parent} ) ;'); $p->replacement('QWidget *${hbox} = new QWidget(${parent});'); $p->replacement('QHBoxLayout ${hbox}Layout = new QHBoxLayout;'); $p->target('${widget} * ${child} = new ${widget} ( @{before,} ${hbox} @{,after} ) ;', "A"); $p->replacement('${widget} *${child} = new ${widget}(@{before,} ${hbox} @{,after});'); $p->replacement('${hbox}Layout->addWidget(${child});'); $p->addAfterLast("A", '${hbox}->setLayout(${hbox}Layout);'); $code = $p->exec(); } Trigger function defines a C++ group of words to replace. Replacement function defines by what the precedent group shall be replaced Variable names (${hbox}, ${parent}) contains what is specific to the replaced group and can be used in the replacement strings. Target/Replacement functions works as Trigger/Replacement, but are used only if trigger string has been found and can use variable defined in trigger. addAfterLast function can be used to add some strings after a group of replacements (probably not very useful). More complete explanations on how to use theese tools can be found at the beginning of mechanization_tools.pm file. Looking at the QHBox/QVBox conversion as an exemple may also be useful. Please, forgive the terminology trigger/target, etc... which is maybe not very appropriate. Hoping these tools can be of some help. Yves |