Page 1 of 2

Regex

Posted: Fri Feb 06, 2015 3:05 am
by trevordevore
I'm trying to write a url parsing library and I'm stuck on regex. I didn't see any built in regex in LiveCode Builder so I tried to use execute script. The code I'm trying is below. The problem is I can't get anything meaningful returned from execute script If I try to return a string from the function and return tMatches["host"] then I get nothing. Ideally I'm trying to return tMatches as an array for further processing. The LiveCode Script does work in the normal IDE.

Any ideas?

Code: Select all

variable tRegex as string
put "(?#scheme)(?:^([a-zA-Z][a-zA-Z0-9\\+\\.-]*)://)?(?#username-pasword)(?:([^/:]+[:@])?([^/:]+)@)?([^/:]*)?(?#port)(:[0-9]*[^/])*(?#path)(/[^?]*)*(?#query)(\\?[^#]*)*(?#fragment)(#.*)*" into tRegex

variable tScript as string
variable tMatches as array
    
put "get matchText(pURL, tRegex, rScheme, rUsername, rPassword, rHost, rPort, rPath, rQueryString, rFragment);" into tScript
put "put rScheme into tA[\qscheme\q];put rUsername into tA[\qusername\q];put rPassword into tA[\qpassword\q];" after tScript
put "put rHost into tA[\qhost\q];put rPort into tA[\qport\q];put rPath into tA[\qpath\q];" after tScript
put "put rQueryString into tA[\qquery string\q];put rFragment into tA[\qfragment\q];return tA" after tScript
    														
-- Use 'execute script' for access to regular expressions.
execute script tScript
put the result into tMatches

Re: Regex

Posted: Fri Feb 06, 2015 2:40 pm
by benjibeaumont
Hi Trevor,

Yes, at the moment there is no regex support in LiveCode builder. This is certainly something we'll be adding.

In the mean time, your execute script method is a work around. We discovered that arrays are not being passed between LCS and LCB currently in alpha 2. Mark has applied a fix though if you are building direct through xCode. I'm not sure if it's been through code review yet so it may not have been merged into the main widgets branch yet. Feel free to pull it and test it though.

Warm regards,

Ben

Re: Regex

Posted: Fri Feb 06, 2015 2:44 pm
by benjibeaumont
Just as a followup, our intention is to wrap the pcre library once the foreign code interface is mature enough. There are a variety of other features we'll implement by wrapping libraries which are waiting on that FFI feature.

Regards,

Ben

Re: Regex

Posted: Fri Feb 06, 2015 3:03 pm
by benjibeaumont
Just as a followup, our intention is to wrap the pcre library once the foreign code interface is mature enough. There are a variety of other features we'll implement by wrapping libraries which are waiting on that FFI feature.

Regards,

Ben

Re: Regex

Posted: Fri Feb 06, 2015 3:06 pm
by trevordevore
Thanks for the info Ben. I tried compiling the develop branch with Mark's fix applied in Xcode 6.1.1 on 10.9 but I'm having trouble with lc-bootstrap-compile.

Undefined symbols for architecture i386:
"___exp10", referenced from:
_uprv_pow10_52 in libfoundation.a(putil.ao)

I'm trying to track down the cause but if anyone has any ideas, please let me know.

Re: Regex

Posted: Fri Feb 06, 2015 3:23 pm
by LCMark
@trevordevore: I've not seen that issue before - try doing a 'Clean' and rebuilding (in case it is stale code) and check the SDK version being compiled against is 10.8.

Re: Regex

Posted: Fri Feb 06, 2015 3:52 pm
by trevordevore
@runrevmark - no luck. I'll fiddle with this some more over the weekend and see if I can figure out why it won't compile.

Re: Regex

Posted: Fri Feb 06, 2015 3:59 pm
by LCMark
@trevordevore: @runrevian has the same setup as you (6.1.1 and 10.9) but seems to be compiling it fine - however, I've asked him to check out a completely fresh livecode repo and submodules and rebuild develop from scratch to see if he sees the same issue.

Re: Regex

Posted: Tue Feb 10, 2015 12:22 pm
by livecodeian
@trevordevore - sorry Trevor, I haven't been able to reproduce that error. LiveCode builds fine for me from a clean checkout from git.

Re: Regex

Posted: Tue Feb 10, 2015 8:18 pm
by trevordevore
Thanks for testing @livecodeian. I just tried reinstalling Xcode but still no luck. Should any changes need to be made to the base Xcode install with the development branch? We don't need the Xcode 3 stuff installed as per the instructions I made when the engine was first posted on github, do we?

Re: Regex

Posted: Fri Feb 13, 2015 3:05 pm
by trevordevore
@livecodeian or @runrevmark - what is the default compiler on your system? Should the engine be compiling with Apple LLVM 6.0 or GCC 4.2?

Re: Regex

Posted: Fri Feb 13, 2015 5:28 pm
by LCMark
The engine should happily compile with all recent Xcode versions (since we switched to Cocoa and dropped PPC).

My default compiler comes out as LLVM 5.1 - Ian's comes out as LLVM 6.0 (this is for both the LiveCode-Community target and lc-bootstrap-compile).

We don't override the compiler options in any of the xcodeproj's as far as I'm aware so something odd is going on somewhere.

Re: Regex

Posted: Fri Feb 13, 2015 5:36 pm
by LCMark
Think I might have a suggestion for a solution...

I was puzzled by 'putil.ao' as there is no file like that in libfoundation *but* I'd forgotten that libfoundation is linked with ICU and libffi so that things depending on it don't have to. So - I think the problem is that you need to update your mac libs...

cd prebuilt
sh fetch-libraries.sh

This should update your local copies (in particular for Mac) and then hopefully things will be happy!

Re: Regex

Posted: Fri Feb 13, 2015 7:06 pm
by trevordevore
Now I'm cooking with gas!

The only change I had to make was to pass in 'mac' as a param to fetch-libraries.sh

sh fetch-libraries.sh mac

Otherwise I got this output and building wouldn't work:

mac linux win32 android ios
fetch-libraries.sh: line 73: ${ARCHS_mac linux win32 android ios[@]}: bad substitution
fetch-libraries.sh: line 74: ${LIBS_mac linux win32 android ios[@]}: bad substitution
fetch-libraries.sh: line 75: ${SUBPLATFORMS_mac linux win32 android ios[@]}: bad substitution
Fetching library: OpenSSL-1.0.1g-All-Universal-Headers
Extracting library: OpenSSL-1.0.1g-All-Universal-Headers
Fetching library: ICU-52.1-All-Universal-Headers
Extracting library: ICU-52.1-All-Universal-Headers

Thanks Mark!

Re: Regex

Posted: Sat Feb 14, 2015 7:56 pm
by peter-b
trevordevore wrote:The only change I had to make was to pass in 'mac' as a param to fetch-libraries.sh

sh fetch-libraries.sh mac

Otherwise I got this output and building wouldn't work:

mac linux win32 android ios
fetch-libraries.sh: line 73: ${ARCHS_mac linux win32 android ios[@]}: bad substitution
fetch-libraries.sh: line 74: ${LIBS_mac linux win32 android ios[@]}: bad substitution
fetch-libraries.sh: line 75: ${SUBPLATFORMS_mac linux win32 android ios[@]}: bad substitution
Urgh, my bug. I'll fix on Monday.