AbstractSyntaxHighlighter.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 27 Oct 2022 14:53:59 +0100
branchjv
changeset 4735 3b11fb3ede98
parent 4733 e19fe34c0dd8
permissions -rw-r--r--
Allow single underscore as method / block argument and temporaries This commit is a follow up for 38b221e.
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
4275
e06f4b087e47 Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4259
diff changeset
     3
 COPYRIGHT (c) 2016-2017 Jan Vrany
4733
e19fe34c0dd8 `AbstractSyntaxHighlighter`: use set color preferences (theme) when marking error
Jan Vrany <jan.vrany@labware.com>
parents: 4723
diff changeset
     4
 COPYRIGHT (c) 2021 LabWare
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     5
	      All Rights Reserved
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     6
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
     7
 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
     8
 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
     9
 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
    10
 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
    11
 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
    12
 hereby transferred.
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    13
"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libcomp' }"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
    16
"{ NameSpace: Smalltalk }"
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
    17
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Parser subclass:#AbstractSyntaxHighlighter
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
    19
	instanceVariableNames:'method sourceText preferences fullSelectorCheck commentColor
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
    20
		commentEmphasis constantColor constantEmphasis'
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	classVariableNames:''
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	poolDictionaries:''
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	category:'System-Compiler'
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    26
!AbstractSyntaxHighlighter class methodsFor:'documentation'!
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    27
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    28
copyright
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
 COPYRIGHT (c) 2006 by eXept Software AG
4275
e06f4b087e47 Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4259
diff changeset
    31
 COPYRIGHT (c) 2016-2017 Jan Vrany
4733
e19fe34c0dd8 `AbstractSyntaxHighlighter`: use set color preferences (theme) when marking error
Jan Vrany <jan.vrany@labware.com>
parents: 4723
diff changeset
    32
 COPYRIGHT (c) 2021 LabWare
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    33
	      All Rights Reserved
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    34
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    35
 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
    36
 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
    37
 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
    38
 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
    39
 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
    40
 hereby transferred.
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    41
"
3345
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    42
!
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    43
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    44
documentation
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    45
"
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    46
    common superclass for (smalltalk-) syntax highlighting.
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    47
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    48
    This will parse the source code and update the local copy of the
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    49
    sourceText (in that instvar) by changing emphasis and color,
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    50
    as syntax elements are encountered.
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    51
    This is done by redefining appropriate markXXX methods, which are
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    52
    called by the parser whenever an interesting syntactic construct is encountered.
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    53
    These methods are no-ops in the Parser class, but redefined here to update
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    54
    the colorization of sourceText.
4200
e0b3fd0f438c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4198
diff changeset
    55
e0b3fd0f438c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4198
diff changeset
    56
    Caveat:
e0b3fd0f438c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4198
diff changeset
    57
        used to be a smalltalk syntax highlighter and therefore (wrongly) subclassed Parser.
e0b3fd0f438c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4198
diff changeset
    58
        However, over time, much functionality was added, which is of use for other languages also
e0b3fd0f438c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4198
diff changeset
    59
        and this class will therefore be changed to use composition and have parsing delegated.
e0b3fd0f438c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4198
diff changeset
    60
        to be independent of the language and to not inherit stuff, which is not needed.
3345
718b64ff3db3 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3344
diff changeset
    61
"
2506
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
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
!AbstractSyntaxHighlighter class methodsFor:'api highlighting'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
formatClassDefinition:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    "format (recolor) a class definition expression in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    ^ self formatExpression:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    73
formatClassDefinition:aString in:aClass elementsInto: elements
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    74
    "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
    75
     Return the text containing font changes and color information."
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    76
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    77
    ^ self formatExpression:aString in:aClass
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    78
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    79
    "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
    80
!
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
    81
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
formatExpression:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    "format (recolor) an expression in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
    86
    |parser|
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    aString isNil ifTrue:[^ nil].
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    parser := self for:(ReadStream on:aString string) in:aClass.
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
    91
    ^ parser formatExpression:aString in:aClass
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
     self
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    95
        formatExpression:'(1 + 2) max:5'
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
    96
        in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "Modified: / 7.4.1998 / 09:57:19 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "Created: / 9.4.1998 / 16:57:16 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
formatMethod:aString in:aClass
3191
e538b29d3cfb Mark methods as obsolete
Stefan Vogel <sv@exept.de>
parents: 3189
diff changeset
   104
    <resource: #obsolete>
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    self obsoleteMethodWarning:'use #formatMethodSource:in:'.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    ^ self formatMethod:nil source:aString in:aClass using:nil
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
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   113
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   118
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    "Modified: / 28-04-2010 / 13:03:04 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
formatMethod:aString in:aClass using:preferencesOrNil
3191
e538b29d3cfb Mark methods as obsolete
Stefan Vogel <sv@exept.de>
parents: 3189
diff changeset
   125
    <resource: #obsolete>
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    self obsoleteMethodWarning:'use #formatMethodSource:in:using:'.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    ^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    "Modified: / 28-04-2010 / 13:03:15 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
formatMethod:methodOrNil source:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    ^ self formatMethod:methodOrNil source:aString in:aClass using:nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
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
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   143
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   148
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    "Created: / 28-04-2010 / 13:44:24 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    aString isNil ifTrue:[^ nil].
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   159
    ^ (self for:aString in:aClass)
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   160
        formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   161
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
     self
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   164
        formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
'
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   169
        in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    "Created: / 28-04-2010 / 13:01:42 / cg"
2527
a87cf2c8edf2 changed: #formatMethod:source:in:using:
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   173
    "Modified: / 05-07-2011 / 11:22:20 / cg"
4323
8f45288cf559 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4272
diff changeset
   174
    "Modified: / 22-12-2018 / 09:01:10 / Claus Gittinger"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
formatMethodSource:aString in:aClass
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    ^ self formatMethod:nil source:aString in:aClass using:nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
     self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   185
	formatMethod:'foo
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    ^ self bar:''hello''.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
'
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   190
	in:UndefinedObject
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    "
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    "Created: / 28-04-2010 / 12:58:13 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
formatMethodSource:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    "format (recolor) a method in a given class.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
     Return the text containing font changes and color information."
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    ^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    "Modified: / 28-04-2010 / 13:02:11 / cg"
3716
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   203
!
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   204
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   205
formatStatements:aString in:aClass
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   206
    "Format (recolor) a list of statements with optional temporaries in a given class.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   207
     Return the text containing font changes and color information."
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   208
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   209
    |parser tree text|
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   210
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   211
    aString isNil ifTrue:[^ nil].
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   212
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   213
    parser := self for:(ReadStream on:aString string) in:aClass.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   214
    parser ignoreErrors:true.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   215
    parser ignoreWarnings:true.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   216
    parser sourceText:(text := aString string asText).
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   217
    "/ use an array here - this can be changed much faster using #at:put:
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   218
    text emphasisCollection:(Array new:aString size).
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   219
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   220
    parser nextToken.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   221
    tree := parser parseMethodBody.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   222
    "/ now, convert the emphasis-array to a runArray
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   223
    text emphasisCollection:(text emphasis asRunArray).
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   224
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   225
    tree == #Error ifTrue:[
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   226
        ^ self colorize:text forErrorAtPosition:parser sourceStream position withOriginal:aString.
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   227
    ].
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   228
    ^ text
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   229
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   230
    "
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   231
     SyntaxHighlighter
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   232
        formatStatements:'| a b | a error: b'
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   233
        in:UndefinedObject
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   234
    "
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   235
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   236
    "Created: / 22-02-2016 / 20:50:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
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
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   239
!AbstractSyntaxHighlighter class methodsFor:'highlighting'!
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   240
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   241
colorize:text forErrorAtPosition:pos withOriginal:originalString
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   242
    |eColor endPos|
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   243
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   244
    endPos := pos + 1.
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   245
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   246
    "/ mhmh - which is better ...
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   247
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   248
    "/ alternative1: colorize the rest after the error in red
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   249
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   250
    eColor := UserPreferences current errorColor.
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   251
    eColor notNil ifTrue:[
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   252
        ^ text
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   253
            emphasizeFrom:endPos 
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   254
            to:text size 
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   255
            with:(#color->eColor).
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   256
    ].
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   257
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   258
    "/ alternative2: take the original emphasis for the rest
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   259
    endPos >= text size ifTrue:[
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   260
        ^ text
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   261
    ] ifFalse:[
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   262
        ^ (text copyTo:endPos) , (originalString copyFrom:(endPos+1))
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   263
    ].
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   264
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   265
    "/ alternative3: no emphasis for rest.
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   266
    ^ text
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   267
! !
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   268
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   269
!AbstractSyntaxHighlighter class methodsFor:'misc'!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   270
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   271
collectionEnumerationSelectors
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   272
    "these are considered wellknown, builtin selectors of very common
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   273
     collection enumeration methods.
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   274
     These are optionally shown with another color (dark green)"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   275
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   276
    ^ #(
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   277
	collect:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   278
	select:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   279
	inject:into:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   280
	count:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   281
	collect:thenSelect:
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   282
	select:thenCollect:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   283
    )
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   284
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   285
    "Created: / 14-02-2012 / 15:56:59 / cg"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   286
!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   287
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   288
controlFlowSelectors
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   289
    "these are considered wellknown, builtin selectors of very common
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   290
     control flow constructs. Correspond to syntax or special forms in other
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   291
     languages. These are optionally shown with another color (blue)"
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
    ^ #(
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   294
        ifTrue: ifFalse:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   295
        ifTrue:ifFalse: ifFalse:ifTrue:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   296
        ifNil: ifNotNil:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   297
        ifNil:ifNotNil: ifNotNil:ifNil:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   298
        and: or:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   299
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   300
        whileTrue:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   301
        whileFalse:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   302
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   303
        to:do:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   304
        downTo:do:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   305
        to:by:do:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   306
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   307
        loop
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   308
        repeat
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   309
        whileTrue
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   310
        whileFalse
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   311
        doWhile:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   312
        doUntil:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   313
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   314
        do:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   315
        doWithIndex:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   316
        pairWiseDo:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   317
        keysAndValuesDo:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   318
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   319
        withPriority:do:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   320
        handle:do:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   321
        on:do:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   322
        catch:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   323
        ignoreIn:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   324
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   325
        "/ newProcess
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   326
        fork:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   327
        ensure:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   328
        ifCurtailed:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   329
        valueOnUnwindDo:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   330
        valueNowOrOnUnwindDo:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   331
3977
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   332
        caseOf:
39fe23d7db13 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   333
        caseOf:otherwise:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   334
    )
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   335
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   336
    "Created: / 08-09-2006 / 15:56:47 / cg"
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   337
!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   338
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   339
debugSelectors
3235
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   340
    "these are considered harmful if left in a deployed application:
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   341
     selectors for debugging which open a debugger (unless haltSignal is
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   342
     caught or disabled, which end-user apps should do).
3235
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   343
     These are optionally shown with another color (redish)"
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   344
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   345
    ^ #(
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   346
	halt halt:
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   347
    )
3235
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   348
6385bfe15842 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3231
diff changeset
   349
    "Modified (comment): / 27-07-2013 / 11:45:07 / cg"
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   350
!
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   351
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   352
errorRaisingSelectors
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   353
    "these are error raisers.
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   354
     These are optionally shown with another color (red)"
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
    ^ #(
4272
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   357
        error error: error:mayProceed: proceedableError:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   358
        raise raiseRequest:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   359
        raiseErrorString: raiseRequestErrorString:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   360
        raiseWith: raiseRequestWith:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   361
        raiseWith:errorString: raiseRequestWith:errorString:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   362
        subclassResponsibility
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   363
        obsoleteMethodWarning obsoleteMethodWarning:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   364
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   365
        shouldNeverBeReached shouldNeverBeSent 
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   366
        shouldNotImplement shouldImplement
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   367
        subscriptBoundsError typeCheckError
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   368
        
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   369
        elementBoundsError errorInvalidFormat
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   370
        elementNotCharacter elementNotInteger
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   371
        errorKeyNotFound: errorNotFound errorNotFound:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   372
        indexNotInteger indexNotInteger:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   373
        indexNotIntegerOrOutOfBounds:
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   374
        mustBeRectangle mustBeString notIndexed
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   375
        notYetImplemented primitiveFailed
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   376
        
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   377
    )
4272
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   378
78ea887ddeb6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 4264
diff changeset
   379
    "Modified: / 28-05-2018 / 15:02:43 / Claus Gittinger"
3342
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   380
!
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   381
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   382
isControlFlowSelector:aSelector
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   383
    "these are considered wellknown, builtin selectors of very common
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   384
     control flow constructs. Correspond to syntax or special forms in other
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   385
     languages. These are optionally shown with another color (blue)"
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   386
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   387
    (self controlFlowSelectors includesIdentical:aSelector) ifTrue:[^ true].
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   388
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   389
    true "((aSelector startsWith:'with') or:[ aSelector startsWith:'all'])" ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   390
	((aSelector endsWith:'do:') or:[ aSelector endsWith:'Do:']) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   391
	    ^ true
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   392
	]
3342
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   393
    ].
d7aec03dc509 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3264
diff changeset
   394
    ^ false.
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   395
! !
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   396
3732
afcdb234bf38 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3675
diff changeset
   397
!AbstractSyntaxHighlighter class methodsFor:'queries'!
afcdb234bf38 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3675
diff changeset
   398
afcdb234bf38 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3675
diff changeset
   399
isAbstract
afcdb234bf38 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3675
diff changeset
   400
    ^ self == AbstractSyntaxHighlighter
afcdb234bf38 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3675
diff changeset
   401
! !
afcdb234bf38 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3675
diff changeset
   402
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   403
!AbstractSyntaxHighlighter class methodsFor:'utilities'!
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   404
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   405
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
   406
    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
   407
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   408
    "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
   409
!
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   410
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   411
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   412
    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
   413
!
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
mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontIn
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   416
    "all positions are 1-based"
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   417
    
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   418
    |e p2 clr|
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   419
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   420
    (clrIn isNil or:[clrIn = Color black]) ifTrue:[
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   421
        e := fontEmp
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   422
    ] ifFalse:[
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   423
        clr := clrIn onDevice:Screen current.
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   424
        fontEmp isNil ifTrue:[
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   425
            e := (#color->clr)
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   426
        ] ifFalse:[
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   427
            e := Text addEmphasis:fontEmp to:(#color->clr).
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   428
        ]
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   429
    ].
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   430
    fontIn notNil ifTrue:[
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   431
        e := Text addEmphasis:e to:(#font->fontIn)
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   432
    ].
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   433
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   434
    (p2 := pos2) isNil ifTrue:[
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   435
        p2 := sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   436
    ] ifFalse:[
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   437
        p2 := p2 min:sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   438
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   439
    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
   440
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   441
    "Created: / 01-06-2012 / 21:42:41 / cg"
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   442
    "Modified (comment): / 21-10-2017 / 14:24:20 / cg"
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   443
!
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   444
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   445
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
   446
    |e p2 clr fgClr|
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
    fgClr := fgClr1 ? fgClr2.
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   449
    (fgClr isNil or:[fgClr = Color black]) ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   450
	e := fontEmp
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   451
    ] ifFalse:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   452
	clr := fgClr onDevice:Screen current.
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   453
	fontEmp isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   454
	    e := (#color->clr)
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   455
	] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   456
	    e := Text addEmphasis:fontEmp to:(#color->clr).
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   457
	]
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   458
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   459
    bgClr notNil ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   460
	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
   461
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   462
    (p2 := pos2) isNil ifTrue:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   463
	p2 := sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   464
    ] ifFalse:[
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   465
	p2 := p2 min:sourceText size
2872
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   466
    ].
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   467
    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
   468
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   469
    "Created: / 01-06-2012 / 21:44:17 / cg"
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   470
!
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   471
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   472
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
   473
    |e p2 clr fgClr|
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
    fgClr := fgClr1 ? fgClr2.
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   476
    (fgClr isNil or:[fgClr = Color black]) ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   477
        e := fontEmp ? fontEmp2
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   478
    ] ifFalse:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   479
        clr := fgClr onDevice:Screen current.
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   480
        (fontEmp ? fontEmp2) isNil ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   481
            e := (#color->clr)
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   482
        ] ifFalse:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   483
            e := Text addEmphasis:(fontEmp ? fontEmp2) to:(#color->clr).
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   484
        ]
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   485
    ].
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   486
    bgClr notNil ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   487
        e := Text addEmphasis:(#backgroundColor->bgClr) to:e.
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   488
    ].
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   489
    (p2 := pos2) isNil ifTrue:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   490
        p2 := sourceText size
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   491
    ] ifFalse:[
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   492
        p2 := p2 min:sourceText size
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   493
    ].
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   494
    sourceText emphasizeFrom:pos1 to:p2 with:e
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   495
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   496
    "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
   497
! !
f992970ef1cd refactored mark code for reuse by other classes
Claus Gittinger <cg@exept.de>
parents: 2817
diff changeset
   498
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
!AbstractSyntaxHighlighter methodsFor:'accessing'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   501
fetchHeavilyUsedPreferenceValues
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   502
    preferences isNil ifTrue:[
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   503
        commentColor :=  commentEmphasis := nil.
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   504
        constantColor := constantEmphasis := nil.
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   505
        ^ self.
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   506
    ].
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   507
    
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   508
    commentColor := preferences commentColor.
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   509
    commentEmphasis := preferences commentEmphasis.
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   510
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   511
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   512
    constantColor := preferences constantColor.
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   513
    constantEmphasis := preferences constantEmphasis.
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   514
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   515
    "Created: / 21-10-2017 / 14:13:33 / cg"
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   516
    "Modified: / 31-05-2018 / 12:21:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   517
!
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   518
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
method:aMethod
2525
f08c56018d9b lifted the method instvar
Claus Gittinger <cg@exept.de>
parents: 2506
diff changeset
   520
    "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
   521
f08c56018d9b lifted the method instvar
Claus Gittinger <cg@exept.de>
parents: 2506
diff changeset
   522
    method := aMethod.
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
    "Created: / 28-04-2010 / 13:15:33 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   527
preferences: aUserPreferences
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   528
    preferences := aUserPreferences.
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   529
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   530
    fullSelectorCheck := UserPreferences current fullSelectorCheck.
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   531
    self fetchHeavilyUsedPreferenceValues.
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   532
    
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   533
    "Modified: / 21-10-2017 / 14:20:06 / cg"
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   534
    "Modified (format): / 05-12-2017 / 21:04:36 / jv"
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   535
    "Modified (format): / 05-12-2017 / 21:05:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   536
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
sourceText
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   540
    "retrieve the updated source text after the highlighting process"
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   541
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
    ^ sourceText
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
    "Created: / 31.3.1998 / 11:49:05 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
sourceText:aString
3599
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   548
    "this text will be updated by the highlighting process"
a999663bd83f some code cleanup
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   549
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
    sourceText := aString.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
    "Created: / 31-03-1998 / 11:49:05 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
    "Modified: / 28-04-2010 / 13:22:27 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   556
!AbstractSyntaxHighlighter methodsFor:'api highlighting'!
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   557
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   558
formatExpression:aString in:aClass
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   559
    "format (recolor) an expression in a given class.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   560
     Return the text containing font changes and color information."
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   561
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   562
    |tree text|
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   563
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   564
    aString isNil ifTrue:[^ nil].
4669
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   565
    classToCompileFor := aClass.
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   566
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   567
    self ignoreErrors:true.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   568
    self ignoreWarnings:true.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   569
    self sourceText:(text := aString string asText).
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   570
    "/ use an array here - this can be changed much faster using #at:put:
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   571
    text emphasisCollection:(Array new:aString size).
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   572
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   573
    self nextToken.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   574
    tree := self expression.
4578
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   575
    tree notNil ifTrue:[
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   576
        "/ now, convert the emphasis-array to a runArray
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   577
        text emphasisCollection:(text emphasis asRunArray).
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   578
4578
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   579
        tree == #Error ifTrue:[
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   580
            ^ self class colorize:text forErrorAtPosition:(self sourceStream position) withOriginal:aString.
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   581
        ].
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   582
    ].
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   583
    ^ text
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   584
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   585
    "
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   586
     self
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   587
        formatExpression:'(1 + 2) max:5'
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   588
        in:UndefinedObject
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   589
    "
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   590
4669
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   591
    "Created: / 09-04-1998 / 16:57:16 / cg"
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   592
    "Modified: / 09-05-2020 / 17:00:01 / cg"
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   593
!
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   594
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   595
formatMethod:methodOrNil source:aString in:aClass using:preferencesOrNil
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   596
    "format (recolor) a method in a given class.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   597
     Return the text containing font changes and color information."
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   598
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   599
    |tree newText|
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   600
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   601
    aString isNil ifTrue:[^ nil].
4669
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   602
    classToCompileFor := aClass.
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   603
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   604
    Error handle:[:ex |
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   605
        "/ Transcript showCR:ex description.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   606
        "/ self breakPoint:#cg.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   607
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   608
        (ParseError handles:ex) ifFalse:[
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   609
            ex creator isHandled ifTrue:[
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   610
                "/ Transcript showCR:'handled' .
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   611
                ex reject.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   612
            ].
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   613
            "Parse error may happen when re-formatting incomplete code while editing"
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   614
"/            ('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   615
            "/ ex suspendedContext fullPrintAll.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   616
        ].
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   617
        ^ self class colorize:(newText ? aString) forErrorAtPosition:(self sourceStream position) withOriginal:aString
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   618
    ] do:[
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   619
        |sourceString|
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   620
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   621
        sourceString := aString string.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   622
        source := sourceString readStream.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   623
        newText := sourceString asUnicode16String asText.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   624
        "/ use an array here (instead of the RunArray) - this can be changed much faster using #at:put:
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   625
        newText emphasisCollection:(Array new:sourceString size).
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   626
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   627
        self method:methodOrNil.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   628
        preferencesOrNil notNil ifTrue:[self preferences:preferencesOrNil].
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   629
        "/ self ignoreErrors:true.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   630
        self ignoreWarnings:true.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   631
        self sourceText:newText.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   632
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   633
        tree := self parseMethod.
4578
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   634
        tree notNil ifTrue:[
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   635
            newText := self sourceText.  "/ might have changed identity
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   636
            "/ now, convert the emphasis-array to a runArray
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   637
            newText emphasisCollection:(newText emphasis asRunArray).
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   638
4578
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   639
            tree == #Error ifTrue:[
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   640
                ^ self class colorize:newText forErrorAtPosition:source position withOriginal:aString.
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   641
            ].
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   642
            self postProcessTree:tree forText:newText
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   643
        ].    
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   644
        ^ newText
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   645
    ]
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   646
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   647
    "
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   648
     self
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   649
        formatMethod:'foo
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   650
    ^ self bar:''hello''.
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   651
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   652
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   653
'
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   654
        in:UndefinedObject
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   655
    "
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   656
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   657
    "Created: / 28-04-2010 / 13:01:42 / cg"
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   658
    "Modified: / 22-12-2018 / 09:01:10 / Claus Gittinger"
4669
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   659
    "Modified: / 09-05-2020 / 16:29:27 / cg"
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   660
!
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   661
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   662
formatMethodSource:aString in:aClass using:preferencesOrNil
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   663
    "format (recolor) a method in a given class.
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   664
     Return the text containing font changes and color information."
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   665
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   666
    ^ self formatMethod:nil source:aString in:aClass using:preferencesOrNil
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   667
c0e6828144eb #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4578
diff changeset
   668
    "Created: / 09-05-2020 / 16:24:32 / cg"
4568
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   669
! !
af6f467152a0 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
   670
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
!AbstractSyntaxHighlighter methodsFor:'error handling'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
parseError:aMessage position:position to:endPos
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
"/ Transcript showCR:aMessage.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
    super parseError:aMessage position:position to:endPos.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
4264
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   677
    self markErrorFrom:position to:endPos
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
showErrorMessage:aMessage position:pos
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
"/ Transcript showCR:aMessage.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
    super showErrorMessage:aMessage position:pos.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
4264
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   684
    self markErrorFrom:pos to:nil "/ to the end
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
syntaxError:aMessage position:position to:endPos
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
"/ Transcript showCR:aMessage.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
    super syntaxError:aMessage position:position to:endPos.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
4264
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   691
    self markErrorFrom:position to:endPos
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
warning:msg position:pos1 to:pos2
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
"/    self markUnknownIdentifierFrom:pos1 to:pos2
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
"/    self
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   698
"/        markFrom:pos1 to:pos2
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
"/        withEmphasis:nil color:UserPreferences current errorColor
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
    "Modified: / 25.9.1999 / 18:42:30 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
!AbstractSyntaxHighlighter methodsFor:'initialization'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
initialize
4114
a68e6f98cb02 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3977
diff changeset
   707
    <modifier: #super> "must be called if redefined"
a68e6f98cb02 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3977
diff changeset
   708
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
    super initialize.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
    foldConstants := false.
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   712
    "/ The `...codeViewThene ? UserPreferences current` trick below is 
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   713
    "/ there to make this code working with both old and editor-thene-aware 
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   714
    "/ code. Will wanish as soon as editor thene support will be
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   715
    "/ integrated.
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   716
    self preferences: (UserPreferences current codeViewTheme ? UserPreferences current).
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
    "Created: / 31-03-1998 / 15:12:55 / cg"
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   719
    "Modified: / 21-10-2017 / 14:20:11 / cg"
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   720
    "Modified: / 05-12-2017 / 21:09:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
!AbstractSyntaxHighlighter methodsFor:'misc'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
2817
b92ea70a5a9f added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   725
collectionEnumerationSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   726
    ^ self class collectionEnumerationSelectors
2817
b92ea70a5a9f added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   727
!
b92ea70a5a9f added: #collectionEnumerationSelectors
Claus Gittinger <cg@exept.de>
parents: 2813
diff changeset
   728
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
controlFlowSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   730
    ^ self class controlFlowSelectors
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   733
debugSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   734
    ^ self class debugSelectors
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   735
!
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   736
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
defineAsUndeclaredVariable:aName
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    "redefined to NOT declare undefined vars"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
    ^ VariableNode globalNamed:aName
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
    "Modified: / 19.10.1998 / 19:38:12 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   745
errorRaisingSelectors
3231
44b2709db25e class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3228
diff changeset
   746
    ^ self class errorRaisingSelectors
3228
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   747
!
e276f545e004 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
   748
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
isSyntaxHighlighter
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
    ^ true
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
plausibilityCheck:aNode
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
    "redefined to NOT do checks"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
    ^ nil
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
    "Modified: / 19.10.1998 / 19:38:12 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
    "Created: / 19.10.1998 / 19:57:18 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
!AbstractSyntaxHighlighter methodsFor:'syntax detection'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   765
markCommentFrom:pos1 to:pos2
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   766
    "all positions are 1-based"
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   767
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   768
    self 
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   769
        markFrom:pos1 to:pos2 
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   770
        withEmphasis:commentEmphasis 
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   771
        color:commentColor
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   772
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   773
    "
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   774
     UserPreferences current commentEmphasis
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   775
     UserPreferences current commentColor
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   776
    "
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   777
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   778
    "Modified (comment): / 21-10-2017 / 14:24:51 / cg"
4281
7edd11db2e23 Editor theme: do not allow for special fonts for comments
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4275
diff changeset
   779
    "Modified: / 31-05-2018 / 12:21:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   780
!
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   781
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   782
markConstantFrom:pos1 to:pos2
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   783
    self 
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   784
        markFrom:pos1 to:pos2 
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   785
        withEmphasis:constantEmphasis 
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   786
        color:constantColor
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   787
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   788
    "Created: / 31-03-1998 / 18:09:22 / cg"
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   789
    "Modified: / 21-10-2017 / 14:15:48 / cg"
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   790
!
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   791
4264
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   792
markErrorFrom:pos1 to:pos2
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   793
    self
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   794
        markFrom:pos1 to:pos2
4733
e19fe34c0dd8 `AbstractSyntaxHighlighter`: use set color preferences (theme) when marking error
Jan Vrany <jan.vrany@labware.com>
parents: 4723
diff changeset
   795
        withEmphasis:nil color:preferences errorColor
e19fe34c0dd8 `AbstractSyntaxHighlighter`: use set color preferences (theme) when marking error
Jan Vrany <jan.vrany@labware.com>
parents: 4723
diff changeset
   796
e19fe34c0dd8 `AbstractSyntaxHighlighter`: use set color preferences (theme) when marking error
Jan Vrany <jan.vrany@labware.com>
parents: 4723
diff changeset
   797
    "Modified: / 15-11-2021 / 18:54:45 / Jan Vrany <jan.vrany@labware.com>"
4264
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   798
!
eb7566800e38 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
   799
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   800
markFrom:pos1 length:len withEmphasis:fontEmp color:clrIn
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   801
    self markFrom:pos1 to:pos1+len-1 withEmphasis:fontEmp color:clrIn
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   802
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   803
    "Created: / 21-10-2017 / 14:47:46 / cg"
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   804
!
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   805
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
markFrom:pos1 to:pos2 withAddedEmphasis:addedEmphasis
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   807
    self class
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   808
	mark:sourceText from:pos1 to:pos2 withAddedEmphasis:addedEmphasis
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
    "Created: / 15-01-2008 / 11:48:18 / cg"
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
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
   814
    self class
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   815
	mark:sourceText from:pos1 to:pos2 withEmphasis:fontEmp color:clrIn
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
    "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
   818
    "Modified: / 01-06-2012 / 21:43:04 / cg"
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   821
markFrom:pos1 to:pos2 withEmphasis:fontEmp color:clrIn font:fontInOrNil
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   822
    "all positions are 1-based"
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   823
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   824
    self class
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   825
        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
   826
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   827
    "Created: / 31-03-1998 / 13:26:53 / cg"
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   828
    "Modified: / 01-06-2012 / 21:43:04 / cg"
4202
b74cb013e847 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4200
diff changeset
   829
    "Modified (comment): / 21-10-2017 / 14:24:47 / cg"
3352
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   830
!
42a5ad1adb52 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   831
2813
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   832
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
   833
    self class
3469
Claus Gittinger <cg@exept.de>
parents: 3352
diff changeset
   834
	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
   835
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   836
    "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
   837
!
51e4b12f18dc added: #markFrom:to:withEmphasis:color:ifNil:backgroundColor:
Claus Gittinger <cg@exept.de>
parents: 2688
diff changeset
   838
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   839
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
   840
    self class
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   841
        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
   842
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   843
    "Created: / 13-02-2012 / 11:48:09 / cg"
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   844
!
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   845
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
markVariable:v
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
    |pos endPos|
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
    pos := tokenPosition.
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
    endPos := pos+tokenName size-1.
3189
5a4bb1727d08 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
   851
    self markVariable:v from:pos to:endPos assigned:false
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
2464
595ec0d9efa9 comment/format in: #markVariable:
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
   853
    "Modified: / 30-11-2010 / 14:44:28 / cg"
4578
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   854
!
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   855
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   856
postProcessTree:tree forText:text
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   857
    "allows for additional checks to be done on the tree
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   858
     (checking arguments to a call-node in expecco, for example)"
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   859
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   860
    "/ intentionaly left blank here.
6a1d8da4191d #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 4568
diff changeset
   861
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
! !
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   864
!AbstractSyntaxHighlighter class methodsFor:'documentation'!
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
2663
e94fe6b650ad changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents: 2662
diff changeset
   866
version
3675
6a75a2fe7a83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   867
    ^ '$Header$'
2663
e94fe6b650ad changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents: 2662
diff changeset
   868
!
e94fe6b650ad changed: #controlFlowSelectors
Claus Gittinger <cg@exept.de>
parents: 2662
diff changeset
   869
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   870
version_CVS
3675
6a75a2fe7a83 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   871
    ^ '$Header$'
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
   872
!
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
   873
3716
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   874
version_HG
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   875
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   876
    ^ '$Changeset: <not expanded> $'
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   877
!
bcd80550baab Added AbstractSyntaxHighlighter class>>formatStatements:in:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3675
diff changeset
   878
2506
3a8b4a11428e Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2464
diff changeset
   879
version_SVN
3189
5a4bb1727d08 class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
   880
    ^ '$ Id $'
2371
2348d09fb80e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
! !
3561
f04a8db1590f class: AbstractSyntaxHighlighter
Claus Gittinger <cg@exept.de>
parents: 3469
diff changeset
   882