Some regex for Decorate > Zscript conversion

Handy guides on how to do things, written by users for users.
Forum rules
Please don't start threads here asking for help. This forum is not for requesting guides, only for posting them. If you need help, the Editing forum is for you.

Some regex for Decorate > Zscript conversion

Postby Jekyll Grim Payne » Thu Aug 23, 2018 3:58 pm

Updated post:

A few regex changes that will help to bring DECORATE close to ZScript syntax with a few simple modifications.

You'll need Notepad++ for that.

Paste your code in Notepad++ and perform the following operations one by one using Regex mode in Search & Replace:

Find:
Code: Select allExpand view
(?i)(^actor)(\s+?\w+?$)

Replace:
Code: Select allExpand view
Class$2 : Actor


Find:
Code: Select allExpand view
(?i)^actor(\s+?.+?$)

Replace:
Code: Select allExpand view
Class$1


Find:
Code: Select allExpand view
(?i)^\s*(?!states|Class)\w([^\}\{:]|::|\w:\w)+?$

Replace:
Code: Select allExpand view
$0;


Find:
Code: Select allExpand view
(?i)^Class(.|\s)+?\n\{

Replace:
Code: Select allExpand view
$0\nDefault \{


Find:
Code: Select allExpand view
(?i)(Default \{)((.|\s)+?)(states|\})

Replace:
Code: Select allExpand view
$1$2\t\}\n$4


Find:
Code: Select allExpand view
(?i)A_ChangeFlag[^"]+"(\w+)",(\w+).+?$

Replace:
Code: Select allExpand view
\{ b$1 \= $2 \};



And then do the minor things like replacing "" with "none", etc.

Someone with actual programming experience could turn it into a quick converter. (Maybe I'll be able to do it later my self)
Last edited by Jekyll Grim Payne on Fri Oct 12, 2018 10:13 am, edited 1 time in total.
User avatar
Jekyll Grim Payne
 
Joined: 21 Jul 2008

Re: Quick regex for Decorate > Zscript conversion

Postby Diode » Wed Sep 05, 2018 8:09 am

That's really good to know!

I can't wait to forget it like I do every other regex I've ever needed, and then spend more time trying to figure out/find the regex for a given task than it would take me to do it manually.
Diode
 
Joined: 29 Feb 2016

Re: Quick regex for Decorate > Zscript conversion

Postby Jekyll Grim Payne » Mon Oct 08, 2018 3:10 pm

I figured I should make more... I'll stick it into this thread for now and maybe I'll clean it up into one post later.

A regex to quickly change all old "offset" keyword definitions into a nice interpolated A_WeaponOffset:

search for:
Code: Select allExpand view
offset\((-*?\w+?),(-*?\w+?)\);


replace with:
Code: Select allExpand view
A_WeaponOffset\($1.0,$2.0,WOF_INTERPOLATE\);



That semicolon is optional, however please note that offset is a keyword so it can be used in the same string as a function, while A_WeaponOffset can't (it has to be an anonymous function). In ZScript that semicolon will tell that there are no functions after the offset keyword. I haven't written a regex yet that will create anonymous functions as needed as well.
User avatar
Jekyll Grim Payne
 
Joined: 21 Jul 2008


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest