volkerdobler / gessQ

gessQ language support in vscode
4 stars 3 forks source link

problem with syntax highlighting (in javascript code) #1

Closed dietzste closed 2 years ago

dietzste commented 2 years ago

First off all: Thanks for creating this extension ๐Ÿฅ‡ ! I'm so glad it exists!

I have noticed a problem that arises with syntax higlighting.

// syntax highlighting using \" working fine
text = "some text \"quoted\"";

//  but here ..
$('[name=\"some code here...\"]').val('');
// langauge syntax fails

I created a screenshot to make it more visable: image

Since the formatting seems to be quite complex, I don't know what the problem is.

volkerdobler commented 2 years ago

Thanks for mentioning it - I will have a look into this issue in the next weeks. Currently, I am busy with project work :-)

volkerdobler commented 2 years ago

Hallo @dietzste,

I am not sure, if I have a problem understanding the issue correctly, but if you use jQuery to get any DOM element with an attribute "name" and specific value, why do you use the backslashes before the apostrophe?

If I put $('name="some values here"]').val('') syntax highlighting works perfect. The mixture of ' and " works fine for me.

Maybe give a more explicit example so I can follow your idea? Thanks Volker

volkerdobler commented 2 years ago

Hallo @dietzste,

I did another research and I think everything works fine in my syntax highlighting.

As far as I know, the following happened/is true:

  1. gessQ. does not allow single quotes as string markers. You have to use double quotes (") - single quotes (') will lead to a syntax error (but I have to check this tomorrow)
  2. Therefore, your javascript will be in a double-quoted expression, and will therefore be recognized correctly as a string (the whole javascript is one string. You only need the backslash quote within the javascript, because you use it within javascript="" - correct?

Again, I am happy to change anything - also the double/single quote rule, but currently, I think, it's correct.

Regards, Volker

dietzste commented 2 years ago

Hallo @volkerdobler,

you are absolutely right. A lot of times I'm using javascript = " ... "; as an environment for js-Code.

Your provided syntax-rules would work fine with double quotes, like: $('[name="some values..."]').val('');

But in an javascript = " ... "; - environment I have to use a backslash quote, where syntax highlighting is not working properly:

javascript="
    $('[name="some code here..."]').val('');
";

as seen here:

grafik

I think it might need just a tiny tweak for regognizing \" to work perfectly. But I have no clue, where to begin.

volkerdobler commented 2 years ago

Maybe I am stupid, but let me try to understand what you need :-) In the tmLanguage file, the syntax highlighting is defined. It's a very complicated syntax, and to be honest, I don't understand it 100%. But coming back to your example.

javascript=" starts (by definition) a string, which ends in your last line ";. So EVERYTHING in this string is handled as string (WITHOUT regular gessQ syntax highlighting). Another example is, that HTML Tags in "label" texts also don't have syntax highlighting - it's just a string for gessQ.

This is the result in my editor:

image

(you can use the command "Developer: Inspect Editor Tokens and Scopes" to see, which scope (base for any syntax highlighting) is at the current curser. In my example, it's a string, not javascript or anything fancy.

If I want/have to change this behaviour, I have to tell the syntax (in the tmLanguage file), a new scope for javascript=" - and I am not sure, what side effect this will have ...

Did you try the "official supported" notepad++ for your file? Does the notepad++ have any syntax highlighting in javascript-strings?

Talk to you soon, Volker

dietzste commented 2 years ago

I think I found something helpful:

If I open this code in Notepad++ and in vs-code I get two different highlightings:

#macro somemacro
    \" another \" doesn't closes the string
    " is needed without \
    \" \" opens string
    " closes String
#endmacro

in vs code: grafik in Notepad++: grafik

This means that syntax highlighting in Notepad++ does not differentiate between /" and " For gessQ it is a dififference, but syntax highlighting in notepad++ ignores it.

I'm sure in vs code the same approach would work: But I think there is even a better solution:

An escaped quote as /" should not start a string. Only " should start a string.

?!.,;*+#'`=-_^ยฐ/\ยง%&รŸ () [] {} 
\"... this should not start a string"
"... only this should start a string"
javascript="
    within a string \" works as it
    should
";

grafik

This behavoir would lead to a correct syntax highlighting if it is not between double quotes.

For code between javascript=""; we need a new scope as you mentioned before.

volkerdobler commented 2 years ago

Hi @dietzste,

I think I found it ... I just published version 0.3.2. Please check if it works for you and let me know. Thanks for your patience.

Volker

dietzste commented 2 years ago

Hi @volkerdobler,

it works fine ๐Ÿ†! Thank you very much ๐Ÿ‘ !

Stefan