Author Topic: Color Coding Embedded  (Read 2716 times)

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Color Coding Embedded
« on: May 16, 2018, 04:11:12 PM »
I was looking at Embedded and found a problem.
Goto Tools > Options > Languages > Web Authoring Languages > PHP > Color Coding.
Select the Embedded tab.
Select a different langauge

Now PHP ColorCoding is marked as changed, but I changed nothing.
This happens for a number of different languages.


I was looking for an example that uses these options, and found none.
I suspect the phony change is really a problem with populating the controls in this tab of CC options.

In Python3 you can have a string like
x = 6
f"The value of x is {x}"

The stuff inside {} is a python expression -- I was looking to see if I could make Slick recognize this and color it properly.


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Color Coding Embedded
« Reply #1 on: May 19, 2018, 03:21:12 PM »
Interesting. Python doesn't seem to handle interpolated strings like other languages.

Here's some Scala code:
Code: [Select]
    var x=1;
    println(f"x=${x+1}");
    println(f"string expresssion=${"some string"}");

Similar python code:
Code: [Select]
    x = 1
    print(f"x={x+1}\n")
    # This python string won't compile
    print(f"string expression={"1"}\n")

We can change the Python string color coding to color interpolated strings for Python too. If we do, it will correctly color code example print string 1 but not the second one (which won't compile anyway so maybe it doesn't matter). I think this is why we didn't bother. Python really parses the entire string first and then processes replacements which is not what most languages with interpolated strings do.

We will look into the config modify issue.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Color Coding Embedded
« Reply #2 on: May 20, 2018, 02:19:02 AM »
Added a hot fix for the config modify issue which will be available in the next hot fix build.

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: Color Coding Embedded
« Reply #3 on: May 20, 2018, 05:35:38 AM »
WRT python strings: I'm not sure what you are getting at.
Why use the { }, but then also have the double quotes? "Hello {" expr "} World"
For instance, this works - by keeping the value inside the string
Code: [Select]
print(f"string expression={1}\n")
What you showed looks to me like SlickC style - implicit concat, I didn't know other languages that do it that way:
Code: [Select]
print(f"string expression={"1"}\n")
In java you might do
Code: [Select]
String a = "Hello" + str(5) + "World";
While the same in SlickC is
Code: [Select]
_str a = "Hello" 5 "World";
And it my latest language I've been working in, "R" (really powerful, yet oh, so ugly)
Code: [Select]
a = paste("Hello", 5, "World", sep = "")

Certainly python strings are screwy in other ways, so I'm willing to believe that they are messed up in this way to.
The one that irritates me the most is that backslash (\) kind-of escapes a quote inside of a raw string.
Code: [Select]
a=R"abc\def"     # A is 7 characters - as expected
a=R"abc\"def"    # A is 8 characters - as expected
a=R"abc\"def\"   # Syntax error - that last quote is escaped! (WTF?)
« Last Edit: May 20, 2018, 05:40:52 AM by jporkkahtc »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Color Coding Embedded
« Reply #4 on: May 20, 2018, 01:50:32 PM »
My point is that the parsing of interpolated strings isn't the typical way this is done. Which means, that the way SlickEdit typically parses interpolated strings when color coding isn't quite right for Python.

Python takes a more simple approach. First, you parse the entire string as if there is no interpolation. Then you look for interpolations inside the string and parse them. Scala and many others do not parse interpolated strings this way. We can add support for interpolated strings to Python similarly to the way it's done for say Scala but only because Python won't compile problem cases (where SlickEdit will have no idea there's a syntax error).

SlickEdit also has a tagging parser for Python but no change is needed there since interpolation can be ignored.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Color Coding Embedded
« Reply #5 on: May 20, 2018, 02:07:59 PM »
I've written parsers for many languages. Overall, Python is a very well designed language. However, Python should have done a better job coming up with the syntax for string literals. You noted the problem with a trailing backslash in a string (like a Windows path). Yep that's a stupid problem. When I mentioned this to the developers of Python in a nice way on one of their forums, they attacked me (wasn't pretty). I guess supporting Windows paths isn't important to them.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6864
  • Hero Points: 528
Re: Color Coding Embedded
« Reply #6 on: May 20, 2018, 03:03:59 PM »
Here are some of the languages that support interpolated strings the way they are typically done:

Scala, Groovy, JavaScript, Kotlin, Puppet, Ruby, Swift

Parsing for a typical interpolated string is done like this:

* parse until start interpolation token (often '${')
* Now tokenize what's inside until the end interpolation token (often '}').
* After that, continue to parse the rest of the string.

This has to be done recursively because you can have an interpolated string inside of an interpolated string.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: Color Coding Embedded
« Reply #7 on: May 20, 2018, 03:11:40 PM »
@Clark: It‘s a shame that they didn’t play nice. There is just too much arrogance and ignorance :(
HS2