Some regex for Decorate > Zscript conversion

Handy guides on how to do things, written by users for users.

Moderators: GZDoom Developers, Raze Developers

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.
Post Reply
User avatar
Jekyll Grim Payne
 
 
Posts: 1065
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Some regex for Decorate > Zscript conversion

Post by Jekyll Grim Payne »

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 all

(?i)(^actor)(\s+?\w+?$)
Replace:

Code: Select all

Class$2 : Actor
Find:

Code: Select all

(?i)^actor(\s+?.+?$)
Replace:

Code: Select all

Class$1
Find:

Code: Select all

(?i)^\s*(?!states|Class)\w([^\}\{:]|::|\w:\w)+?$
Replace:

Code: Select all

$0;
Find:

Code: Select all

(?i)^Class(.|\s)+?\n\{
Replace:

Code: Select all

$0\nDefault \{
Find:

Code: Select all

(?i)(Default \{)((.|\s)+?)(states|\})
Replace:

Code: Select all

$1$2\t\}\n$4
Find:

Code: Select all

(?i)A_ChangeFlag[^"]+"(\w+)",(\w+).+?$
Replace:

Code: Select all

\{ 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 9:13 am, edited 1 time in total.
Diode
Posts: 53
Joined: Mon Feb 29, 2016 2:34 pm

Re: Quick regex for Decorate > Zscript conversion

Post by Diode »

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.
User avatar
Jekyll Grim Payne
 
 
Posts: 1065
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Quick regex for Decorate > Zscript conversion

Post by Jekyll Grim Payne »

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 all

offset\((-*?\w+?),(-*?\w+?)\);
replace with:

Code: Select all

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.
Post Reply

Return to “Tutorials”