Parsing scripts for comments

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Parsing scripts for comments

Post by kdjanz » Fri Apr 09, 2021 7:32 am

The first message on https://forums.livecode.com/viewtopic.php?f=7&t=35686 shows what the nodes look like when first analyzed. I have to manually untangled them using the code for moving the nodes that I posted there.

I would love to see an algorithm to layout the nodes automatically to remove the crossings of the dependency lines. The manual move part of this problem is solved - now I’m looking for intelligent sorting and moving.

Suggestions?

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Parsing scripts for comments

Post by Thierry » Fri Apr 09, 2021 8:13 am

stam wrote:
Thu Apr 08, 2021 5:38 pm
Ah, that makes sense...
Hello Stam,

Behind the scene, what makes sense is that we must catch strings
to be able to match comments without false positives.
Then the only way, AFAIK is to redirect strings patterns and comments patterns in 2 different slots.
This is doable by using back references in the replacement text.

Now, getting rid off all comments is as simple as that:

Code: Select all

on fun aStr, aComment
   if aStr is not empty then  return aStr
   return empty
end fun

....

      if sunnYreplace( T, rex, "?{ fun \1 \2 }", newTxt) then
         put newTxt into fld "Fout"
      else
         put "no match: "  into fld "Fout"
      end if
and the result:

screenshot 2021-04-09.jpg


Happy coding,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Parsing scripts for comments

Post by stam » Fri Apr 09, 2021 8:22 am

Thierry wrote:
Fri Apr 09, 2021 8:13 am
Behind the scene, what makes sense is that we must catch strings to be able to match comments without false positives.
Thanks once again Thierry.
I was thinking I’d need to put the text into a container, delete all text within quotes then do a regex search for all the different comment structures... by as usual you put it much more elegantly and succinctly!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Parsing scripts for comments

Post by Thierry » Sat Apr 10, 2021 5:35 am

stam wrote:
Fri Apr 09, 2021 8:22 am
as usual you put it much more elegantly and succinctly!
and after a long sleep and a nice coffee, I end up with this one-liner.
Still the same regex.

Code: Select all

   -- Parsing scripts for comments
   
   if sunnYreplace( fld "IN", rex, "\1", newTxt) then \
           put newTxt into fld "OUT"
           
As often, having a break after a long period of pure coding,
and coming back later open up our mind...

Kind regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”