开发者

VB.NET Syntax Coding

I know many people ask how some of these are done, but I do not understand the context in which to use the answers, so...

I'm building a code editor for a subversion of Python language, and I found a very decent way of highlighting keywords in the RichTextBox through this:

  bluwords.Add(KEYWORDS GO HERE)
  If scriptt.Text.Length > 0 Then
       Dim selectStart2 As Integer = scriptt.SelectionStart
       scriptt.Select(0, scriptt.Text.Length)
       scriptt.SelectionColor = Color.Black
       scriptt.DeselectAll()
       For Each oneWord As String In bluwords
            Dim pos As Integer = 0
            Do While scriptt.Text.ToUpper.IndexOf(oneWord.ToUpper, pos) >= 0
                 pos = scriptt.Text.ToUpper.IndexOf(oneWord.ToUpper, pos)
                 scriptt.Select(pos, oneWord.Length)
                 scriptt.SelectionColor = Color.Blue
                 pos += 1
            Loop
       Next
       scriptt.SelectionStart = selectStart2
  End If

(scriptt is the richtextbox) But when any decent amount of code is typed (or loaded via OpenFileDialog) chunks of the code go missing, the syntax selection falls apart, and it just plain ruins it. I'm looking for a more efficient way of doing this, maybe something more like visual studio itself...because there is NO NEED to highlight all text, set it black, then redo all of the syntaxing, and the text begins to over-right if you 开发者_开发技巧go back to insert characters between text. Also, in this version of Python, hash (#) is used for comments on comment only lines and double hash (##) is used for comments on the same line. Now I saw that someone had asked about this exact thing, and the working answer to select to the end of the line was something like: ^\'[^\r\n]+$|''[^\r\n]+$ which I cannot seem to get into practice. I also wanted to select text between quotes and turn it turquoise, such as between the first quotation mark and the second, the text is turquoise, and the same between the 3rd and 4th etcetera...

Any help is appreciated!


Visual Studio uses a full-blown parser based on the language grammer; using a few simple regex's is never going to give you the same results.

Have you looked at SyntaxHighlighter?

(Also see: Syntax Highlighting)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜