SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: jporkkahtc on May 16, 2018, 04:11:12 pm

Title: Color Coding Embedded
Post by: jporkkahtc 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.

Title: Re: Color Coding Embedded
Post by: Clark 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"string expresssion=${"some string"}");

Similar python code:
Code: [Select]
    x = 1
    # 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.
Title: Re: Color Coding Embedded
Post by: Clark 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.
Title: Re: Color Coding Embedded
Post by: jporkkahtc 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?)
Title: Re: Color Coding Embedded
Post by: Clark 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.
Title: Re: Color Coding Embedded
Post by: Clark 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.
Title: Re: Color Coding Embedded
Post by: Clark 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.
Title: Re: Color Coding Embedded
Post by: hs2 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 :(