SyntaxHighlighter.st
author Claus Gittinger <cg@exept.de>
Tue, 31 Mar 1998 19:58:52 +0200
changeset 665 14114d1e653c
parent 662 5a0a832ac06c
child 667 adfa44cccb67
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1998 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"



Parser subclass:#SyntaxHighlighter
	instanceVariableNames:'sourceText identifierColor identifierEmphasis
		argumentIdentifierColor argumentIdentifierEmphasis
		localIdentifierColor localIdentifierEmphasis
		unknownIdentifierColor unknownIdentifierEmphasis
		globalIdentifierColor globalIdentifierEmphasis commentColor
		commentEmphasis methodSelectorEmphasis methodSelectorColor
		selectorEmphasis selectorColor stringColor stringEmphasis
		selfColor selfEmphasis superColor superEmphasis hereColor
		hereEmphasis thisContextColor thisContextEmphasis
		booleanConstantColor booleanConstantEmphasis constantColor
		constantEmphasis'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Compiler'
!

!SyntaxHighlighter class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1998 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"


! !

!SyntaxHighlighter class methodsFor:'highlighting'!

formatMethod:aString in:aClass
    "format a method in a given class."

    |parser tree text|

    aString isNil ifTrue:[^ nil].

    parser := self for:(ReadStream on:aString) in:aClass.
    parser ignoreErrors.
    parser ignoreWarnings.
    parser sourceText:(text := aString asText).

    tree := parser parseMethod.
    ^ text

    "
     self
        formatMethod:'foo 
    ^ self bar:''hello''.

    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
'
        in:UndefinedObject
    "

    "Modified: / 31.3.1998 / 14:31:26 / cg"
! !

!SyntaxHighlighter methodsFor:'accessing'!

sourceText
    "return the value of the instance variable 'sourceText' (automatically generated)"

    ^ sourceText

    "Created: / 31.3.1998 / 11:49:05 / cg"
!

sourceText:something
    "set the value of the instance variable 'sourceText' (automatically generated)"

    sourceText := something.

    "Created: / 31.3.1998 / 11:49:05 / cg"
! !

!SyntaxHighlighter methodsFor:'initialization'!

initialize
    |prefs|

    super initialize.

    prefs := UserPreferences current.
    identifierEmphasis := prefs identifierEmphasis.
    identifierColor := prefs identifierColor.
    argumentIdentifierEmphasis := prefs argumentIdentifierEmphasis.
    argumentIdentifierColor := prefs argumentIdentifierColor.
    localIdentifierEmphasis := prefs localIdentifierEmphasis.
    localIdentifierColor := prefs localIdentifierColor.
    globalIdentifierEmphasis := prefs globalIdentifierEmphasis.
    globalIdentifierColor := prefs globalIdentifierColor.
    unknownIdentifierEmphasis := prefs unknownIdentifierEmphasis.
    unknownIdentifierColor := prefs unknownIdentifierColor.
    commentEmphasis := prefs commentEmphasis.
    commentColor := prefs commentColor.
    methodSelectorEmphasis := prefs methodSelectorEmphasis.
    methodSelectorColor := prefs methodSelectorColor.
    selectorEmphasis := prefs selectorEmphasis.
    selectorColor := prefs selectorColor.
    stringEmphasis := prefs stringEmphasis.
    stringColor := prefs stringColor.
    selfEmphasis := prefs selfEmphasis.
    selfColor := prefs selfColor.
    hereEmphasis := prefs hereEmphasis.
    hereColor := prefs hereColor.
    superEmphasis := prefs superEmphasis.
    superColor := prefs superColor.
    thisContextEmphasis := prefs thisContextEmphasis.
    thisContextColor := prefs thisContextColor.
    constantEmphasis := prefs constantEmphasis.
    constantColor := prefs constantColor.
    booleanConstantEmphasis := prefs booleanConstantEmphasis.
    booleanConstantColor := prefs booleanConstantColor.

    "Created: / 31.3.1998 / 15:12:55 / cg"
    "Modified: / 31.3.1998 / 19:12:18 / cg"
! !

!SyntaxHighlighter methodsFor:'syntax detection'!

markArgumentIdentifierFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:argumentIdentifierEmphasis color:argumentIdentifierColor

    "Modified: / 31.3.1998 / 18:01:27 / cg"
!

markBooleanConstantFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:booleanConstantEmphasis color:booleanConstantColor

    "Created: / 31.3.1998 / 18:09:01 / cg"
    "Modified: / 31.3.1998 / 19:36:44 / cg"
!

markCommentFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:commentEmphasis color:commentColor

    "Modified: / 31.3.1998 / 18:01:55 / cg"
!

markConstantFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:constantEmphasis color:constantColor

    "Modified: / 31.3.1998 / 18:01:44 / cg"
    "Created: / 31.3.1998 / 18:09:22 / cg"
!

markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clr
    |e|

    e := Text addEmphasis:fontEmp to:(#color->clr).
    sourceText emphasizeFrom:pos1 to:pos2 with:e

    "Created: / 31.3.1998 / 13:26:53 / cg"
    "Modified: / 31.3.1998 / 18:01:02 / cg"
!

markGlobalIdentifierFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:globalIdentifierEmphasis color:globalIdentifierColor

    "Modified: / 31.3.1998 / 18:02:14 / cg"
!

markHereFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:hereEmphasis color:hereColor

    "Modified: / 31.3.1998 / 18:02:25 / cg"
!

markIdentifierFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:identifierEmphasis color:identifierColor

    "Modified: / 31.3.1998 / 18:02:39 / cg"
    "Created: / 31.3.1998 / 18:04:56 / cg"
!

markLocalIdentifierFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:localIdentifierEmphasis color:localIdentifierColor

    "Modified: / 31.3.1998 / 18:02:39 / cg"
!

markMethodSelectorFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:methodSelectorEmphasis color:methodSelectorColor

    "Modified: / 31.3.1998 / 18:02:52 / cg"
!

markSelectorFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:selectorEmphasis color:selectorColor

    "Modified: / 31.3.1998 / 18:03:01 / cg"
!

markSelfFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:selfEmphasis color:selfColor

    "Modified: / 31.3.1998 / 18:03:10 / cg"
!

markStringFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:stringEmphasis color:stringColor

    "Modified: / 31.3.1998 / 18:03:18 / cg"
!

markSuperFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:superEmphasis color:superColor

    "Modified: / 31.3.1998 / 18:03:26 / cg"
!

markThisContextFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:thisContextEmphasis color:thisContextColor

    "Modified: / 31.3.1998 / 18:03:36 / cg"
!

markUnknownIdentifierFrom:pos1 to:pos2
    self 
        markFrom:pos1 to:pos2 
        withEmphasis:unknownIdentifierEmphasis color:unknownIdentifierColor

    "Created: / 31.3.1998 / 19:09:26 / cg"
    "Modified: / 31.3.1998 / 19:10:30 / cg"
! !

!SyntaxHighlighter class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libcomp/SyntaxHighlighter.st,v 1.2 1998-03-31 17:58:52 cg Exp $'
! !