I have been playing around with the string interpolation and this seems to work as I wanted (and almost the same as what Visual Studio from Microsoft does)
def("text/x-csharp", {
name: "clike",
keywords: words("abstract as async await base break case catch checked class const continue" +
" default delegate do else enum event explicit extern finally fixed for" +
" foreach goto if implicit in init interface internal is lock namespace new" +
" operator out override params private protected public readonly record ref required return sealed" +
" sizeof stackalloc static struct switch this throw try typeof unchecked" +
" unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
" global group into join let orderby partial remove select set value var yield"),
types: words("Action Boolean Byte Char DateTime DateTimeOffset Decimal Double Func" +
" Guid Int16 Int32 Int64 Object SByte Single String Task TimeSpan UInt16 UInt32" +
" UInt64 bool byte char decimal double short int long object" +
" sbyte float string ushort uint ulong"),
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
defKeywords: words("class interface namespace record struct var"),
typeFirstDefinitions: true,
atoms: words("true false null"),
hooks: {
"@": function(stream, state) {
if (stream.eat('"')) {
state.tokenize = tokenAtString;
return tokenAtString(stream, state);
}
stream.eatWhile(/[\w\$_]/);
return "meta";
},
'$': function(stream, state) {
if (stream.peek() !== '"') return false;
state.tokenize = tokenStringInterpolation(false, false);
return state.tokenize(stream, state);
}
}
});
function tokenStringInterpolation(interpolating, insideString) {
return function (stream, state) {
var ch;
while (!stream.eol()) {
ch = stream.next();
if (interpolating) {
if (ch != "(") {
stream.skipTo("}");
state.tokenize = tokenStringInterpolation(false, insideString)
return "variable";
}
}
if (ch == '"') {
if (!insideString) {
state.tokenize = tokenStringInterpolation(interpolating, true)
return "string";
}
else {
state.tokenize = null;
return "";
}
}
if (ch == "{") {
if (stream.peek() === '{') // This '{{' escapes string interpolation
stream.next();
else {
state.tokenize = tokenStringInterpolation(true, insideString);
return "";
}
}
if (ch == "}") {
if (stream.peek() === '}') // This '}}' escapes string interpolation
stream.next();
else {
state.tokenize = tokenStringInterpolation(false, insideString);
return "";
}
}
if (ch == "(" && interpolating) {
state.tokenize = null;
return "";
}
state.tokenize = tokenStringInterpolation(false, insideString)
return "string";
}
return "string"
}
}
The only thing what I can’t get right is this char … meaby you have an idea and if you have some tips to improve the code then I’m happy to hear them because this is the first time I made something like this for codemirror.
The " should also be colored as a string
