Regex

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Regex

Post by trevordevore » Fri Feb 06, 2015 3:05 am

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
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

benjibeaumont
Livecode Staff Member
Livecode Staff Member
Posts: 53
Joined: Tue Jun 03, 2008 10:31 am

Re: Regex

Post by benjibeaumont » Fri Feb 06, 2015 2:40 pm

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
Ben Beaumont | Runtime Revolution

benjibeaumont
Livecode Staff Member
Livecode Staff Member
Posts: 53
Joined: Tue Jun 03, 2008 10:31 am

Re: Regex

Post by benjibeaumont » Fri Feb 06, 2015 2:44 pm

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
Ben Beaumont | Runtime Revolution

benjibeaumont
Livecode Staff Member
Livecode Staff Member
Posts: 53
Joined: Tue Jun 03, 2008 10:31 am

Re: Regex

Post by benjibeaumont » Fri Feb 06, 2015 3:03 pm

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
Ben Beaumont | Runtime Revolution

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Regex

Post by trevordevore » Fri Feb 06, 2015 3:06 pm

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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

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

Re: Regex

Post by LCMark » Fri Feb 06, 2015 3:23 pm

@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.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Regex

Post by trevordevore » Fri Feb 06, 2015 3:52 pm

@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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

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

Re: Regex

Post by LCMark » Fri Feb 06, 2015 3:59 pm

@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.

livecodeian
Posts: 10
Joined: Mon Apr 22, 2013 3:29 pm
Location: Edinburgh
Contact:

Re: Regex

Post by livecodeian » Tue Feb 10, 2015 12:22 pm

@trevordevore - sorry Trevor, I haven't been able to reproduce that error. LiveCode builds fine for me from a clean checkout from git.
Ian Macphail, LiveCode Ltd.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Regex

Post by trevordevore » Tue Feb 10, 2015 8:18 pm

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?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Regex

Post by trevordevore » Fri Feb 13, 2015 3:05 pm

@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?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

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

Re: Regex

Post by LCMark » Fri Feb 13, 2015 5:28 pm

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.

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

Re: Regex

Post by LCMark » Fri Feb 13, 2015 5:36 pm

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!

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Regex

Post by trevordevore » Fri Feb 13, 2015 7:06 pm

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!
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

peter-b
Posts: 182
Joined: Thu Nov 20, 2014 2:14 pm
Location: LiveCode Ltd.

Re: Regex

Post by peter-b » Sat Feb 14, 2015 7:56 pm

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.
LiveCode Open Source Team — @PeterTBBrett — peter.brett@livecode.com

Post Reply

Return to “LiveCode Builder”