GoScintilla - 2.7 (Purebasic 4.5 onwards)

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by srod »

Hi Justin,

the following is based on the block-comment demo, but for simplicity (so as not to confuse the issue too much) I have removed the block-comment styling code.

Instead, only lines (or part lines) beginning with // are commented. A part line will be commented only if the // occurs at the beginning of a line or the preceeding character is either whitespace (tab or space) or a ; character.

Code: Select all

IncludePath "..\..\..\"
XIncludeFile "GoScintilla.pbi"


Declare.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)


;Initialise the Scintilla library for Windows.
  CompilerIf  #PB_Compiler_OS = #PB_OS_Windows 
    InitScintilla()
  CompilerEndIf

If OpenWindow(0, 100, 200, 600, 600, "GoScintilla demo!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) ;Required for the tab key to function correctly when the Scintilla control has the focus.

  ;Create our Scintilla control. Note that we do not specify a callback; this is optional for GoSctintilla.
    GOSCI_Create(1, 10, 10, 580, 580, 0, #GOSCI_AUTOSIZELINENUMBERSMARGIN|#GOSCI_ALLOWCODEFOLDING)
  ;Set the padding added to the width of the line-number margin.
    GOSCI_SetAttribute(1, #GOSCI_LINENUMBERAUTOSIZEPADDING, 10)

  ;Set folding symbols margin width.
    GOSCI_SetMarginWidth(1, #GOSCI_MARGINFOLDINGSYMBOLS, 24)

  ;Set the back color of the line containing the caret.
    GOSCI_SetColor(1, #GOSCI_CARETLINEBACKCOLOR, $B4FFFF)

  ;Set font.
    GOSCI_SetFont(1, "Courier New", 10)

  ;Set tabs. Here we use a 'hard' tab in which a tab character is physically inserted. Set the 3rd (optional) parameter to 1 to use soft-tabs.
    GOSCI_SetTabs(1, 2)

  ;Set styles for our syntax highlighting.
  ;=======================================
    ;First define some constants to identify our various styles.
    ;You can name these as we wish.
      Enumeration
        #STYLES_COMMANDS = 1
        #STYLES_COMMENTS
        #STYLES_COMPILER
        #STYLES_LITERALSTRINGS
        #STYLES_NUMBERS
        #STYLES_FUNCTIONS
        #STYLES_FIELDS
      EndEnumeration

    ;Set individual styles for commands.
      GOSCI_SetStyleFont(1, #STYLES_COMMANDS, "", -1, #PB_Font_Bold)
      GOSCI_SetStyleColors(1, #STYLES_COMMANDS, $800000)  ;We have omitted the optional back color.

    ;Set individual styles for comments.
      GOSCI_SetStyleFont(1, #STYLES_COMMENTS, "", -1, #PB_Font_Italic)
      GOSCI_SetStyleColors(1, #STYLES_COMMENTS, $006400)  ;We have omitted the optional back color.

    ;Set individual styles for compiler directives etc..
      GOSCI_SetStyleColors(1, #STYLES_COMPILER, $2193DE)  ;We have omitted the optional back color.

    ;Set individual styles for literal strings.
      GOSCI_SetStyleColors(1, #STYLES_LITERALSTRINGS, #Gray)  ;We have omitted the optional back color.

    ;Set individual styles for numbers.
      GOSCI_SetStyleColors(1, #STYLES_NUMBERS, #Red)  ;We have omitted the optional back color.

    ;Set individual styles for functions.
      GOSCI_SetStyleColors(1, #STYLES_FUNCTIONS, #Blue)  ;We have omitted the optional back color.

    ;Set individual styles for fields.
      GOSCI_SetStyleColors(1, #STYLES_FIELDS, $2730D8)  ;We have omitted the optional back color.

  ;Set keywords for our syntax highlighting.
  ;=========================================
    ;First some commands.
      GOSCI_AddKeywords(1, "auto bool break bstr case char const continue date default do double else enum", #STYLES_COMMANDS)
      GOSCI_AddKeywords(1, "extern float for goto if int long lpwstr lpvoid register return short signed", #STYLES_COMMANDS)
      GOSCI_AddKeywords(1, "sizeof static struct switch typedef ulong union unsigned variant vartype void volatile while", #STYLES_COMMANDS)
    ;Now set up quotes to denote literal strings. Note the space separating the pair of quotes from the pait of ' symbols.
      GOSCI_AddKeywords(1, Chr(34) + Chr(34) + " ''", #STYLES_LITERALSTRINGS, #GOSCI_DELIMITBETWEEN)
    ;Now set up a # symbol to denote a compiler directive.
      GOSCI_AddKeywords(1, "#", #STYLES_COMPILER, #GOSCI_LEFTDELIMITWITHOUTWHITESPACE)
    ;Now set up a ( symbol to denote a function.
      GOSCI_AddKeywords(1, "(", #STYLES_FUNCTIONS, #GOSCI_RIGHTDELIMITWITHWHITESPACE)
    ;We arrange for a ) symbol to match the coloring of the ( symbol.
      GOSCI_AddKeywords(1, ")", #STYLES_FUNCTIONS)
    ;Now set up a . symbol to delimit structure members.
      GOSCI_AddKeywords(1, ".", #STYLES_FIELDS, #GOSCI_LEFTDELIMITWITHWHITESPACE|#GOSCI_RIGHTDELIMITWITHWHITESPACE)

    ;Add some folding keywords.
      GOSCI_AddKeywords(1, "{", #STYLES_COMMANDS, #GOSCI_OPENFOLDKEYWORD)
      GOSCI_AddKeywords(1, "}", #STYLES_COMMANDS, #GOSCI_CLOSEFOLDKEYWORD)


  ;Additional lexer options.
  ;=========================
    ;The lexer needs to know what separator characters we are using.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_SEPARATORSYMBOLS, @"=+-*/%[],{}&;|!>()") ;You would use GOSCI_AddKeywords() to set a style for some of these if required.
    ;We can also set a style for numbers.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_NUMBERSSTYLEINDEX, #STYLES_NUMBERS)


  ;Set our user-defined line styling function.
  ;===========================================
    GOSCI_SetLineStylingFunction(1, @MyLineStyler())
  

  Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_SizeWindow
        ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(0)-20, WindowHeight(0)-20)
      
      Case #PB_Event_Gadget
        Select EventGadget()
        EndSelect
    EndSelect
  Until eventID = #PB_Event_CloseWindow 

  ;Free the Scintilla gadget.
  ;This needs explicitly calling in order to free resources used by GoScintilla.
    GOSCI_Free(1)
EndIf


;/////////////////////////////////////////////////////////////////////////////////
;The following is our user-defined line-styling function, called whenever GoScintilla is called upon to style lines.
;Here we look out for // line comment markers and, if encountered, comment the remainder of the line IF the preceding character was a
;whitespace character or a ; or the beginning of the line.
Procedure.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
  Protected result = #GOSCI_STYLELINESASREQUIRED, numBytesStyled, *ptrAscii.ASCII, blnLastSymbolAValidStarter = #True
  While numUtf8Bytes
    numBytesStyled = 0
    *ptrAscii = *utf8Buffer
    If blnLastSymbolAValidStarter And *ptrAscii\a = '/' And numUtf8Bytes > 1
      *ptrAscii + 1
      If *ptrAscii\a = '/' ;We have a single line comment and so we style the remainder of this line (excluding EOL characters) appropriately.
        numBytesStyled = numUtf8Bytes
        ;Do not apply the comment style to EOL characters as this can cause problems.
          *ptrAscii + numUtf8Bytes - 1
          While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
            *ptrAscii - 1
            numBytesStyled - 1
          Wend
          ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
      EndIf
    EndIf
    If numBytesStyled = 0
      If *ptrAscii\a = 9 Or *ptrAscii\a = 32 Or *ptrAscii\a = ';'
        blnLastSymbolAValidStarter = #True
      Else
        blnLastSymbolAValidStarter = #False
      EndIf
      numBytesStyled = GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes)    
    EndIf
    numUtf8Bytes - numBytesStyled
    *utf8Buffer + numBytesStyled
  Wend
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
To get a proper C++ type highlighter, you would need to combine this code with the block-comment demo to give complete coverage of comments etc. As I say, I kept this example as simple as possible.

The code is probably not very efficient because I hacked it up very quickly. :)

I hope this helps?
I may look like a mule, but I'm not a complete ass.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by Justin »

Thanks but i can't seem to put both things to work, i tried expanding the if/endif block with part of your code but when entering a new commented line everything messes:

Code: Select all

Procedure.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
  Protected result = #GOSCI_STYLELINESASREQUIRED, blnIsEndOfPreviousLineCommented, numBytesToStyle, numBytesStyled, *ptrAscii.ASCII
  ;Is the end of the previous line commented? (We store a flag to indicate this in the line data.)
    If currentLine > 0
      blnIsEndOfPreviousLineCommented = GOSCI_GetLineData(id, currentLine-1)
    EndIf
  ;Need to loop through the UTF-8 buffer, alternating between styling comments and invoking GoScintilla's styling lexer as appropriate.
    While numUtf8Bytes
      If blnIsEndOfPreviousLineCommented
        numBytesStyled = myStylerUtility_StyleCommentPart(id, *utf8Buffer, numUtf8Bytes, @blnIsEndOfPreviousLineCommented)
        numUtf8Bytes - numBytesStyled
        *utf8Buffer + numBytesStyled
      EndIf
      If numUtf8Bytes > 0
        ;We are now outside of a comment block. We now search for an opening /* comment marker on a symbol by symbol basis.
        ;All other symbols will be passed back to GoScintilla for styling.
          While numUtf8Bytes > 0
            *ptrAscii = *utf8Buffer
            If *ptrAscii\a = '/' And numUtf8Bytes > 1
              *ptrAscii + 1
              If *ptrAscii\a = '*' ;Open comment found.
                ;Apply the comment style to the /* symbol so as not to confuse our comment styler utility function below.
                  ScintillaSendMessage(id, #SCI_SETSTYLING, 2, #STYLES_COMMENTS)
                  numUtf8Bytes - 2
                  *utf8Buffer + 2
                blnIsEndOfPreviousLineCommented = #True ;Mark that, at this point, the end of the current line will be commented.
                Break
              
              ;///////////////////////////////////////////////////////////
              elseIf *ptrAscii\a = '/' ;Single comment line
                ;ScintillaSendMessage(id, #SCI_SETSTYLING, numUtf8Bytes, #STYLES_COMMENTS)
								numBytesStyled = numUtf8Bytes
								;Do not apply the comment style to EOL characters as this can cause problems.
								*ptrAscii + numUtf8Bytes - 1
								While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
									*ptrAscii - 1
									numBytesStyled - 1
								Wend
								ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
								;////////////////////////////////////////////////////////////////
              endif 
            EndIf
            numBytesStyled = GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes)
            numUtf8Bytes - numBytesStyled
            *utf8Buffer + numBytesStyled
          Wend
      EndIf

    Wend
  ;Mark the current line as appropriate, depending upon whether it is an open ended comment.
    If GOSCI_GetLineData(id, currentLine) <> blnIsEndOfPreviousLineCommented
      GOSCI_SetLineData(id, currentLine, blnIsEndOfPreviousLineCommented)
      result = #GOSCI_STYLENEXTLINEREGARDLESS
    EndIf
  ProcedureReturn result
EndProcedure
any solution?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by srod »

Okay, try the following.

Remember that // will only result in a commented part line if the // appears at the beginning of a line or is immediately preceded by whitespace or a semi-colon, but you can change all of this easily enough.

This is about all I have time for right now Justin.

Code: Select all

IncludePath "..\..\..\"
XIncludeFile "GoScintilla.pbi"

Declare.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
Declare.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER)


;Initialise the Scintilla library for Windows.
  CompilerIf  #PB_Compiler_OS = #PB_OS_Windows 
    InitScintilla()
  CompilerEndIf

If OpenWindow(0, 100, 200, 600, 600, "GoScintilla demo!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) ;Required for the tab key to function correctly when the Scintilla control has the focus.

  ;Create our Scintilla control. Note that we do not specify a callback; this is optional for GoSctintilla.
    GOSCI_Create(1, 10, 10, 580, 580, 0, #GOSCI_AUTOSIZELINENUMBERSMARGIN|#GOSCI_ALLOWCODEFOLDING)
  ;Set the padding added to the width of the line-number margin.
    GOSCI_SetAttribute(1, #GOSCI_LINENUMBERAUTOSIZEPADDING, 10)

  ;Set folding symbols margin width.
    GOSCI_SetMarginWidth(1, #GOSCI_MARGINFOLDINGSYMBOLS, 24)

  ;Set the back color of the line containing the caret.
    GOSCI_SetColor(1, #GOSCI_CARETLINEBACKCOLOR, $B4FFFF)

  ;Set font.
    GOSCI_SetFont(1, "Courier New", 10)

  ;Set tabs. Here we use a 'hard' tab in which a tab character is physically inserted. Set the 3rd (optional) parameter to 1 to use soft-tabs.
    GOSCI_SetTabs(1, 2)

  ;Set styles for our syntax highlighting.
  ;=======================================
    ;First define some constants to identify our various styles.
    ;You can name these as we wish.
      Enumeration
        #STYLES_COMMANDS = 1
        #STYLES_COMMENTS
        #STYLES_COMPILER
        #STYLES_LITERALSTRINGS
        #STYLES_NUMBERS
        #STYLES_FUNCTIONS
        #STYLES_FIELDS
      EndEnumeration

    ;Set individual styles for commands.
      GOSCI_SetStyleFont(1, #STYLES_COMMANDS, "", -1, #PB_Font_Bold)
      GOSCI_SetStyleColors(1, #STYLES_COMMANDS, $800000)  ;We have omitted the optional back color.

    ;Set individual styles for comments.
      GOSCI_SetStyleFont(1, #STYLES_COMMENTS, "", -1, #PB_Font_Italic)
      GOSCI_SetStyleColors(1, #STYLES_COMMENTS, $006400)  ;We have omitted the optional back color.

    ;Set individual styles for compiler directives etc..
      GOSCI_SetStyleColors(1, #STYLES_COMPILER, $2193DE)  ;We have omitted the optional back color.

    ;Set individual styles for literal strings.
      GOSCI_SetStyleColors(1, #STYLES_LITERALSTRINGS, #Gray)  ;We have omitted the optional back color.

    ;Set individual styles for numbers.
      GOSCI_SetStyleColors(1, #STYLES_NUMBERS, #Red)  ;We have omitted the optional back color.

    ;Set individual styles for functions.
      GOSCI_SetStyleColors(1, #STYLES_FUNCTIONS, #Blue)  ;We have omitted the optional back color.

    ;Set individual styles for fields.
      GOSCI_SetStyleColors(1, #STYLES_FIELDS, $2730D8)  ;We have omitted the optional back color.

  ;Set keywords for our syntax highlighting.
  ;=========================================
    ;First some commands.
      GOSCI_AddKeywords(1, "auto bool break bstr case char const continue date default do double else enum", #STYLES_COMMANDS)
      GOSCI_AddKeywords(1, "extern float for goto if int long lpwstr lpvoid register return short signed", #STYLES_COMMANDS)
      GOSCI_AddKeywords(1, "sizeof static struct switch typedef ulong union unsigned variant vartype void volatile while", #STYLES_COMMANDS)
    ;Now set up quotes to denote literal strings. Note the space separating the pair of quotes from the pait of ' symbols.
      GOSCI_AddKeywords(1, Chr(34) + Chr(34) + " ''", #STYLES_LITERALSTRINGS, #GOSCI_DELIMITBETWEEN)
    ;Now set up a # symbol to denote a compiler directive.
      GOSCI_AddKeywords(1, "#", #STYLES_COMPILER, #GOSCI_LEFTDELIMITWITHOUTWHITESPACE)
    ;Now set up a ( symbol to denote a function.
      GOSCI_AddKeywords(1, "(", #STYLES_FUNCTIONS, #GOSCI_RIGHTDELIMITWITHWHITESPACE)
    ;We arrange for a ) symbol to match the coloring of the ( symbol.
      GOSCI_AddKeywords(1, ")", #STYLES_FUNCTIONS)
    ;Now set up a . symbol to delimit structure members.
      GOSCI_AddKeywords(1, ".", #STYLES_FIELDS, #GOSCI_LEFTDELIMITWITHWHITESPACE|#GOSCI_RIGHTDELIMITWITHWHITESPACE)

    ;Add some folding keywords.
      GOSCI_AddKeywords(1, "{", #STYLES_COMMANDS, #GOSCI_OPENFOLDKEYWORD)
      GOSCI_AddKeywords(1, "}", #STYLES_COMMANDS, #GOSCI_CLOSEFOLDKEYWORD)


  ;Additional lexer options.
  ;=========================
    ;The lexer needs to know what separator characters we are using.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_SEPARATORSYMBOLS, @"=+-*/%[],{}&;|!>()") ;You would use GOSCI_AddKeywords() to set a style for some of these if required.
    ;We can also set a style for numbers.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_NUMBERSSTYLEINDEX, #STYLES_NUMBERS)


  ;Set our user-defined line styling function.
  ;===========================================
    GOSCI_SetLineStylingFunction(1, @MyLineStyler())
  
  
  ;Set some initial text. We load a c source file from disc.
  ;======================
    If ReadFile(1, "exampleSource.c")
      While Eof(1) = #False
        text$ = ReadString(1)
        GOSCI_InsertLineOfText(1, -1, text$)
      Wend
      CloseFile(1)
    EndIf


  Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_SizeWindow
        ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(0)-20, WindowHeight(0)-20)
      
      Case #PB_Event_Gadget
        Select EventGadget()
        EndSelect
    EndSelect
  Until eventID = #PB_Event_CloseWindow 

  ;Free the Scintilla gadget.
  ;This needs explicitly calling in order to free resources used by GoScintilla.
    GOSCI_Free(1)
EndIf


;/////////////////////////////////////////////////////////////////////////////////
;The following is our user-defined line-styling function, called whenever GoScintilla is called upon to style lines.
Procedure.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
  Protected result = #GOSCI_STYLELINESASREQUIRED, blnIsEndOfPreviousLineCommented, numBytesToStyle, numBytesStyled, *ptrAscii.ASCII
  Protected blnLastSymbolAValidStarter = #True
  ;Is the end of the previous line commented? (We store a flag to indicate this in the line data.)
    If currentLine > 0
      blnIsEndOfPreviousLineCommented = GOSCI_GetLineData(id, currentLine-1)
    EndIf
  ;Need to loop through the UTF-8 buffer, alternating between styling comments and invoking GoScintilla's styling lexer as appropriate.
    While numUtf8Bytes
      If blnIsEndOfPreviousLineCommented
        numBytesStyled = myStylerUtility_StyleCommentPart(id, *utf8Buffer, numUtf8Bytes, @blnIsEndOfPreviousLineCommented)
        numUtf8Bytes - numBytesStyled
        *utf8Buffer + numBytesStyled
      EndIf
      blnLastSymbolAValidStarter = #True
      If numUtf8Bytes > 0
        ;We are now outside of a comment block. We now search for an opening /* comment marker on a symbol by symbol basis.
        ;All other symbols will be passed back to GoScintilla for styling.
          While numUtf8Bytes > 0
            numBytesStyled = 0
            *ptrAscii = *utf8Buffer
            If *ptrAscii\a = '/' And numUtf8Bytes > 1
              *ptrAscii + 1
              If blnLastSymbolAValidStarter And *ptrAscii\a = '/' ;We have a single line comment and so we style the remainder of this line (excluding EOL characters) appropriately.
                numBytesStyled = numUtf8Bytes
                ;Do not apply the comment style to EOL characters as this can cause problems.
                  *ptrAscii + numUtf8Bytes - 1
                  While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
                    *ptrAscii - 1
                    numBytesStyled - 1
                  Wend
                ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
              ElseIf *ptrAscii\a = '*' ;Open comment found.
                ;Apply the comment style to the /* symbol so as not to confuse our comment styler utility function below.
                  ScintillaSendMessage(id, #SCI_SETSTYLING, 2, #STYLES_COMMENTS)
                  numUtf8Bytes - 2
                  *utf8Buffer + 2
                blnIsEndOfPreviousLineCommented = #True ;Mark that, at this point, the end of the current line will be commented.
                Break
              EndIf
            EndIf
            If numBytesStyled = 0
              If *ptrAscii\a = 9 Or *ptrAscii\a = 32 Or *ptrAscii\a = ';'
                blnLastSymbolAValidStarter = #True
              Else
                blnLastSymbolAValidStarter = #False
              EndIf
              numBytesStyled = GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes)    
            EndIf
            numUtf8Bytes - numBytesStyled
            *utf8Buffer + numBytesStyled
          Wend
      EndIf
    Wend
  ;Mark the current line as appropriate, depending upon whether it is an open ended comment.
    If GOSCI_GetLineData(id, currentLine) <> blnIsEndOfPreviousLineCommented
      GOSCI_SetLineData(id, currentLine, blnIsEndOfPreviousLineCommented)
      result = #GOSCI_STYLENEXTLINEREGARDLESS
    EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
;A utility function called by our main line styler above to apply the comment style to any part of a line which is commented.
;Returns the number of bytes styled.
Procedure.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER)
  Protected numBytesToStyle, *ptrAscii.ASCII
  *ptrAscii = *utf8Buffer
  While numBytesToStyle < numUtf8Bytes
    numBytesToStyle + 1
    If *ptrAscii\a = '*' And numBytesToStyle < numUtf8Bytes
      *ptrAscii + 1
      If *ptrAscii\a = '/'
        numBytesToStyle + 1
        *ptrCommented\i = #False 
        Break
      EndIf
    Else
      *ptrAscii + 1      
    EndIf
  Wend
  If numBytesToStyle
    ;Do not apply the comment style to EOL characters. This will cause Scintilla to force us to restyle the entire document.
    ;Instead we will leave myLineStyler() to invoke the GOSCI_StyleNextSymbol() function in order to apply the default style.
      *ptrAscii-1
      While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
        numBytesToStyle - 1
        *ptrAscii-1
        If numBytesToStyle = 0
          Break
        EndIf
      Wend
      If numBytesToStyle
        ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesToStyle, #STYLES_COMMENTS)
      EndIf
  EndIf
  ProcedureReturn numBytesToStyle
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
I may look like a mule, but I'm not a complete ass.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by Justin »

It works great, thanks.

Have you noticed line 285? there is a little bug on #else. I prefer to use a keyword list for compiler directives rather than colorize whatever #* but just to let you know.

The code looks pretty complex, supporting variable length delimiters would be nice to handle this, and also some high level functions for block comments like
GOSCI_AddKeywor(id, "/*",#STYLES_COMMENT,#GOSCI_OPENSTYLEBLOCK)
GOSCI_AddKeywords(id, "*/", #STYLES_COMMENT, #GOSCI_CLOSESTYLEBLOCK)

i would not care to pay for it if you put it on your site.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by srod »

No, GoScintilla suits my purposes as it is right now and so I will not be adding additional features any time soon.
Have you noticed line 285? there is a little bug on #else. I prefer to use a keyword list for compiler directives rather than colorize whatever #* but just to let you know.
Well spotted! I had missed that. :)

Yes, I agree, a keyword list does make more sense in this kind of situation.

However, it is a bug because these kinds of delimiters were intended to allow for effortless styling of PB style constants. As it stands, the demos regard #constant as a constant/directive, but do not recognise #If as such (regarding it as a directive # followed by the keyword If).

I have fixed the bug and will upload a new version of GoScintilla tomorrow after a little more testing.

Thanks for the heads up. :)
I may look like a mule, but I'm not a complete ass.
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by byo »

*sends an e-beer srod's way*
Proud registered Purebasic user.
Because programming should be fun.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by srod »

byo wrote:*sends an e-beer srod's way*
What good is a virtual beer? Can I spill it down my shirt? Does it make me more attractive to women? Does it endow me with the singing voice of an angel?

:)

Cheers mate.

@Justin : did you take a look at Eddy's Scintilla offering? His uses a RegExp styling engine and thus may be more suited to using multi-character / multi-word delimiters etc. http://www.purebasic.fr/english/viewtop ... 14&t=40256
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by srod »

Version 1.0 - 7th January 2010

Fixed a bug with the Lexer and have included a second version of the "block comments" advanced demo program (as requested by Justin).

Please see the nxSoftware site for the download.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 1.0 beta 4 (PB 4.4 only)

Post by ts-soft »

ts-soft wrote:Bugreport on Linux :wink:

After changing all #White, #Red and so on to real colors comes a Error in GoScintilla.pbi
at line 1251 - 'Character$' length to Trim() has to be one.

Code: Select all

keyWord$ = Trim(keyWord$)
?

Tested on ubuntu x86 and x64 with the same result.

greetings
Thomas
This Bug is solved (a PB Bug) in PB4.41 RC 1

Only adding this to the Headerfile:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  #White = 16777215
  #Gray = 8421504
  #Red = 255
  #Blue = 16711680
CompilerEndIf
and all works fine.

Greetings
Thomas
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by srod »

Thanks Thomas.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by ts-soft »

A bit help required :)

Image

Greetings
Thomas
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by srod »

Code: Select all

GOSCI_SetColor(1, #GOSCI_FOLDMARGINLOBACKCOLOR, #Blue)
GOSCI_SetColor(1, #GOSCI_FOLDMARGINHIBACKCOLOR, #Blue)
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by ts-soft »

thx, :D
i see, i have to set both before it work
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by srod »

Yes, I followed Scintilla's lead there in order to retain the full flexibility etc.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 1.0 (PB 4.4 only)

Post by ts-soft »

I have test the lo and than the hi, but not both :lol:
Post Reply