Page 2 of 2

Re: Parsing scripts for comments

Posted: Fri Apr 09, 2021 7:32 am
by kdjanz
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?

Re: Parsing scripts for comments

Posted: Fri Apr 09, 2021 8:13 am
by Thierry
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

Re: Parsing scripts for comments

Posted: Fri Apr 09, 2021 8:22 am
by stam
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!

Re: Parsing scripts for comments

Posted: Sat Apr 10, 2021 5:35 am
by Thierry
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