syntax highlight

This is a discussion on syntax highlight within the Windows Programming forums, part of the Platform Specific Boards category; i want help on syntax highlighting i mean i want to know how to code for enabling syntax highlighting in ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    38

    syntax highlight

    i want help on syntax highlighting
    i mean i want to know how to code for enabling syntax highlighting in my text editor
    any tutorials or articles
    or any other help is most welcome
    thanx

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    What IDE are you using?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    38
    microsoft visual c++ 6

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    The syntax should already be highlighted, if by highlighting you mean different aspects of the language being in different colours. Give more information about what you're tring to achieve.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    38
    i'm trying to make a text editor with an additional feature of syntax highligting

    u may consider that i'm trying to make an application that will be able to make new files save them edit them and will also be able to do syntax highlighting

    if still not clear please feel free to ask again

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Look into the rich edit control. Also, look for the source code for other syntax highlighting text editors:
    http://www.google.com/search?q=text+...+site%3Asf.net

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Ah I see. Yes, use the rich edit control. Whenever a key is pressed, run the edit control text through a parser that loads up a table of what words correspond to what kind of text formatting. You will also need to make sure that keywords within strings aren't considered parts of the language, ie:
    Code:
    string str="If you want to continue, press the enter key";
    You don't want the 'if' and'continue' there to be considered a keyword, so you will have to consider that in the parser. This shouldn't be too difficult to do, good luck.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    38
    thank you all for your support

    anonytmouse thanx for the resourceful google link i got some code on what i was trying to achieve......but what i was looking for was a procedure or a tutorial on how to do it so that i can code it myself and my way ........ anyway i may now have to hack the code

    bennyandthejets u almost exactly gave me what i wanted but i have a lot to learn before understanding what u have told ( no idea about parsers and all).......so what i was looking for was a complete explanation or a tutorial kinda thing that wud explain me all that is needed for doing the job ...............anyways i think i should now first study about parser and then have a look at what u have told me
    ok i thank both of u again

    I"M STILL HOPEFUL THAT SOMEONE COULD GIMME A LINK TO A MORE DETAILED EXPLANATION ON THE ISSUE (syntax higlighting)

  9. #9
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I've never actually come across this kind of project before, so I can't really help you find a ready made tutorial. I can however help you with any coding/design problems.

    To elaborate, parsing means going through some data and manipulating it to make it more useful. In your case, it means you would go through each bit of code in the rich edit control, determine what colour it should be, and make it that colour. It would be a good idea to use a 'string' object, as it already contains many functions for retrieving whole words and whatnot from the string.

    Good luck.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Here's an example that parses some code and adds [color] tags.

    Code:
    struct {
    	char * szKeyword;
    	size_t cchKeyword;
    	COLORREF clr;
    } wrds[] =
    {
      { "for",    sizeof("for")    - 1, RGB(255,0,0) },
      { "if",     sizeof("if")     - 1, RGB(255,0,0) },
      { "return", sizeof("return") - 1, RGB(0,0,255) },
      { "struct", sizeof("struct") - 1, RGB(0,255,0) }
    };
    
    void Colorfy(char * szInput)
    {
    	int i, j;
    
    	for(i = 0;szInput[i] != '\0';i++)
    	{
    		BOOL bKeyword = FALSE;
    
    		for(j = 0;j < sizeof(wrds) / sizeof(wrds[0]);j++)
    		{
    			if (strncmp(&szInput[i], wrds[j].szKeyword, wrds[j].cchKeyword) == 0)
    			{
    				printf("[color=%06x]%s[/color]", wrds[j].clr, wrds[j].szKeyword);
    				i += wrds[j].cchKeyword;
    				bKeyword = TRUE;
    				break;
    			}
    		}
    
    		if (!bKeyword) putchar(szInput[i]);
    	}
    }

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    38
    thanks bennyandthejets for ur enlightening words
    and thankx anonytmouse for the useful peice of code

    thanks guys for your support
    now i think that its time for me to get my hands dirty and do some work on the lines suggested by both of u

    once again thanks for helping and following up

  12. #12
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    to do useful syntax hilighting you need to parse. Which means you may want to look at lex and yacc. These are utilities made specifically for the purpose of creating parsers. They spit out wonderfully ugly C code that will do parsing of text files that you give it. It's a thought anyway. Hope it helps some.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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