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
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
What IDE are you using?
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
microsoft visual c++ 6
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.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
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
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
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:
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.Code:string str="If you want to continue, press the enter key";
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
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)
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.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
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]); } }
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
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