Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Public Member Functions | List of all members
SyntaxHighlighter Class Reference

Super simple C# syntax highlighter. Adapted from https://codingvision.net/interface/c-simple-syntax-highlighting More...

Public Member Functions

string HighlightWithBBCode (string code)
 Highlight C# code with BBCode tags. More...
 

Detailed Description

Super simple C# syntax highlighter. Adapted from https://codingvision.net/interface/c-simple-syntax-highlighting

Definition at line 9 of file SyntaxHighlighter.cs.

Member Function Documentation

◆ HighlightWithBBCode()

string SyntaxHighlighter.HighlightWithBBCode ( string  code)
inline

Highlight C# code with BBCode tags.

Parameters
codeC# code string
Returns
Input string with BBCode tags.

Definition at line 16 of file SyntaxHighlighter.cs.

17  {
18  string outputCode = code;
19 
20  // getting keywords/functions
21  const string keywords = @"\b(public|private|protected|partial|static|namespace|class|using|void|float|Vector2|int|bool|string|foreach|in|var|override|if|for|else|new|true|false)\b";
22  MatchCollection keywordMatches = Regex.Matches(outputCode, keywords);
23  outputCode = ColorizeMatches(outputCode, keywordMatches, Colors.Cyan);
24 
25  // getting types/classes from the text
26  const string types = @"\b(GD|OS|Engine)\b";
27  MatchCollection typeMatches = Regex.Matches(outputCode, types);
28  outputCode = ColorizeMatches(outputCode, typeMatches, Colors.DarkCyan);
29 
30  // getting strings
31  const string strings = "\".+?\"";
32  MatchCollection stringMatches = Regex.Matches(outputCode, strings);
33  outputCode = ColorizeMatches(outputCode, stringMatches, Colors.Brown);
34 
35  // inline comments
36  var comments = @"(\/\/.*)";
37  MatchCollection commentMatches = Regex.Matches(outputCode, comments);
38  outputCode = ColorizeMatches(outputCode, commentMatches, Colors.Green);
39 
40  // multiline comments
41  comments = @"(\/\*.+?\*\/)";
42  commentMatches = Regex.Matches(outputCode, comments, RegexOptions.Multiline | RegexOptions.Singleline);
43  return ColorizeMatches(outputCode, commentMatches, Colors.Green);
44  }

The documentation for this class was generated from the following file: