AbstractSyntaxHighlighter.st
author Claus Gittinger <cg@exept.de>
Fri, 06 Feb 2015 09:33:09 +0100
changeset 3573 1f32e1038e8e
parent 3561 f04a8db1590f
child 3599 a999663bd83f
permissions -rw-r--r--
class: MessageNode changed: #withConstantValueDo:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     1
"
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     2
 COPYRIGHT (c) 2006 by eXept Software AG
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     3
	      All Rights Reserved
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     4
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     5
 This software is furnished under a license and may be used
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     6
 only in accordance with the terms of that license and with the
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     9
 other person.  No title to or ownership of the software is
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    10
 hereby transferred.
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    11
"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libcomp' }"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
    14
"{ NameSpace: Smalltalk }"
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
    15
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Parser subclass:#AbstractSyntaxHighlighter
2525
f08c56018d9b lifted the method instvar
Claus Gittinger <cg@exept.de>
parents: 2506
diff changeset
    17
	instanceVariableNames:'method sourceText preferences fullSelectorCheck'
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'System-Compiler'
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    23
!AbstractSyntaxHighlighter class methodsFor:'documentation'!
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    24
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    25
copyright
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    26
"
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    27
 COPYRIGHT (c) 2006 by eXept Software AG
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    28
	      All Rights Reserved
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    29
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    30
 This software is furnished under a license and may be used
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    31
 only in accordance with the terms of that license and with the
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    33
 be provided or otherwise made available to, or used by, any
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    34
 other person.  No title to or ownership of the software is
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    35
 hereby transferred.
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    36
"
3345
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    37
!
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    38
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    39
documentation
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    40
"
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    41
    common superclass for (smalltalk-) syntax highlighting.
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    42
"
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    43
! !
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
!AbstractSyntaxHighlighter class methodsFor:'api highlighting'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
formatClassDefinition:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    "format (recolor) a class definition expression in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    ^ self formatExpression:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    54
formatClassDefinition:aString in:aClass elementsInto: elements
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    55
    "format (recolor) a class definition expression in a given class.
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    56
     Return the text containing font changes and color information."
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    57
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    58
    ^ self formatExpression:aString in:aClass
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    59
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    60
    "Created: / 10-04-2011 / 18:18:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    61
!
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    62
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
formatExpression:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    "format (recolor) an expression in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    |parser tree text endPos|
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    aString isNil ifTrue:[^ nil].
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    parser := self for:(ReadStream on:aString string) in:aClass.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    parser ignoreErrors:true.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    parser ignoreWarnings:true.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    parser sourceText:(text := aString string asText).
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "/ use an array here - this can be changed much faster using #at:put:
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    text emphasisCollection:(Array new:aString size).
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    parser nextToken.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    tree := parser expression.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    "/ now, convert the emphasis-array to a runArray
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    text emphasisCollection:(text emphasis asRunArray).
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    tree == #Error ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    84
	"/ mhmh - which is better ...
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    85
	"/ alternative1: color rest after error in red
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    86
"/        text
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    87
"/            emphasizeFrom:(parser sourceStream position)
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    88
"/            to:text size
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
"/            with:(#color->Color red).
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    92
	"/ alternative2: take original emphasis for rest
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    94
	endPos := parser sourceStream position + 1.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    95
	endPos >= text size ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    96
	    ^ text
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    97
	].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
    98
	^ (text copyTo:endPos) , (aString copyFrom:(endPos+1))
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   100
	"/ alternative3: no emphasis for rest.
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
"/        ^ text "/ aString
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    ].
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    ^ text
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   108
	formatExpression:'(1 + 2) max:5'
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   109
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    "Modified: / 7.4.1998 / 09:57:19 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "Created: / 9.4.1998 / 16:57:16 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
formatMethod:aString in:aClass
3191
e538b29d3cfb Mark methods as obsolete
Stefan Vogel <sv@exept.de>
parents: 3189
diff changeset
   117
    <resource: #obsolete>
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    self obsoleteMethodWarning:'use #formatMethodSource:in:'.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    ^ self formatMethod:nil source:aString in:aClass using:nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   126
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   131
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    "Modified: / 28-04-2010 / 13:03:04 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
formatMethod:aString in:aClass using:preferencesOrNil
3191
e538b29d3cfb Mark methods as obsolete
Stefan Vogel <sv@exept.de>
parents: 3189
diff changeset
   138
    <resource: #obsolete>
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    self obsoleteMethodWarning:'use #formatMethodSource:in:using:'.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    ^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    "Modified: / 28-04-2010 / 13:03:15 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
formatMethod:methodOrNil source:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    ^ self formatMethod:methodOrNil source:aString in:aClass using:nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   156
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   161
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
    "Created: / 28-04-2010 / 13:44:24 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    |highlighter tree text endPos eColor|
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    aString isNil ifTrue:[^ nil].
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    Error handle:[:ex |
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   176
	Transcript showCR:ex description.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   177
	self breakPoint:#cg.
3201
13eb554c3f26 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3191
diff changeset
   178
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   179
	ex creator isHandled ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   180
	    ex reject.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   181
	].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   182
	(ParseError handles:ex) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   183
	    "Parse error may happen when re-formatting incomplete code while editing"
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   184
	    ('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   185
	    "/ ex suspendedContext fullPrintAll.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   186
	].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   187
	^ aString
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    ] do:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   189
	highlighter := self for:(ReadStream on:aString string) in:aClass.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   190
	highlighter method:methodOrNil.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   191
	preferencesOrNil notNil ifTrue:[highlighter preferences:preferencesOrNil].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   192
	"/ highlighter ignoreErrors:true.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   193
	highlighter ignoreWarnings:true.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   194
	highlighter sourceText:(text := aString string asText).
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   196
	"/ use an array here - this can be changed much faster using #at:put:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   197
	text emphasisCollection:(Array new:aString size).
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   199
	tree := highlighter parseMethod.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   200
	"/ now, convert the emphasis-array to a runArray
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   201
	text emphasisCollection:(text emphasis asRunArray).
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   203
	tree == #Error ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   204
	    eColor := UserPreferences current errorColor.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   205
	    eColor notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   206
		"/ mhmh - which is better ...
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   207
		"/ alternative1: color rest after error in red
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   208
		text
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   209
		    emphasizeFrom:(highlighter sourceStream position + 1)
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   210
		    to:text size
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   211
		    with:(#color->eColor).
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   212
	    ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   213
		"/ alternative2: take original emphasis for rest
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   215
		endPos := highlighter sourceStream position + 1.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   216
		endPos >= text size ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   217
		    ^ text
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   218
		].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   219
		^ (text copyTo:endPos) , (aString copyFrom:(endPos+1))
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   220
	    ].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   221
	    "/ alternative3: no emphasis for rest.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   222
	].
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   223
	^ text
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    ]
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   227
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   232
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    "Created: / 28-04-2010 / 13:01:42 / cg"
2527
a87cf2c8edf2 changed: #formatMethod:source:in:using:
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   236
    "Modified: / 05-07-2011 / 11:22:20 / cg"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
2526
ecd1ee8f03bc category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   239
formatMethod:aMethodOrNil source:aString in:aClass using:preferencesOrNil elementsInto: elements
2568
44f3c6ce19f1 fixed #formatMethod:source:in:using:elementsInto:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2527
diff changeset
   240
44f3c6ce19f1 fixed #formatMethod:source:in:using:elementsInto:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2527
diff changeset
   241
    ^ self formatMethod:aMethodOrNil source:aString in:aClass using:preferencesOrNil
2526
ecd1ee8f03bc category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   242
ecd1ee8f03bc category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   243
    "Created: / 05-07-2011 / 10:41:14 / cg"
2568
44f3c6ce19f1 fixed #formatMethod:source:in:using:elementsInto:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2527
diff changeset
   244
    "Modified: / 20-07-2011 / 16:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2526
ecd1ee8f03bc category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   245
!
ecd1ee8f03bc category of: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   246
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
formatMethodSource:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    ^ self formatMethod:nil source:aString in:aClass using:nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   255
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   260
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    "Created: / 28-04-2010 / 12:58:13 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
formatMethodSource:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
    ^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
    "Modified: / 28-04-2010 / 13:02:11 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   275
!AbstractSyntaxHighlighter class methodsFor:'misc'!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   276
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   277
collectionEnumerationSelectors
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   278
    "these are considered wellknown, builtin selectors of very common
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   279
     collection enumeration methods.
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   280
     These are optionally shown with another color (dark green)"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   281
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   282
    ^ #(
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   283
	collect:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   284
	select:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   285
	inject:into:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   286
	count:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   287
	collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   288
	select:thenCollect:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   289
    )
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   290
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   291
    "Created: / 14-02-2012 / 15:56:59 / cg"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   292
!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   293
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   294
controlFlowSelectors
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   295
    "these are considered wellknown, builtin selectors of very common
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   296
     control flow constructs. Correspond to syntax or special forms in other
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   297
     languages. These are optionally shown with another color (blue)"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   298
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   299
    ^ #(
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   300
	ifTrue: ifFalse:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   301
	ifTrue:ifFalse: ifFalse:ifTrue:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   302
	ifNil: ifNotNil:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   303
	ifNil:ifNotNil: ifNotNil:ifNil:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   304
	and: or:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   305
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   306
	whileTrue:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   307
	whileFalse:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   308
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   309
	to:do:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   310
	downTo:do:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   311
	to:by:do:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   312
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   313
	loop
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   314
	whileTrue
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   315
	whileFalse
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   316
	doWhile:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   317
	doUntil:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   318
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   319
	do:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   320
	doWithIndex:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   321
	pairWiseDo:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   322
	keysAndValuesDo:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   323
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   324
	withPriority:do:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   325
	handle:do:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   326
	on:do:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   327
	catch:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   328
	ignoreIn:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   329
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   330
	"/ newProcess
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   331
	fork:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   332
	ensure:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   333
	ifCurtailed:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   334
	valueOnUnwindDo:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   335
	valueNowOrOnUnwindDo:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   336
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   337
	caseOf:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   338
	caseOf:otherwise:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   339
    )
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   340
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   341
    "Created: / 08-09-2006 / 15:56:47 / cg"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   342
!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   343
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   344
debugSelectors
3235
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   345
    "these are considered harmful if left in a deployed application:
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   346
     selectors for debugging which open a debugger (unless haltSignal is
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   347
     caught or disabled, which end-user apps should do).
3235
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   348
     These are optionally shown with another color (redish)"
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   349
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   350
    ^ #(
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   351
	halt halt:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   352
    )
3235
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   353
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   354
    "Modified (comment): / 27-07-2013 / 11:45:07 / cg"
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   355
!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   356
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   357
errorRaisingSelectors
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   358
    "these are error raisers.
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   359
     These are optionally shown with another color (red)"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   360
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   361
    ^ #(
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   362
	error error:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   363
	raise raiseRequest:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   364
	raiseErrorString: raiseRequestErrorString:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   365
	raiseWith: raiseRequestWith:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   366
	raiseWith:errorString: raiseRequestWith:errorString:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   367
	subclassResponsibility
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   368
	obsoleteMethodWarning obsoleteMethodWarning:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   369
    )
3342
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   370
!
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   371
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   372
isControlFlowSelector:aSelector
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   373
    "these are considered wellknown, builtin selectors of very common
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   374
     control flow constructs. Correspond to syntax or special forms in other
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   375
     languages. These are optionally shown with another color (blue)"
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   376
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   377
    (self controlFlowSelectors includesIdentical:aSelector) ifTrue:[^ true].
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   378
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   379
    true "((aSelector startsWith:'with') or:[ aSelector startsWith:'all'])" ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   380
	((aSelector endsWith:'do:') or:[ aSelector endsWith:'Do:']) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   381
	    ^ true
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   382
	]
3342
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   383
    ].
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   384
    ^ false.
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   385
! !
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   386
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   387
!AbstractSyntaxHighlighter class methodsFor:'utilities'!
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   388
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   389
mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   390
    sourceText emphasisFrom:pos1 to:pos2 add:addedEmphasis
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   391
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   392
    "Created: / 01-06-2012 / 21:43:36 / cg"
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   393
!
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   394
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   395
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   396
    self mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:nil
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   397
!
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   398
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   399
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontIn
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   400
    |e p2 clr|
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   401
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   402
    (clrIn isNil or:[clrIn = Color black]) ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   403
	e := fontEmp
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   404
    ] ifFalse:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   405
	clr := clrIn onDevice:Screen current.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   406
	fontEmp isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   407
	    e := (#color->clr)
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   408
	] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   409
	    e := Text addEmphasis:fontEmp to:(#color->clr).
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   410
	]
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   411
    ].
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   412
    fontIn notNil ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   413
	e := Text addEmphasis:e to:(#font->fontIn)
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   414
    ].
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   415
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   416
    (p2 := pos2) isNil ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   417
	p2 := sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   418
    ] ifFalse:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   419
	p2 := p2 min:sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   420
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   421
    sourceText emphasizeFrom:pos1 to:p2 with:e
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   422
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   423
    "Created: / 01-06-2012 / 21:42:41 / cg"
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   424
!
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   425
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   426
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   427
    |e p2 clr fgClr|
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   428
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   429
    fgClr := fgClr1 ? fgClr2.
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   430
    (fgClr isNil or:[fgClr = Color black]) ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   431
	e := fontEmp
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   432
    ] ifFalse:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   433
	clr := fgClr onDevice:Screen current.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   434
	fontEmp isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   435
	    e := (#color->clr)
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   436
	] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   437
	    e := Text addEmphasis:fontEmp to:(#color->clr).
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   438
	]
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   439
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   440
    bgClr notNil ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   441
	e := Text addEmphasis:(#backgroundColor->bgClr) to:e.
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   442
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   443
    (p2 := pos2) isNil ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   444
	p2 := sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   445
    ] ifFalse:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   446
	p2 := p2 min:sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   447
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   448
    sourceText emphasizeFrom:pos1 to:p2 with:e
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   449
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   450
    "Created: / 01-06-2012 / 21:44:17 / cg"
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   451
!
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   452
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   453
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp ifNil:fontEmp2 color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   454
    |e p2 clr fgClr|
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   455
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   456
    fgClr := fgClr1 ? fgClr2.
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   457
    (fgClr isNil or:[fgClr = Color black]) ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   458
        e := fontEmp ? fontEmp2
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   459
    ] ifFalse:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   460
        clr := fgClr onDevice:Screen current.
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   461
        (fontEmp ? fontEmp2) isNil ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   462
            e := (#color->clr)
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   463
        ] ifFalse:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   464
            e := Text addEmphasis:(fontEmp ? fontEmp2) to:(#color->clr).
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   465
        ]
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   466
    ].
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   467
    bgClr notNil ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   468
        e := Text addEmphasis:(#backgroundColor->bgClr) to:e.
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   469
    ].
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   470
    (p2 := pos2) isNil ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   471
        p2 := sourceText size
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   472
    ] ifFalse:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   473
        p2 := p2 min:sourceText size
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   474
    ].
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   475
    sourceText emphasizeFrom:pos1 to:p2 with:e
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   476
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   477
    "Created: / 01-06-2012 / 21:44:17 / cg"
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   478
! !
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   479
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
!AbstractSyntaxHighlighter methodsFor:'accessing'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
method:aMethod
2525
f08c56018d9b lifted the method instvar
Claus Gittinger <cg@exept.de>
parents: 2506
diff changeset
   483
    "the original method, if known (for subclasses which can make use of it)"
f08c56018d9b lifted the method instvar
Claus Gittinger <cg@exept.de>
parents: 2506
diff changeset
   484
f08c56018d9b lifted the method instvar
Claus Gittinger <cg@exept.de>
parents: 2506
diff changeset
   485
    method := aMethod.
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
    "Created: / 28-04-2010 / 13:15:33 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
preferences:something
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
    preferences := something.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
sourceText
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
    ^ sourceText
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
    "Created: / 31.3.1998 / 11:49:05 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
sourceText:aString
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
    sourceText := aString.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
    "Created: / 31-03-1998 / 11:49:05 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
    "Modified: / 28-04-2010 / 13:22:27 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
!AbstractSyntaxHighlighter methodsFor:'error handling'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
parseError:aMessage position:position to:endPos
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
"/ Transcript showCR:aMessage.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    super parseError:aMessage position:position to:endPos.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   513
    self
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   514
	markFrom:position to:endPos
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   515
	withEmphasis:nil color:UserPreferences current errorColor
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
showErrorMessage:aMessage position:pos
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
"/ Transcript showCR:aMessage.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
    super showErrorMessage:aMessage position:pos.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   522
    self
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   523
	markFrom:pos to:nil
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   524
	withEmphasis:nil color:UserPreferences current errorColor
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
syntaxError:aMessage position:position to:endPos
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
"/ Transcript showCR:aMessage.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    super syntaxError:aMessage position:position to:endPos.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   531
    self
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   532
	markFrom:position to:endPos
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   533
	withEmphasis:nil color:UserPreferences current errorColor
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
warning:msg position:pos1 to:pos2
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
"/    self markUnknownIdentifierFrom:pos1 to:pos2
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
"/    self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   540
"/        markFrom:pos1 to:pos2
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
"/        withEmphasis:nil color:UserPreferences current errorColor
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
    "Modified: / 25.9.1999 / 18:42:30 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
!AbstractSyntaxHighlighter methodsFor:'initialization'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
initialize
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
    super initialize.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
    foldConstants := false.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
    preferences := UserPreferences current.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
    fullSelectorCheck := preferences fullSelectorCheck.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
    "Created: / 31-03-1998 / 15:12:55 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
    "Modified: / 28-04-2010 / 13:17:45 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
!AbstractSyntaxHighlighter methodsFor:'misc'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
2817
b92ea70a5a9f added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   561
collectionEnumerationSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   562
    ^ self class collectionEnumerationSelectors
2817
b92ea70a5a9f added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   563
!
b92ea70a5a9f added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   564
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
controlFlowSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   566
    ^ self class controlFlowSelectors
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   569
debugSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   570
    ^ self class debugSelectors
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   571
!
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   572
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
defineAsUndeclaredVariable:aName
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
    "redefined to NOT declare undefined vars"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
    ^ VariableNode globalNamed:aName
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
    "Modified: / 19.10.1998 / 19:38:12 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   581
errorRaisingSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   582
    ^ self class errorRaisingSelectors
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   583
!
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   584
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
isSyntaxHighlighter
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
    ^ true
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
plausibilityCheck:aNode
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    "redefined to NOT do checks"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
    ^ nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
    "Modified: / 19.10.1998 / 19:38:12 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
    "Created: / 19.10.1998 / 19:57:18 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
!AbstractSyntaxHighlighter methodsFor:'syntax detection'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
markFrom:pos1 to:pos2 withAddedEmphasis:addedEmphasis
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   602
    self class
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   603
	mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
    "Created: / 15-01-2008 / 11:48:18 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   609
    self class
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   610
	mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
    "Created: / 31-03-1998 / 13:26:53 / cg"
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   613
    "Modified: / 01-06-2012 / 21:43:04 / cg"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   616
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   617
    self class
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   618
	mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   619
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   620
    "Created: / 31-03-1998 / 13:26:53 / cg"
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   621
    "Modified: / 01-06-2012 / 21:43:04 / cg"
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   622
!
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   623
2813
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   624
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   625
    self class
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   626
	mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
2813
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   627
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   628
    "Created: / 13-02-2012 / 11:48:09 / cg"
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   629
!
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   630
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   631
markFrom:pos1 to:pos2 withEmphasis:fontEmp ifNil:fontEmp2 color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   632
    self class
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   633
        mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp ifNil:fontEmp2 color:fgClr1 ifNil:fgClr2 backgroundColor:bgClr
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   634
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   635
    "Created: / 13-02-2012 / 11:48:09 / cg"
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   636
!
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   637
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
markVariable:v
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
    |pos endPos|
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
    pos := tokenPosition.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
    endPos := pos+tokenName size-1.
3189
5a4bb1727d08 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
   643
    self markVariable:v from:pos to:endPos assigned:false
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
2464
595ec0d9efa9 comment/format in: #markVariable:
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
   645
    "Modified: / 30-11-2010 / 14:44:28 / cg"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
!AbstractSyntaxHighlighter class methodsFor:'documentation'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
2663
e94fe6b650ad changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents: 2662
diff changeset
   650
version
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   651
    ^ '$Header: /cvs/stx/stx/libcomp/AbstractSyntaxHighlighter.st,v 1.33 2015-02-01 21:53:37 cg Exp $'
2663
e94fe6b650ad changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents: 2662
diff changeset
   652
!
e94fe6b650ad changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents: 2662
diff changeset
   653
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
version_CVS
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   655
    ^ '$Header: /cvs/stx/stx/libcomp/AbstractSyntaxHighlighter.st,v 1.33 2015-02-01 21:53:37 cg Exp $'
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
   656
!
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
   657
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
   658
version_SVN
3189
5a4bb1727d08 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
   659
    ^ '$ Id $'
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
! !
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   661