tools/GroovySourceHighlighter.st
changeset 3028 3bc512cb6649
parent 2760 818fa434937a
parent 2873 3084c43f20a1
child 3324 a58245c0e83a
equal deleted inserted replaced
2835:2dec810ad03b 3028:3bc512cb6649
    23 Object subclass:#GroovySourceHighlighter
    23 Object subclass:#GroovySourceHighlighter
    24 	instanceVariableNames:'preferences cachedStringEmphasis cachedStringColor sourceText
    24 	instanceVariableNames:'preferences cachedStringEmphasis cachedStringColor sourceText
    25 		sourceIndex'
    25 		sourceIndex'
    26 	classVariableNames:''
    26 	classVariableNames:''
    27 	poolDictionaries:''
    27 	poolDictionaries:''
    28 	category:'Languages-Java-Tools-Source'
    28 	category:'Languages-Groovy-Tools-Source'
    29 !
    29 !
    30 
    30 
    31 JavaScanner subclass:#Scanner
    31 GroovyScanner subclass:#Scanner
    32 	instanceVariableNames:'buffer bufferFirst bufferLast highlighter'
    32 	instanceVariableNames:'buffer bufferFirst bufferLast highlighter'
    33 	classVariableNames:''
    33 	classVariableNames:''
    34 	poolDictionaries:''
    34 	poolDictionaries:''
    35 	privateIn:GroovySourceHighlighter
    35 	privateIn:GroovySourceHighlighter
    36 !
    36 !
    61 "
    61 "
    62 !
    62 !
    63 
    63 
    64 documentation
    64 documentation
    65 "
    65 "
    66     A syntax highligter for Java. This highlighter is SmallSense-aware and
    66     A syntax highligter for Groovy. This highlighter is SmallSense-aware and
    67     supports incremental highlighting.
    67     supports incremental highlighting, however, it does only lexical highlighting.
    68 
    68 
    69     [author:]
    69     [author:]
    70         Jan Vrany <jan.vrany@fit.cvut.cz>
    70         Jan Vrany <jan.vrany@fit.cvut.cz>
    71 
    71 
    72     [instance variables:]
    72     [instance variables:]
   232 ! !
   232 ! !
   233 
   233 
   234 !GroovySourceHighlighter methodsFor:'formatting-private'!
   234 !GroovySourceHighlighter methodsFor:'formatting-private'!
   235 
   235 
   236 format: source
   236 format: source
   237     | scanner |
   237     "Simple formatting based on lexical structure only"
   238 
   238 
   239     sourceText := source string asText.
   239     | scanner token lastToken0 lastToken1 lastValue0 lastValue1 lastPosition0 lastPosition1 |
       
   240     sourceText := source asText.
   240     scanner := Scanner for: source string.
   241     scanner := Scanner for: source string.
   241     scanner highlighter: self.
   242     scanner highlighter: self.
   242     [
   243     [
   243         [ scanner nextToken ~~ #EOF ] whileTrue.
   244         [ (token := scanner nextToken) ~~ #EOF ] whileTrue:[
       
   245             "/ Here, try to guess what's selector...
       
   246             token == $( ifTrue:[
       
   247                 lastPosition0 == #Identifier ifTrue:[
       
   248                     self markSelectorFrom: lastPosition0  to: lastPosition0 + lastValue0 size - 1.
       
   249                 ].
       
   250             ].
       
   251 
       
   252             lastToken1 := lastToken0.
       
   253             lastValue1 := lastValue0.
       
   254             lastPosition1  := lastPosition0.
       
   255 
       
   256             lastToken0 := token.
       
   257             lastValue0 := scanner tokenValue.
       
   258             lastPosition0 := scanner tokenStartPosition.
       
   259         ].
   244     ] on: Error do:[:ex|
   260     ] on: Error do:[:ex|
   245         ex
   261     ].   
   246     ].                
       
   247 
       
   248     ^ sourceText
   262     ^ sourceText
   249 
   263 
   250     "Created: / 02-10-2013 / 14:40:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   264     "Created: / 02-10-2013 / 14:40:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   265     "Modified: / 03-10-2013 / 20:27:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   251 ! !
   266 ! !
   252 
   267 
   253 !GroovySourceHighlighter methodsFor:'queries'!
   268 !GroovySourceHighlighter methodsFor:'queries'!
   254 
   269 
   255 doLexicalHighlightingOnly
   270 doLexicalHighlightingOnly
   694     "Created: / 17-03-2012 / 00:05:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   709     "Created: / 17-03-2012 / 00:05:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   695 ! !
   710 ! !
   696 
   711 
   697 !GroovySourceHighlighter class methodsFor:'documentation'!
   712 !GroovySourceHighlighter class methodsFor:'documentation'!
   698 
   713 
   699 version
       
   700     ^ '$Header: /cvs/stx/stx/libjava/tools/GroovySourceHighlighter.st,v 1.1 2013-10-03 08:31:41 vrany Exp $'
       
   701 !
       
   702 
       
   703 version_CVS
       
   704     ^ '$Header: /cvs/stx/stx/libjava/tools/GroovySourceHighlighter.st,v 1.1 2013-10-03 08:31:41 vrany Exp $'
       
   705 !
       
   706 
       
   707 version_HG
   714 version_HG
   708 
   715 
   709     ^ '$Changeset: <not expanded> $'
   716     ^ '$Changeset: <not expanded> $'
   710 ! !
   717 ! !
   711 
   718