Best Method for syntax highlighting

This is a discussion on Best Method for syntax highlighting within the Windows Programming forums, part of the Platform Specific Boards category; Hello all, i just finish a text/source editor... now im trying to design a function for my syntax highlighter, do ...

  1. #1
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204

    Best Method for syntax highlighting

    Hello all, i just finish a text/source editor... now im trying to design a function for my syntax highlighter, do you guys know the best method for this?..

    i have an idea in my mind, ill try highlight only the active lines so the highlighting will be fast.. but im not sure if this will work and i heard that SetCharformat kinda mess up the undo in Richedit.. just need some advise i know some of you guys have gone tru this kind of project before, i hope you guys can help me

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Well there are certain characters you should look for like quotes and comment symbols. I would go through once and search for those special characters, and highlight until it's match is found (switch/case on every character, one each case, call a hightlight function that highlights the text until the character is encountered again). Then I'd go through again and highlight reserved words by tokenizing a line at a time and strcmp()'ing. I'm sure you can crank out some more efficiency with a slightly different algorithm, but this just seemed like a nice clean method in my head.

  3. #3
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    How does rich text box coloring work anyways, what if I wanted to do this:
    "Red birds sing"
    Would I go something like this?:
    "\cblueRed\cend birds sing"

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    I am using the IDE that comes with MSVC .NET 2002 and I know that it highlights as soon as it hits a keyword and unhighlights if you keep typing; aka as I type integer, int becomes blue and then as soon as a I type inte the normal font color returns. If I were trying to emulate this I would probably:

    1. subclass the editwindows wndproc.
    2. intercept keydown message
    3. if letter typed check from carrot start (begginning of word) until current carrot against list of keywords
    4. if found change font color to blue(or whatever) else change to black
    5. if keypressed was tab or space reset carrot start to next letter pressed
    6. pass message to editwindows oldproc

    To keep with optimization I would filter the list of keywords as the current word progressed to the actual search list would narrow itself as the word progressed in length.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  2. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 04:17 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-07-2008, 11:30 PM
  4. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM
  5. Replies: 2
    Last Post: 01-22-2008, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21