Change text color while writing
Solution 1:
What you are looking for are Color Schemes, which automatically set the text color based on the context. Sublime supports them out of the box, see https://docs.sublimetext.io/guide/customization/color_schemes.html and https://www.sublimetext.com/docs/3/color_schemes.html.
Solution 2:
but I don't want context to define my text color. I WANT to do it. I should be responsible for this.
The issue with this is that good code editors ideally do not like to modify your source files.
For your use case the editor will have to store some extra information (metadata) somewhere so that it can keep track of, and display, the right colour to you in the editor. It can do this by storing this additional metadata in your source file itself or by storing it separately in its own database or a separate file.
Obviously adding this extra information in the source file may interfere with code execution, when you run your code. Storing the data separately is better but this data can be lost if you don't copy the metadata file / rules too when copying your source file and viewing it in a different system.
That's why most code editors display colours based on context, after analysing your code, as this way, they don't have to include any additional data in your source file.
Anyway, you can try the first approach by defining your own metadata and storing it in your source code using TextMate.
TextMate editor has a feature called Bundles (equivalent to macros or scripts).
You should be able to do what you want by creating your own bundle to search for some specific keywords in code comments (like NOTE, WARNING, TODO or RED, BLUE, GREEN etc.) and defining that when such keywords are encountered the text following them should be coloured with whatever colour you have defined for them.
Here's the documentation on TextMate Bundles.
Otherwise, just use Pages and write your code in that. And when you want to execute your code, manually copy and paste it to a text file and run it.