ReplaceText: back refs in replacement string

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller, LCMark

Post Reply
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

ReplaceText: back refs in replacement string

Post by Thierry » Wed Oct 09, 2013 10:49 am

Hi,

For those liking regex, here is one nice feature missing:

put replaceText( "aaa bbb", "(\w+)\s+(\w+)", "\2\1")
--> bbb aaa

As we can already use back references in our regex (2nd parameter),
I think keeping the same syntax is fine : \1, \2, ...

Well, guess it's enough for a start :)

Any thoughts on this?

Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1561
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: ReplaceText: back refs in replacement string

Post by monte » Wed Oct 09, 2013 11:00 pm

You're making me want to brush up on my RegEx Thierry
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: ReplaceText: back refs in replacement string

Post by Thierry » Thu Oct 10, 2013 5:03 am

monte wrote:You're making me want to brush up on my RegEx Thierry
<g>
Please, don't.
I wouldn't like to feel responsible for any brain damage..
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: ReplaceText: back refs in replacement string

Post by LCMark » Mon Oct 14, 2013 9:29 am

@Thierry: This would be a neat addition... The only thing I'd suggest is making it a different function name for handling 'patterns' in the replacement string - maybe replaceTextWithPattern? This existing code that has '\n' in replacement strings will still work as expected :)

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: ReplaceText: back refs in replacement string

Post by Thierry » Mon Oct 14, 2013 10:26 am

@runrevmark I'm fine with a new function.

Just to be sure, I guess that by *This existing code*, you mean old user's code, yes?

I have more options for this function in mind.. ( inspired by the Perl substitute s/// )
Is this better to talk about all of them right now
or later when I'll be ready to code them?

And 2 more questions from a benevolent contributor:

1) is there some possibility to organize a tchat
with one of the core LC developers for very precise questions about the engine code?

2) still loosing some hair(1) trying to understand how to stay in sync with all the repos:
--- origin runrev github: livecode and thirdparty module
--- my thierrydouez github forks: livecode and thirdparty module
--- my local repos

Having a libpcre_8_33 branch on my thirdparty local and github repo,
how do I do to start working with the latest runrev develop branch?

Regards,

Thierry

(1) don't worry, no much left anyway :)
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

garyth123
Posts: 88
Joined: Sat Apr 27, 2013 11:14 am
Location: Edinburgh, Scotland
Contact:

Re: ReplaceText: back refs in replacement string

Post by garyth123 » Tue Oct 22, 2013 10:58 am

Thierry wrote: As we can already use back references in our regex (2nd parameter),
I think keeping the same syntax is fine : \1, \2, ...
So we can't use back references in LC at present?

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: ReplaceText: back refs in replacement string

Post by LCMark » Fri Oct 25, 2013 8:33 am

@Thierry: Yes - by 'the existing code', I meant existing code that uses replaceText().

Feel free to discuss any thoughts you have on options for the function and such, others might have input that will help evolve them.

In terms of your other questions...

1) This sounds like a good idea - I'll see what I can do in the near future. In the mean time, do post any queries you have here and I'll try and answer them.

2) Yes - it can get a bit tricky with all the branches and submodules floating around. It has taken me a while to get used to git (we were using subversion for a *long* time before we went open-source, the mental transition has taken a while). It seems to me that the default 'clone' option that github has is not really suitable for the work-flow we have for accepting pull-requests - the issue being we (runrev) are the only ones who write to any of the branches - it ends up with you having to remember to keep updating master and develop in your fork, which is a bit silly since they should (essentially) be read-only. Therefore I've started doing this:

Checkout my fork of livecode (runrevmark)
Delete the master / develop and any release branches locally and remotely
Add runrev/livecode.git as a remote (git add runrev https://github.com/runrev/livecode.git)
Then checkout the runrev develop / master etc. branches directly e.g. git checkout -b master runrev/master

This last step links the local master branch to the runrev master branch meaning that when you switch to it and do 'git pull', you get the latest changes - rather than having to indirect through the master branch in your fork on github.

If you want to (as you have) modify the submodules, then you can do a similar thing - change the remote repo reference in the submodule to your clone, and remap the master / develop etc. branches to point to the runrev submodule repo.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1561
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: ReplaceText: back refs in replacement string

Post by monte » Tue Oct 29, 2013 4:20 am

@runrevmark you can change the remote tracking branches using:

Code: Select all

git remote add upstream https://github.com/runrev/livecode.git
git branch -u upstream/master master
git branch -u upstream/develop develop
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: ReplaceText: back refs in replacement string

Post by LCMark » Tue Oct 29, 2013 10:27 am

@monte: I thought there might be a simpler way - thanks :)

Post Reply

Return to “Engine Contributors”