Jump to content
  • Advertisement
Sign in to follow this  
ouraqt

Syntax Highlighting (How?)

This topic is 4423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing an IDE for a programming language I'm writing (I'll probably use it for scripting AI in games or writing simple tools). Of course the IDE includes a text editor, which I would like to have syntax highlighting. The language resembles C/C#/Java so I would like it to color certain keywords like "for", "if", and "int". Do I need to make a RichEdit control? A little help here would be greatly appreciated. :) Edit: I'm coding in native C++, using only the Win32 API.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
One thing that you might think about doing is writing a module for Visual Studio (search your msdn for babel something or other, if you have it). I did that for my own language and it worked out fairly well. By properly formatting your output from your compiler (if that is what you are using) you can get good error messages just like with C++. Then with custom build events you can easily develop in your own language in Visual Studio.

Otherwise, you can use a rich edit as you said. I think you will find some things about this here at gamedev if you search (I remember something about syntax highlighting coming up). One thing you might think of doing is lexing the text occasionally and coloring lexemes (which is kind of how you do in for visual studio).

Sorry if that isn't much to go on.

Share this post


Link to post
Share on other sites
I'm not interesting in writing a module for Visual Studio, I'm writing a stand-alone IDE. Actually I already have the whole IDE finished, including project files, text editors, output windows and everything - except syntax highlighting. It's not exactly necessary, though.

How do I create multi-colored Rich Edit's?

Share this post


Link to post
Share on other sites
The idea behind highlighting in a RichEdit is to programatically move the cursor to select the keywords, change the color for the selection, and restore the user's selection.

Then, you can use lexical hightlight just fine by checking the changed lines for keywords and updating colors. Syntax highlighting involves parsing, and as such it's a little bit harder.

Share this post


Link to post
Share on other sites
rate++ for scintilla. It's also bound to the wxWidgets library (great cross-platform gui library) that has both python and lua bindings. It's called something different in there though, something like wxRichTextControl or something

Share this post


Link to post
Share on other sites
Actually I'm looking for a small solution, parsing is no problem (all you have to do is look for keywords while excluding strings and comments, right?). I'm curious though - how do you change the color of some text in a Rich Edit?

And I'm also curious, what does "rich edit" mean? Is it like an improved normal Win32 edit control?

Edit: (hehe..."edit...") I just found out that a RichEdit control is an edit box that displays RTF data. Now I just need to find out how to use it. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
The idea behind highlighting in a RichEdit is to programatically move the cursor to select the keywords, change the color for the selection, and restore the user's selection.


Hahahahaha, you said programatically. Sorry, I couldn't help it ;-)

Share this post


Link to post
Share on other sites
Look at scintilla. It has source code. The best way of doing things is usually to look at how other people do it. Then either copy it (giving credit where due) or reimplenting it if you think you can do it better / does not serve your needs.

To change colour of rich edit text. Taken from MSDN

// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
CHARFORMAT cf;

// Modify the word format so that the selected word is
// displayed in bold and not striked out.
cf.dwMask = CFM_STRIKEOUT|CFM_BOLD;
cf.dwEffects = CFE_BOLD;
pmyRichEditCtrl->SetWordCharFormat(cf);


Share this post


Link to post
Share on other sites
I wrote the PHP IDE that I use at work myself, including extensive syntax highlighting. You can read some of my comments on how I did it in this thread.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!