Tricky1975 / kitty

Quick Syntax Highlighter for use on the console
zlib License
3 stars 3 forks source link

Implement multiple ways to start strings #23

Open freezernick opened 4 years ago

freezernick commented 4 years ago

Closes #7 and closes #5 grafik

I consider changing converting

protected string stringstart = "\"";
protected string stringend = "\"";
&
protected string astringstart = "'";
protected string astringend = "'";

to something like an string array or list

protected string[] stringStarts = ...;
protected string[] stringEnd = ...;

This would be more in line with how I will probably handle the markdown parsing. It would also increase the maintainability of the code, since nobody would have to add another case to the parser if there would be the need for a third string start / end.

EDIT: Just thinking about it, I realized that this is not possible since there is no way to know which start matches which end. Maybe a list of structs stringDelimiterPair ? 😋

EDIT2: I will implement #5 with this PR too

I will mark the PR as draft until this is done

Tricky1975 commented 4 years ago

Hmm.... Yeah, the array thing looks like the most doable thing. Indeed, the system must be sure the same closure is used as for opening (which is what Lua, Python, JavaScript and so on require as well). Not sure if a struct is needed for that, but it could be an idea...

freezernick commented 4 years ago

An alternative to a struct would be comparing the indexes of the string start and string end arrays. But I think with a struct there is more flexibility and it can also be used for #5

Tricky1975 commented 4 years ago

Yeah, when it comes to multi-line strings we gotta deal with that not all languages have the same approach for that. In python that is 3x" (also used for multi-line comments) and Lua uses [[ and ]] (and when prefixing [[ with -- you get a multi-line comment), and C# uses @" for the opening and just a " for the closing.... With that taken in mind a struct could be an idea... I gotta admit the current string detector is very primitive...

freezernick commented 4 years ago

grafik

It seems to work =)

I'll only have to add the structs to the missing languages and do some testing with other languages. Then I'll adapt this a bit for #5 probably

Tricky1975 commented 4 years ago

For Python try 3x " and not 3x' I do not know if ''' is accepted but """ is... Now my Python is a bit rusty... :) The single line strings look cool ;)