Fast syntax highlighting in RTB

Discussion in 'Programming General' started by Darthatron, Jan 19, 2012.

Fast syntax highlighting in RTB
  1. Unread #1 - Jan 19, 2012 at 6:25 AM
  2. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Fast syntax highlighting in RTB

    So, I'm making an assembler with a GUI in C#, and I've decided to just make a user control with some syntax highlighting. I'm not very imaginative with names, so I'm just calling it CodeTextBox. Chances are that I'll make it open source once it's done anyway, so I was wondering if anyone was willing to put some effort in to help make it a better control.

    So far I've got syntax highlighting working pretty well, and there's no noticeable lag even with hundreds of lines of code. The way I did this was by only updating the syntax on the current line, rather than the entire RTB all at once.

    I want it to be simple to change the highlighting that takes place, it currently uses something like this:
    Code:
                txtMain.TheSyntax.ClearSyntax();
                txtMain.TheSyntax.AddSyntax(new string[] { ".org", ".word", ".hword", ".align", }, Color.Gray); //Directives
                txtMain.TheSyntax.AddSyntax(new string[] { "push", "pop", "mov", "movs", "ldr", "ldrb", "ldrh", "lsl", "lsr", "b", "bx", "bl", "blx", "bge", "beq", "blt", "cmp", "add", "sub" }, Color.Blue); //Keywords
                txtMain.TheSyntax.AddSyntax(new string[] { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "lr", "sp", "pc" }, Color.DarkCyan); //Registers
    Other syntax colors are set pretty easily as well:
    Code:
                txtMain.TheSyntax.NumericColor = Color.DarkMagenta;
                txtMain.TheSyntax.HighlightNumbers = true;
                txtMain.TheSyntax.CommentColor = Color.DarkGreen;
                txtMain.TheSyntax.HighlightComments = false;
                txtMain.TheSyntax.StringColor = Color.DarkRed;
                txtMain.TheSyntax.HighlightStrings = false;
    And of course you can set the size of the tab key, rather than sending an actual TAB character to the textbox.
    Code:
                txtMain.TabSize = 4;
    Currently the only thing not complete for Syntax Highlighting is comments, mainly because they are multi-line, so I'm trying to work out a way to make that work well. Ideas?

    I'm not really having trouble with anything, but I think it could be a good community project if anyone else is bored. So, who's bored?
     
  3. Unread #2 - Jan 20, 2012 at 4:45 AM
  4. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Fast syntax highlighting in RTB

    In fact, I'm just going to leave this here if anyone is interested in it.
     
  5. Unread #3 - Jan 20, 2012 at 8:22 AM
  6. Aleul
    Joined:
    Apr 9, 2011
    Posts:
    2
    Referrals:
    0
    Sythe Gold:
    0

    Aleul Newcomer

    Fast syntax highlighting in RTB

    Hey man, I'll make some changes to this tonight after work\tomorrow morning, heading off to work here in a minute. I have a question though so I don't go changing things on you.

    Is there any particular reason you're not inheriting from a RichTextBox, and that on the on change event calling a parser? It'd take out the need to call Win32 functions (well, maybe not entirely but I've only glance over the code atm).

    Then by separating out the parser you can easily reuse it for things that aren't specifically this control
     
  7. Unread #4 - Jan 20, 2012 at 10:21 PM
  8. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Fast syntax highlighting in RTB

    No real reason, really. I just felt it would be more open if I didn't inherit anything. But if you think it would be better, then fair enough. ^_^

    I don't really use C# all that often, so I'm not surprised (and won't be offended) if my code is sloppy.
     
  9. Unread #5 - Jan 29, 2012 at 3:30 AM
  10. iJava
    Joined:
    Nov 21, 2011
    Posts:
    1,197
    Referrals:
    11
    Sythe Gold:
    485
    Discord Unique ID:
    220055593568829441

    iJava .Previously known as RSGoldRush
    $200 USD Donor New

    Fast syntax highlighting in RTB

    If you finish this then I may create a version for Java and we could perhaps provide them together on SF?
     
  11. Unread #6 - Apr 16, 2012 at 12:06 AM
  12. dongchan
    Joined:
    Apr 15, 2012
    Posts:
    82
    Referrals:
    0
    Sythe Gold:
    0

    dongchan Member

    Fast syntax highlighting in RTB

    can anyone tell me what's the mean of "SF"?
     
  13. Unread #7 - Apr 16, 2012 at 12:55 AM
  14. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    Fast syntax highlighting in RTB

    SourceForge. It's a place where programmers supply open-source applications.
     
  15. Unread #8 - Jun 19, 2012 at 10:42 PM
  16. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    Fast syntax highlighting in RTB

    To make things a bit more flexible for the end-user you might want to manage syntax highlighting through XML like what AvalonEdit does
     
  17. Unread #9 - Jun 21, 2012 at 4:10 PM
  18. Kyle_Undefined
    Joined:
    Feb 9, 2012
    Posts:
    53
    Referrals:
    0
    Sythe Gold:
    0

    Kyle_Undefined Member

    Fast syntax highlighting in RTB

    Couldn't you have the syntax highlighting for the whole document run in the background? It shouldn't be that hard to properly do it, no matter how many lines the file is.
     
< java experience required for a rs bot? | Get Help! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site