Hi,
Basically what I try to do here is convert a slice-file (
www.zeroc.com) to a C++ header file so DoxyGen can parse it without a glitch
.
So I don't care about layouting in sed... As it will be interpreted by a machine anyway
.
I have 3 questions for sed...
Let me first show the input file:
Code:
#ifndef TEST1
#define TEST1
module main
{
local interface test1
extends ext1,
ext2
{
bool function( );
idempotent bool function( );
nonmutating bool function( );
nonmutating bool function( ) throws RangeError;
nonmutating bool function( ) throws RangeError, NormalError;
nonmutating bool function( ) throws RangeError,
NormalError;
nonmutating bool function( ) throws RangeError
, NormalError;
};
};
#endif // TEST1
Now what it has to look like:
Code:
#ifndef TEST1
#define TEST1
namespace main
{
class test1
: public ext1, public
ext2
{
bool function( );
bool function( );
bool function( ) const;
bool function( ) const throw(RangeError);
bool function( ) const throw(RangeError, NormalError);
bool function( ) const throw (RangeError,
NormalError);
bool function( ) const throw (RangeError
, NormalError);
};
};
#endif // TEST1
I am trying to do this with 'sed'... Now I managed to get this script:
Code:
s/local//g
s/interface/class/g
s/extends/: public/g
s/module/namespace/g
s/sequence/vector/g
s/dictionary/map/g
/class/,/{/s/{/{public:/g
s/idempotent//g
s/nonmutating\(.*\);/\1 const;/g
now the problems I have are those:
- throws ...; -> throw(...); with support for multiple errors on multiple lines
- extends ..., ..., ... -> : public ..., public ..., public ...
- nonmutating ... () throws... -> ... () const throw...;
I have been looking around for something called 'N', but that seems like only running once, and what I need is something that even runs on multiple lines...
For (1) I need everything from 'throws' -> ';'. And then change the keyword 'throws' -> 'throw(', and the keyword ';' -> ');'. That would do this trick, but I don't know how to tell in sed.
For (2) I need to convert the extends <class>[, <class>] into : public <class>[, public <class]...
(3) is rather simple if I know how to do (1) in fact... So never mind about that one
Could someone help me with this?
Thanks!