Author Topic: Help with interpolated string coloring  (Read 439 times)

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Help with interpolated string coloring
« on: March 07, 2021, 10:49:38 pm »
I am a long time SE user but not one who updates frequently.  I only recently upgraded to 25.0 from 18 (yeah, I know... I suck ::)).

Anyway, a lot of my work is in scheduling and automating a multitude of jobs for which I do a lot of editing of Windows batch files (JPSoft's Take Command files actually).  The new syntax coloring capabilities in the new version are much better than the older version and I've been able to set up the coloring, using regular expressions, to cover almost all that I need, including the enhanced options in Take Command.  But I haven't been able to get the Sub Item option to work for interpolated strings and could use some help.

Specifically, I would like to treat almost everything following an ECHO command to be colored as a string (since essentially that's what it is).  I have been able to set up ECHO as a keyword and have everything following, up to the end of the line or a > symbol, colored as a string (everything from a > symbol to the end of line is highlighted as a redirection).  The thing I can't seem to get to work is having anything in that string starting with a % (an environment variable) colored to stand out as a variable.

I set up a string definition with a starting delimiter of (?<=ECHOS?) +.+ to start a string following ECHO or ECHOS.  That part seems to work.  Then I add a sub item with %[a-zA-Z0-9_]* but that doesn't seem to work even though the regex itself tests out fine.

Can someone steer me to what I'm doing wrong?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5702
  • Hero Points: 457
Re: Help with interpolated string coloring
« Reply #1 on: March 08, 2021, 04:16:05 pm »
If I'm reading what you done, only an item with a start AND an end can make use of subitems. You've only specified a start delimiter. There needs to be an end. What's inbetween the start and the end will apply sub-items.

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #2 on: March 09, 2021, 08:12:31 pm »
But can't the end be a word delimiter (usually a space but sometimes a second '%')?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5702
  • Hero Points: 457
Re: Help with interpolated string coloring
« Reply #3 on: March 09, 2021, 09:00:51 pm »
I'm not following you.  It looks like you've specified a start delimiter which is a regex which includes the entire string and not just "echo".

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #4 on: March 09, 2021, 09:59:06 pm »
The echo definition as a keyword uses the Perl regex ECHO\.?S?.  This covers ECHO ECHO. and ECHOS as keywords.  Then I have an additional definition as a string using the regex (?<=ECHOS?) +[^<>]+ which anchors at the starting echo using lookbehind but doesn't include it in the coloring.  This colors anything following ECHO or ECHOS as a string up to the end of the line or a redirection character < or >.  If there is a redirection character, everything following is colored as an operator (bold).

This all works fine.  The starting ECHO is colored as a keyword and all the text from there to either the end of the line or a redirection character is colored as a string.  What I can't figure out is how to have environment variables (or Take Command's variables and functions) all of which start with a % character and end either at the end of the line, at another % character (some people still use the old format %variable%) or at a word border such as a space or tab. 

It seems that no matter what I try as the sub item definition, the entire line remains colored as a string.  I tried %[a-zA-Z0-9_]+ which works fine in the regex evaluator but does nothing for changing the coloring.  I'm sure I'm doing something wrong somewhere but the documentation doesn't offer much guidance in this area.  It's obvious that the regex setting is not the only thing necessary to get the string parsed for variables but I don't know what I'm missing.

I hope I have explained a little better.  Any assistance greatly appreciated.

EDIT:
As an example, my current setup colors like this:
echo Job run %date at %time >>process.log

I would like it to look like this:
echo Job run %date at %time >>process.log

« Last Edit: March 09, 2021, 10:14:46 pm by cthomson »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5702
  • Hero Points: 457
Re: Help with interpolated string coloring
« Reply #5 on: March 09, 2021, 10:28:20 pm »
post a picture of the dialog and the settings for the start and end search strings. I don’t need to see any sub item definition.

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #6 on: March 09, 2021, 11:01:51 pm »
Image attached...

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5702
  • Hero Points: 457
Re: Help with interpolated string coloring
« Reply #7 on: March 09, 2021, 11:13:42 pm »
It’s like I thought. The start needs to match “echo” or “echos” and not include anything else. You can specify a different color for the start delimiter and the text inbetween the start and end. Then you need to define the end to be a look ahead match for end of line or not some set of characters.

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #8 on: March 09, 2021, 11:23:27 pm »
So the start should be just the starting delimiter and not include the matching of what actually constitutes the string portion? Then the end would be end of line or a redirection character? Do I use \r\n as the end of line character set?

I'll give it a try when I'm back at the computer in the morning.

Thanks for your help!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5702
  • Hero Points: 457
Re: Help with interpolated string coloring
« Reply #9 on: March 09, 2021, 11:54:08 pm »
Be sure to use $ as a match in the end. It’s fine if you use \r and \n but they are typically not there even when one is present in your code. Not totally intuitive I know.

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #10 on: March 10, 2021, 12:01:13 am »
Ahhh... very good information. Thanks again.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5702
  • Hero Points: 457
Re: Help with interpolated string coloring
« Reply #11 on: March 10, 2021, 12:11:33 am »
Also, keep in mind there are already definitions for "echo" and "echos". You can just delete them and add your own for both. That's probably the easiest way to go.

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #12 on: March 10, 2021, 12:16:50 am »
Yup, that part is already done.

cthomson

  • Community Member
  • Posts: 38
  • Hero Points: 1
Re: Help with interpolated string coloring
« Reply #13 on: March 10, 2021, 01:52:39 pm »
It works!

Thanks again!