[802] in Coldmud discussion meeting
MOO Verb -> ColdC Method
daemon@ATHENA.MIT.EDU (Sun Sep 10 17:05:19 1995
)
Date: Sun, 10 Sep 1995 15:04:33 -0600
From: 869683 Gillespie Brandon James <brandon@smithfield.declab.usu.edu>
To: coldstuff@MIT.EDU
In the wee morning hours of last night, I started to hack up a MOO->ColdC
convertor. It currently does everything, including some buildint function
conversions, up to the point where I got sick of doing it (about at
property/verb MOO builtins).
This is NOT intended as a direct conversion utility, you WILL have to
still do some cleanup/rewrites. However, if it helps lure some of the MOO
crowd over, yipee :)
-------------------------------
moo2coldc
#!/u2/consultants/brandon/bin/p
while (<>) {
# get comments out of the way...
(s/^(\s*)\"\s*(.*)\s*\"\;/$1\/\/ $2/) && print && next;
# Fix lists first...
s/\{/[/g;
s/\}/]/g;
# if we know it will only match once, continue
(s/^(\s*)else$/${1}} else {/) && print && next;
(s/^(\s*)(endif|endfor|endwhile)/${1}}/) && print && next;
# control .. things (man am I up too late)
s/^(\s*)if\s+\((.*)\)\s*/${1}if ($2) {\n/;
s/^(\s*)elseif\s+\((.*)\)/${1}} else if ($2) {/;
s/^(\s*)for\s+([a-z_\*])\s+in\s+([\(\[].*[\)\]])\s*/${1}for $2 in $3 {\n/;
s/^(\s*)while\s+\((.*)\)\s*/${1}while ($2) {\n/;
# change 'this' to nothing, fix properties
s/this:/./g;
s/this\.//g;
# change obj:verb to obj.method, fix property refs by making them methods
s/([a-z_\*]+)\.([a-z_\*]+)/$1.$2()/gi;
s/([a-z_\*]+):([a-z_\*]+)/$1.$2/gi;
# handle subrange syntax, this doesn't get assignment subranges
s/([a-z_\*]+)\[([0-9]+)\.\.([0-9]+)\]/${1}.subrange(${2}, ${3})/gi;
# do basic function conversions...
s/typeof\(/type\(/g;
s/tonum\(/toint\(/g;
s/length\((.*)\)/${1}.length()/g;
s/rindex\((.*)\)/${1}.rindex()/g;
s/match\(/match_regexp(/g;
s/rmatch\(/match_regexp(/g;
s/substitute\((.*),\s*(.*)\)/${1}.regexp\(/g;
s/listinsert\(/insert(/g;
s/listappend\(/append(/g;
s/listdelete\(/delete(/g;
s/listset\(/replace(/g;
s/chparent\((.*),\s*(.*)\)/${1}.chparents(${2})/g;
s/parent\((.*)\)/${1}.parents()/g;
s/children\((.*)\)/${1}.children()/g;
s/recycle\(/destroy(/g;
s/max_object\(/next_dbref(/g;
s/move\((.*)\)/${1}.move_to()/g;
## properties/verbs are not the same, PAY ATTENTION
s/properties\((.*)\)/${1}.parameters()/g;
s/properties\((.*)\)/${1}.parameters()/g;
## Bad
# s/players\(\)//g;
print;
}