SyntaxHighlighter2.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Jan 2018 19:19:37 +0100
changeset 17959 dd48c30087b2
parent 17858 b2633d40e03f
child 18046 fd21c26b4fc9
permissions -rw-r--r--
#FEATURE by cg class: DictionaryInspectorView added: #doHideEmptyCollections #doShowEmptyCollections changed: #fieldMenu #indexListForNameSpace #initialize
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
10067
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     2
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     3
              All Rights Reserved
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
10067
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     5
Permission is hereby granted, free of charge, to any person
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     6
obtaining a copy of this software and associated documentation
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     7
files (the 'Software'), to deal in the Software without
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     8
restriction, including without limitation the rights to use,
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
     9
copy, modify, merge, publish, distribute, sublicense, and/or sell
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    10
copies of the Software, and to permit persons to whom the
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    11
Software is furnished to do so, subject to the following
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    12
conditions:
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    13
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    14
The above copyright notice and this permission notice shall be
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    15
included in all copies or substantial portions of the Software.
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    16
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    17
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    18
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    19
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    20
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    21
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    22
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    23
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    24
OTHER DEALINGS IN THE SOFTWARE.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"{ Package: 'stx:libtool' }"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    28
"{ NameSpace: Smalltalk }"
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    29
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
SyntaxHighlighter subclass:#SyntaxHighlighter2
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
    31
	instanceVariableNames:'elements lastVariableElements lastSelectorElement
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
    32
		ignoreBadIdentifier'
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	classVariableNames:''
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	poolDictionaries:''
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
	category:'Interface-CodeView-Syntax'
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!SyntaxHighlighter2 class methodsFor:'documentation'!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
copyright
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
10067
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    42
 COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    43
              All Rights Reserved
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    44
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    45
Permission is hereby granted, free of charge, to any person
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    46
obtaining a copy of this software and associated documentation
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    47
files (the 'Software'), to deal in the Software without
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    48
restriction, including without limitation the rights to use,
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    49
copy, modify, merge, publish, distribute, sublicense, and/or sell
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    50
copies of the Software, and to permit persons to whom the
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    51
Software is furnished to do so, subject to the following
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    52
conditions:
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
10067
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    54
The above copyright notice and this permission notice shall be
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    55
included in all copies or substantial portions of the Software.
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    56
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    57
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    58
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    59
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    60
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    61
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    62
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    63
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
c7b27b7cc827 changed: #copyright
Claus Gittinger <cg@exept.de>
parents: 10022
diff changeset
    64
OTHER DEALINGS IN THE SOFTWARE.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
"
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    66
!
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    67
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    68
documentation
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    69
"
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    70
    A slightly improved syntax highlighter.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    71
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    72
    In addition to the inherited colorization, this one also remembers
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    73
    so called 'syntax elements' (variable tokens and selectors) and remembers
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    74
    them in a list.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    75
    This can be later used by the codeView to highlight uses of a clicked-on
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    76
    variable or a clicked-on selector.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    77
    Also this list could (but is not, at the moment) be used to forward/backward
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    78
    search for the next use of some variable.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    79
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    80
    [caveat:]
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    81
        This code has a smell: there is a lot of code duplication,
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    82
        and most can be moved to the superclass. Actually, there is propably no
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    83
        reason to have both classes around, so why not integrate all into the superclass.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
    84
"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
! !
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
17858
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
    87
!SyntaxHighlighter2 class methodsFor:'api highlighting'!
12636
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    88
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    89
formatClassDefinition:aString in:aClass elementsInto: elements
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    90
    "format (recolor) a class definition expression in a given class.
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    91
     Return the text containing font changes and color information."
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    92
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    93
    ^ self formatExpression:aString in:aClass elementsInto: elements
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    94
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    95
    "Created: / 10-04-2011 / 18:18:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    96
!
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    97
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    98
formatExpression:aString in:aClass elementsInto: elements
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
    99
    "format (recolor) an expression in a given class.
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   100
     Return the text containing font changes and color information."
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   101
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   102
    "/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   103
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   104
    |parser tree text|
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   105
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   106
    aString isNil ifTrue:[^ nil].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   107
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   108
    parser := self for:(ReadStream on:aString string) in:aClass.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   109
    parser elements: elements.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   110
    parser ignoreErrors:true.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   111
    parser ignoreWarnings:true.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   112
    parser sourceText:(text := aString string asText).
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   113
    "/ use an array here - this can be changed much faster using #at:put:
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   114
    text emphasisCollection:(Array new:aString size).
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   115
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   116
    parser nextToken.
15580
deefdf789ee7 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15473
diff changeset
   117
    [
deefdf789ee7 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15473
diff changeset
   118
        tree := parser "expression"statementList.
deefdf789ee7 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15473
diff changeset
   119
    ] on:ParseError do:[
deefdf789ee7 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15473
diff changeset
   120
        tree := #Error
deefdf789ee7 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15473
diff changeset
   121
    ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   122
    "/ now, convert the emphasis-array to a runArray
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   123
    text emphasisCollection:(text emphasis asRunArray).
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   124
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   125
    tree == #Error ifTrue:[
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   126
        ^ self colorize:text forErrorAtPosition:parser sourceStream position withOriginal:aString
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   127
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   128
    ^ text
12636
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   129
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   130
    "
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   131
     self
14299
163fd5573c17 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14056
diff changeset
   132
        formatExpression:'(1 + 2) max:5'
163fd5573c17 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14056
diff changeset
   133
        in:UndefinedObject
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    "
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   135
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   136
    "Created: / 25-07-2010 / 08:56:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   137
    "Modified: / 25-07-2010 / 10:57:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
formatMethod:aString in:aClass using:preferencesOrNil elementsInto: elements
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "format (recolor) a method in a given class.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
     Return the text containing font changes and color information."
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
10152
561883853228 comment/format in: #formatMethod:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10150
diff changeset
   144
    "/ obsolete interface
10150
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   145
    ^ self
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   146
        formatMethod:nil
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   147
        source:aString
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   148
        in:aClass
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   149
        using:preferencesOrNil elementsInto:elements
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   150
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   151
    "Created: / 25-07-2010 / 08:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10152
561883853228 comment/format in: #formatMethod:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10150
diff changeset
   152
    "Modified (comment): / 05-07-2011 / 11:07:50 / cg"
10150
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   153
!
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   154
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   155
formatMethod:aMethodOrNil source:aString in:aClass using:preferencesOrNil elementsInto: elements
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   156
    "format (recolor) a method in a given class.
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   157
     Return the text containing font changes and color information."
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   158
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   159
    "/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   160
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   161
    |highlighter tree newText|
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
    aString isNil ifTrue:[^ nil].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    Error handle:[:ex |
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   166
        "/ Transcript showCR:ex description.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
        (self parseErrorSignal handles:ex) ifFalse:[
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   168
            ex creator isHandled ifTrue:[
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   169
                "/ Transcript showCR:'handled'.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   170
                ex reject.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   171
            ].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
            "Parse error may happen when re-formatting incomplete code while editing"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
            ('SyntaxHighlighter [info]: error during highlight: ' , ex description) infoPrintCR.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
            "/ ex suspendedContext fullPrintAll.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
        ].
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   176
        highlighter notNil ifTrue:[
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   177
            ^ self colorize:(newText ? aString) forErrorAtPosition:highlighter sourceStream position withOriginal:aString
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   178
        ].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
        ^ aString
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    ] do:[
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   181
        |sourceString|
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   182
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   183
        sourceString := aString string.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   184
        newText := sourceString asUnicode16String asText.
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   185
        "/ use an array here (instead of the RunArray) - this can be changed much faster using #at:put:
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   186
        newText emphasisCollection:(Array new:sourceString size).
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   187
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   188
        highlighter := self for:(ReadStream on:sourceString) in:aClass.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
        highlighter elements: elements.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
        preferencesOrNil notNil ifTrue:[highlighter preferences:preferencesOrNil].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
        "/ highlighter ignoreErrors:true.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
        highlighter ignoreWarnings:true.
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   193
        highlighter sourceText:newText.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
        tree := highlighter parseMethod.
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   196
        newText := highlighter sourceText.  "/ might have changed identity
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
        "/ now, convert the emphasis-array to a runArray
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   198
        newText emphasisCollection:(newText emphasis asRunArray).
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
        tree == #Error ifTrue:[
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   201
            ^ self colorize:newText forErrorAtPosition:highlighter sourceStream position withOriginal:aString
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   202
        ].
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   203
        ^ newText
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   204
    ]
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    "
15446
d4cda7a1df4e some code cleanup
Claus Gittinger <cg@exept.de>
parents: 14489
diff changeset
   207
     self formatMethod:'foo
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    ^ self bar:''hello''.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    ' , (Character doubleQuote asString) , 'some comment' , (Character doubleQuote asString) , '
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
'
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
        in:UndefinedObject
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    "
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    "Modified: / 22-08-2006 / 13:32:04 / cg"
10150
3792ee8840ea added: #formatMethod:source:in:using:elementsInto:
Claus Gittinger <cg@exept.de>
parents: 10067
diff changeset
   216
    "Created: / 05-07-2011 / 10:39:21 / cg"
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   217
    "Modified: / 28-05-2013 / 22:45:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17858
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   218
! !
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   219
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   220
!SyntaxHighlighter2 class methodsFor:'highlighting'!
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   221
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   222
format:aString parsingWith:aBlock in:aClass elementsInto:elements
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   223
    "common code for formatStatementList, formatExpression, ...
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   224
     format (recolor) whatever is parsed in aBlock (within the context of a given class).
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   225
     Return the text containing font changes and color information.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   226
     As a side effect, put syntax elements into the passed in elements container
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   227
     (for element-highlighting in codeView2)"
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   228
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   229
    "/ cg: I smell a wumpus: I don't think, all of this must be redefined - most is already there in the superclass.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   230
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   231
    |parser tree text|
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   232
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   233
    aString isNil ifTrue:[^ nil].
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   234
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   235
    parser := self for:(ReadStream on:aString string) in:aClass.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   236
    parser elements: elements.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   237
    parser ignoreErrors:true.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   238
    parser ignoreWarnings:true.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   239
    parser sourceText:(text := aString string asText).
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   240
    "/ use an array here - this can be changed much faster using #at:put:
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   241
    text emphasisCollection:(Array new:aString size).
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   242
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   243
    parser nextToken.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   244
    tree := aBlock value:parser.
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   245
    "/ now, convert the emphasis-array to a runArray
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   246
    text emphasisCollection:(text emphasis asRunArray).
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   247
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   248
    tree == #Error ifTrue:[
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   249
        ^ self colorize:text forErrorAtPosition:parser sourceStream position withOriginal:aString
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   250
    ].
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   251
    ^ text
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   252
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   253
    "
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   254
     self
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   255
        formatStatementList:'(1 + 2) max:5. 1 + 2' 
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   256
        in:UndefinedObject
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   257
        elementsInto:(OrderedCollection new).
b2633d40e03f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17371
diff changeset
   258
    "
12636
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   259
!
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   260
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   261
formatStatementList:aString in:aClass elementsInto: elements
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   262
    "format (recolor) a statement list in a given class.
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   263
     Return the text containing font changes and color information."
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   264
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   265
    ^ self 
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   266
        format:aString parsingWith:[:parser | parser statementList]
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   267
        in:aClass elementsInto:elements
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   268
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   269
    "
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   270
     self
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   271
        formatStatementList:'(1 + 2) max:5. 1 + 2' 
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   272
        in:UndefinedObject
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   273
        elementsInto:(OrderedCollection new).
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
   274
    "
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
! !
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
!SyntaxHighlighter2 methodsFor:'accessing'!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
elements
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    ^ elements
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   283
elements:aParseTreeIndexCollection
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
   284
    "the element collection, to collect variables, selectors etc. into"
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
   285
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   286
    elements := aParseTreeIndexCollection.
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
   287
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
   288
    "Modified (comment): / 21-08-2011 / 09:13:31 / cg"
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   289
!
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   290
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   291
tree: aParseNode
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   292
    super tree: aParseNode.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   293
    elements tree: aParseNode
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   294
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   295
    "Created: / 16-02-2012 / 09:56:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
! !
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
!SyntaxHighlighter2 methodsFor:'initialization'!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
initialize
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
17371
ffbfab2b0c09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 15714
diff changeset
   302
    <modifier: #super> "must be called if redefined"
ffbfab2b0c09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 15714
diff changeset
   303
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
    super initialize.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   305
    elements := ParseTreeIndex new.
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
   306
    lastVariableElements := Dictionary new.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
    "Created: / 14-02-2010 / 13:08:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   309
    "Modified: / 16-02-2012 / 09:59:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17371
ffbfab2b0c09 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 15714
diff changeset
   310
    "Modified: / 08-02-2017 / 00:31:42 / cg"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
! !
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
!SyntaxHighlighter2 methodsFor:'parsing-expressions'!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   315
_binaryExpressionFor:receiverArg
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   316
    "parse a binary-expression; return a node-tree, nil or #Error"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   317
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   318
    |receiver expr arg sel pos1 pos2 lno|
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   319
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   320
    receiver := receiverArg.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   321
    (receiver == #Error) ifTrue:[^ #Error].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   322
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   323
    "special kludge: since Scanner cannot know if -digit is a binary
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   324
     expression or a negative constant, handle cases here"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   325
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   326
    [(tokenType == #BinaryOperator)
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   327
     or:[(tokenType == $|)
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   328
     or:[(tokenType == $^ and:[parserFlags allowCaretAsBinop])
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   329
         or:[((tokenType == #Integer) or:[tokenType == #Float])
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   330
             and:[tokenValue < 0]]]]
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   331
    ] whileTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   332
        "/ kludge alarm: in a function-call argList, #, is not a binarySelector
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   333
        inFunctionCallArgument == true ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   334
            ((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   335
                ^ receiver
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   336
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   337
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   338
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   339
        pos1 := tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   340
        lno := tokenLineNr.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   341
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   342
        "/ kludge alarm: bar, caret and minus are not scanned as binop
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   343
        (tokenType == $|) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   344
            sel := '|'.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   345
            sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   346
            self nextToken.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   347
        ] ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   348
            (tokenType == $^) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   349
                sel := '^'.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   350
                sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   351
                self nextToken.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   352
            ] ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   353
                (tokenType == #BinaryOperator) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   354
                    sel := tokenName.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   355
                    sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1).
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   356
                    self nextToken
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   357
                ] ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   358
                    sel := '-'.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   359
                    token := tokenValue := tokenValue negated.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   360
                    tokenPosition := tokenPosition + 1. "/ to skip the sign
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   361
                ]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   362
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   363
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   364
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   365
        pos2 := pos1 + sel size - 1.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   366
        self markSelector:sel from:pos1 to:pos2 receiverNode:receiver.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   367
        lastSelectorElement := nil.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   368
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   369
        arg := self unaryExpression.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   370
        (arg == #Error) ifTrue:[^ #Error].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   371
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   372
        expr := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   373
        expr isErrorNode ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   374
            self parseError:(expr errorString) position:pos1 to:tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   375
            self clearErrorFlag. "ok, user wants it - so he'll get it"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   376
            expr := BinaryNode receiver:receiver selector:sel arg:arg fold:nil.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   377
        ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   378
        expr lineNumber:lno.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   379
        expr selectorPosition:pos1.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   380
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   381
        self checkPlausibilityOf:expr from:pos1 to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   382
        parseForCode ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   383
            self rememberSelectorUsed:sel receiver:receiver
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   384
        ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   385
        receiver := expr.   "/ for next message
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   386
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   387
    ^ receiver
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   388
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   389
    "Modified: / 09-01-1998 / 19:05:18 / stefan"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   390
    "Modified: / 14-02-2010 / 17:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   391
    "Modified: / 19-01-2012 / 10:46:49 / cg"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   392
    "Created: / 16-02-2012 / 21:54:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   393
!
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   394
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   395
_keywordExpressionFor:receiverArg
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   396
    "parse a keyword-expression; return a node-tree, nil or #Error.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   397
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   398
     keywordExpression ::= binaryexpression
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   399
                           | { KEYWORD-PART binaryExpression }
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   400
    "
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   401
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   402
    |expr receiver sel arg args posR1 posR2 pos1 pos2 lno positions constVal|
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   403
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   404
    receiver := receiverArg.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   405
    posR1 := tokenPosition.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   406
    (tokenType == #Keyword) ifFalse:[^ receiver].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   407
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   408
    pos1 := posR2 := tokenPosition.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   409
    pos2 := tokenPosition + tokenName size - 1.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   410
    positions := OrderedCollection with:(pos1 to:pos2).
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   411
    sel := tokenName.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   412
    lno := tokenLineNr.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   413
    self nextToken.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   414
    arg := self binaryExpression.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   415
    (arg == #Error) ifTrue:[^ #Error].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   416
    args := Array with:arg.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   417
    [tokenType == #Keyword] whileTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   418
        sel := sel , tokenName.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   419
        pos2 := tokenPosition + tokenName size - 1.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   420
        positions add:(tokenPosition to:pos2).
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   421
        self nextToken.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   422
        arg := self binaryExpression.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   423
        (arg == #Error) ifTrue:[^ #Error].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   424
        args := args copyWith:arg.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   425
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   426
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   427
    positions do:[:p |
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   428
        self markSelector:sel from:p start to:p stop receiverNode:receiver.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   429
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   430
    lastSelectorElement := nil.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   431
    sel := self selectorCheck:sel for:receiver positions:positions.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   432
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   433
    ignoreWarnings ifFalse:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   434
        (Class definitionSelectors includes:sel) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   435
            (receiver isVariable and:[receiver isUndeclared]) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   436
                "this is not an error - the undefined class may be loaded after this code!!"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   437
                self warning:('as yet undefined superclass: ' , receiver name) position:pos1 to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   438
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   439
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   440
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   441
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   442
    expr := MessageNode receiver:receiver selector:sel args:args fold:foldConstants.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   443
    expr isErrorNode ifTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   444
        self parseError:(expr errorString) position:pos1 to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   445
        self clearErrorFlag. "ok, user wants it - so he'll get it"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   446
        expr := MessageNode receiver:receiver selector:sel args:args fold:nil.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   447
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   448
    expr lineNumber:lno.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   449
    self checkPlausibilityOf:expr from:pos1 to:pos2.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   450
    parseForCode ifFalse:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   451
        self rememberSelectorUsed:sel receiver:receiver
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   452
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   453
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   454
"/        (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[    "/ do not check this for doits
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   455
"/            receiver isSuper ifTrue:[
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   456
"/                sel ~= selector ifTrue:[
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   457
"/                    self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?'
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   458
"/                                  position:posR1 to:posR2-1
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   459
"/                ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   460
"/            ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   461
"/        ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   462
"/
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   463
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   464
    (sel = #ifTrue: or:[sel = #ifFalse: or:[sel = #ifTrue:ifFalse: or:[sel = #ifFalse:ifTrue:]]]) ifTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   465
        (expr receiver withConstantValueDo:[:val | constVal := val]) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   466
            |indexOfArgNotExecuted|
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   467
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   468
            "/ receiver evaluates to a constant
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   469
            constVal == true ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   470
                (sel startsWith: #ifFalse:) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   471
                    indexOfArgNotExecuted := 1.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   472
                ] ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   473
                    indexOfArgNotExecuted := 2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   474
                ]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   475
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   476
            constVal == false ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   477
                (sel startsWith: #ifTrue:) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   478
                    indexOfArgNotExecuted := 1.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   479
                ] ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   480
                    indexOfArgNotExecuted := 2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   481
                ]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   482
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   483
            indexOfArgNotExecuted == 2 ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   484
                args size == 1 ifTrue:[ indexOfArgNotExecuted := nil]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   485
            ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   486
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   487
            indexOfArgNotExecuted notNil ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   488
                |argIsNotExecuted|
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   489
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   490
                "/ self warning:'receiver is constant; arg',indexOfArgNotExecuted printString,' is never executed' position:pos1 to:tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   491
                argIsNotExecuted := expr args at:indexOfArgNotExecuted.
14489
1b8f51cfd187 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14384
diff changeset
   492
                argIsNotExecuted realNode isBlockNode ifTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   493
                    self markCommentFrom:argIsNotExecuted startPosition to:argIsNotExecuted endPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   494
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   495
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   496
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   497
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   498
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   499
    (ignoreErrors or:[ignoreWarnings]) ifFalse:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   500
        (sel = #and: or:[sel = #or:]) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   501
            expr arg1 isBlock ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   502
                (expr arg1 isVariable
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   503
                and:[ (expr arg1 name asLowercase includesString:'block')]) ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   504
                    self warnCommonMistake:'(possible common mistake) missing block brackets ?'
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   505
                              position:pos2+1 to:tokenPosition-1
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   506
                ]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   507
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   508
            ^ expr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   509
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   510
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   511
        (sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   512
            expr receiver isBlock ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   513
                (expr receiver isVariable
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   514
                and:[ (expr receiver name asLowercase includesString:'block')]) ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   515
                    self warnCommonMistake:'(possible common mistake) missing block brackets ?'
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   516
                              position:pos1 to:pos2
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   517
                ]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   518
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   519
            ^ expr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   520
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   521
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   522
        (sel = #ifTrue: or:[sel = #ifFalse:]) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   523
            expr receiver isMessage ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   524
                (expr receiver selector = #whileTrue or:[expr receiver selector = #whileFalse]) ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   525
                    self warnCommonMistake:'strange receiver expression'
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   526
                              position:pos1 to:pos2
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   527
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   528
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   529
            ^ expr
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   530
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   531
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   532
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   533
    ^ expr.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   534
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   535
    "Modified: / 14-02-2010 / 17:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   536
    "Modified: / 19-01-2012 / 10:47:01 / cg"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   537
    "Created: / 16-02-2012 / 21:54:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   538
!
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   539
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   540
_unaryExpressionFor:receiverArg
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   541
    "parse a unary-expression; return a node-tree, nil or #Error"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   542
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   543
    |receiver expr sel pos pos2 lNr arguments|
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   544
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   545
    receiver := receiverArg.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   546
    (receiver == #Error) ifTrue:[^ #Error].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   547
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   548
    [ self isValidUnarySelector:tokenType ] whileTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   549
        pos := tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   550
        pos2 := pos + tokenName size - 1.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   551
        lNr := tokenLineNr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   552
        sel := tokenName.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   553
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   554
        self markSelector:sel from:pos to:pos2 receiverNode:receiver.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   555
        lastSelectorElement := nil.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   556
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   557
        self nextToken.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   558
        tokenType == $( ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   559
            parserFlags allowSqueakExtensions == true ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   560
                "/ croquet/squeak extension - c/java-style arguments
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   561
                arguments := self functionCallArgList.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   562
                "/ synthetic selector: foo[:[with:[with:[...]]]]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   563
                arguments notEmpty ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   564
                    sel := sel , ':'.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   565
                    arguments size - 1 timesRepeat:[ sel := sel , 'with:' ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   566
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   567
                sel := self selectorCheck:sel for:receiver position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   568
                expr := MessageNode receiver:receiver selector:sel args:arguments fold:foldConstants.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   569
                expr isErrorNode ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   570
                    self parseError:(expr errorString) position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   571
                    self clearErrorFlag. "ok, user wants it - so he'll get it"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   572
                    expr := MessageNode receiver:receiver selector:sel args:arguments fold:nil.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   573
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   574
                expr lineNumber:lNr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   575
                self checkPlausibilityOf:expr from:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   576
                parseForCode ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   577
                    self rememberSelectorUsed:sel receiver:receiver
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   578
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   579
                ^ expr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   580
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   581
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   582
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   583
        sel := self selectorCheck:sel for:receiver position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   584
        expr := UnaryNode receiver:receiver selector:sel fold:foldConstants.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   585
        expr isErrorNode ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   586
            self warning:(expr errorString , '.\\If you proceed, that error will happen at runtime.') withCRs position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   587
            self clearErrorFlag. "ok, user wants it - so he'll get it"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   588
            expr := UnaryNode receiver:receiver selector:sel fold:nil.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   589
        ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   590
        expr lineNumber:lNr.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   591
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   592
        self checkPlausibilityOf:expr from:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   593
        parseForCode ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   594
            self rememberSelectorUsed:sel receiver:receiver
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   595
        ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   596
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   597
        receiver := expr.   "/ for next message
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   598
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   599
    ^ receiver
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   600
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   601
    "Modified: / 14-02-2010 / 17:56:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   602
    "Modified: / 19-01-2012 / 10:47:37 / cg"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   603
    "Created: / 16-02-2012 / 21:54:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   604
!
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   605
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   606
binaryExpression
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   607
    | node savedLastSelectorElement |
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   608
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   609
    savedLastSelectorElement := lastSelectorElement.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   610
    lastSelectorElement := nil.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   611
    node := super binaryExpression.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   612
    (lastSelectorElement notNil and:[node ~~ #Error and:[node isMessage]]) ifTrue:[
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   613
	lastSelectorElement node parent: node.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   614
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   615
    lastSelectorElement := savedLastSelectorElement.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   616
    ^node
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   617
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   618
    "Modified: / 19-01-2000 / 16:22:16 / cg"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   619
    "Created: / 16-02-2012 / 21:56:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   620
!
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   621
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
binaryExpressionFor:receiverArg
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
    "parse a binary-expression; return a node-tree, nil or #Error"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   625
    |receiver expr arg sel pos1 pos2 lno|
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
    receiver := receiverArg.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
    (receiver == #Error) ifTrue:[^ #Error].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
    "special kludge: since Scanner cannot know if -digit is a binary
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
     expression or a negative constant, handle cases here"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
    [(tokenType == #BinaryOperator) 
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
     or:[(tokenType == $|)
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
     or:[(tokenType == $^ and:[parserFlags allowCaretAsBinop])
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
         or:[((tokenType == #Integer) or:[tokenType == #Float])
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
             and:[tokenValue < 0]]]]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
    ] whileTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
        "/ kludge alarm: in a function-call argList, #, is not a binarySelector
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
        inFunctionCallArgument == true ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
            ((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
                ^ receiver
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
        pos1 := tokenPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
        lno := tokenLineNr.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
        "/ kludge alarm: bar, caret and minus are not scanned as binop
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
        (tokenType == $|) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
            sel := '|'.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
            sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
            self nextToken.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
        ] ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
            (tokenType == $^) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
                sel := '^'.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
                sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
                self nextToken.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
            ] ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
                (tokenType == #BinaryOperator) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
                    sel := tokenName.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
                    sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1).
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
                    self nextToken
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
                ] ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
                    sel := '-'.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   666
                    token := tokenValue := tokenValue negated.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
                    tokenPosition := tokenPosition + 1. "/ to skip the sign
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
                ]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
        pos2 := pos1 + sel size - 1.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
        self markSelector:sel from:pos1 to:pos2 receiverNode:receiver.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
        lastSelectorElement := nil.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
        arg := self unaryExpression.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
        (arg == #Error) ifTrue:[^ #Error].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
        expr := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
        expr isErrorNode ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
            self parseError:(expr errorString) position:pos1 to:tokenPosition.
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   682
            self clearErrorFlag. "ok, user wants it - so he'll get it"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
            expr := BinaryNode receiver:receiver selector:sel arg:arg fold:nil.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
        expr lineNumber:lno.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
        expr selectorPosition:pos1.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   688
        self checkPlausibilityOf:expr from:pos1 to:pos2.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
        receiver := expr.   "/ for next message
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
    ^ receiver
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
    "Modified: / 09-01-1998 / 19:05:18 / stefan"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
    "Modified: / 14-02-2010 / 17:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   695
    "Modified: / 19-01-2012 / 10:46:49 / cg"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
expression
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   699
    | node savedLastSelectorElement |
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   701
    savedLastSelectorElement := lastSelectorElement.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   702
    lastSelectorElement := nil.
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   703
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   704
    node := super expression.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   705
    ((node ~~ #Error) and:[node isMessage]) ifTrue:[
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   706
        [ lastSelectorElement notNil ] whileTrue:[
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   707
            lastSelectorElement node parent: node.
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   708
            lastSelectorElement := lastSelectorElement previousElement.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
    ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   711
    lastSelectorElement := savedLastSelectorElement.
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   712
    ^node
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
    "Modified: / 19-01-2000 / 16:22:16 / cg"
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   715
    "Modified: / 16-02-2012 / 23:39:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
keywordExpressionFor:receiverArg
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
    "parse a keyword-expression; return a node-tree, nil or #Error.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
     keywordExpression ::= binaryexpression
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
                           | { KEYWORD-PART binaryExpression }
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
    "
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   725
    |expr receiver sel arg args posR1 posR2 pos1 pos2 lno positions constVal|
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
    receiver := receiverArg.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
    posR1 := tokenPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
    (tokenType == #Keyword) ifFalse:[^ receiver].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
    pos1 := posR2 := tokenPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
    pos2 := tokenPosition + tokenName size - 1.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
    positions := OrderedCollection with:(pos1 to:pos2).
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   734
    sel := tokenName.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   735
    lno := tokenLineNr.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
    self nextToken.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
    arg := self binaryExpression.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    (arg == #Error) ifTrue:[^ #Error].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
    args := Array with:arg.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
    [tokenType == #Keyword] whileTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
        sel := sel , tokenName.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
        pos2 := tokenPosition + tokenName size - 1.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
        positions add:(tokenPosition to:pos2).
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
        self nextToken.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   745
        arg := self binaryExpression.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   746
        (arg == #Error) ifTrue:[^ #Error].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
        args := args copyWith:arg.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   750
    positions do:[:p |
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
        self markSelector:sel from:p start to:p stop receiverNode:receiver.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
    lastSelectorElement := nil.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
    sel := self selectorCheck:sel for:receiver positions:positions.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
    ignoreWarnings ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
        (Class definitionSelectors includes:sel) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
            (receiver isVariable and:[receiver isUndeclared]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
                "this is not an error - the undefined class may be loaded after this code!!"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
                self warning:('as yet undefined superclass: ' , receiver name) position:pos1 to:pos2.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
    expr := MessageNode receiver:receiver selector:sel args:args fold:foldConstants.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
    expr isErrorNode ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   767
        self parseError:(expr errorString) position:pos1 to:pos2.
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   768
        self clearErrorFlag. "ok, user wants it - so he'll get it"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
        expr := MessageNode receiver:receiver selector:sel args:args fold:nil.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
    expr lineNumber:lno.
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   772
    self checkPlausibilityOf:expr from:pos1 to:pos2.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
"/        (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[    "/ do not check this for doits
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
"/            receiver isSuper ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
"/                sel ~= selector ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
"/                    self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?'
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
"/                                  position:posR1 to:posR2-1
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
"/                ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   780
"/            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   781
"/        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
"/
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
    (sel = #ifTrue: or:[sel = #ifFalse: or:[sel = #ifTrue:ifFalse: or:[sel = #ifFalse:ifTrue:]]]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
        (expr receiver withConstantValueDo:[:val | constVal := val]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
            |indexOfArgNotExecuted|
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
            "/ receiver evaluates to a constant
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
            constVal == true ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
                (sel startsWith: #ifFalse:) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
                    indexOfArgNotExecuted := 1.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
                ] ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
                    indexOfArgNotExecuted := 2.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
                ]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
            constVal == false ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
                (sel startsWith: #ifTrue:) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
                    indexOfArgNotExecuted := 1.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
                ] ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   800
                    indexOfArgNotExecuted := 2.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
                ]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
            indexOfArgNotExecuted == 2 ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
                args size == 1 ifTrue:[ indexOfArgNotExecuted := nil]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
            indexOfArgNotExecuted notNil ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
                |argIsNotExecuted|
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
                "/ self warning:'receiver is constant; arg',indexOfArgNotExecuted printString,' is never executed' position:pos1 to:tokenPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
                argIsNotExecuted := expr args at:indexOfArgNotExecuted.
14489
1b8f51cfd187 class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14384
diff changeset
   812
                argIsNotExecuted realNode isBlockNode ifTrue:[
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
                    self markCommentFrom:argIsNotExecuted startPosition to:argIsNotExecuted endPosition.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
                ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   815
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    (ignoreErrors or:[ignoreWarnings]) ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
        (sel = #and: or:[sel = #or:]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
            expr arg1 isBlock ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
                (expr arg1 isVariable
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
                and:[ (expr arg1 name asLowercase includesString:'block')]) ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
                    self warnCommonMistake:'(possible common mistake) missing block brackets ?'
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
                              position:pos2+1 to:tokenPosition-1
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
                ]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
            ^ expr.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
        (sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
            expr receiver isBlock ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   833
                (expr receiver isVariable
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
                and:[ (expr receiver name asLowercase includesString:'block')]) ifFalse:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
                    self warnCommonMistake:'(possible common mistake) missing block brackets ?'
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
                              position:pos1 to:pos2
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
                ]
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
            ^ expr.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
        (sel = #ifTrue: or:[sel = #ifFalse:]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
            expr receiver isMessage ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   844
                (expr receiver selector = #whileTrue or:[expr receiver selector = #whileFalse]) ifTrue:[
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
                    self warnCommonMistake:'strange receiver expression'
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
                              position:pos1 to:pos2
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
                ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
            ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
            ^ expr
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   850
        ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
    ].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
    ^ expr.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
    "Modified: / 14-02-2010 / 17:58:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   856
    "Modified: / 19-01-2012 / 10:47:01 / cg"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   858
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
unaryExpressionFor:receiverArg
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    "parse a unary-expression; return a node-tree, nil or #Error"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   862
    |receiver expr sel pos pos2 lNr arguments savedLastSelectorElement|
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   863
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   864
    savedLastSelectorElement := lastSelectorElement.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
    receiver := receiverArg.
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
    (receiver == #Error) ifTrue:[^ #Error].
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   867
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   868
    [ self isValidUnarySelector:tokenType ] whileTrue:[
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   869
        pos := tokenPosition.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   870
        pos2 := pos + tokenName size - 1.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   871
        lNr := tokenLineNr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   872
        sel := tokenName.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   873
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   874
        lastSelectorElement := nil.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   875
        self markSelector:sel from:pos to:pos2 receiverNode:receiver.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   876
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   877
        self nextToken.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   878
        tokenType == $( ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   879
            parserFlags allowSqueakExtensions == true ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   880
                "/ croquet/squeak extension - c/java-style arguments
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   881
                arguments := self functionCallArgList.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   882
                "/ synthetic selector: foo[:[with:[with:[...]]]]
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   883
                arguments notEmpty ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   884
                    sel := sel , ':'.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   885
                    arguments size - 1 timesRepeat:[ sel := sel , 'with:' ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   886
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   887
                sel := self selectorCheck:sel for:receiver position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   888
                expr := MessageNode receiver:receiver selector:sel args:arguments fold:foldConstants.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   889
                expr isErrorNode ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   890
                    self parseError:(expr errorString) position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   891
                    self clearErrorFlag. "ok, user wants it - so he'll get it"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   892
                    expr := MessageNode receiver:receiver selector:sel args:arguments fold:nil.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   893
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   894
                lastSelectorElement node parent: expr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   895
                expr lineNumber:lNr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   896
                self checkPlausibilityOf:expr from:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   897
                parseForCode ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   898
                    self rememberSelectorUsed:sel receiver:receiver
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   899
                ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   900
                ^ expr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   901
            ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   902
        ].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   904
        sel := self selectorCheck:sel for:receiver position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   905
        expr := UnaryNode receiver:receiver selector:sel fold:foldConstants.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   906
        expr isErrorNode ifTrue:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   907
            self warning:(expr errorString , '.\\If you proceed, that error will happen at runtime.') withCRs position:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   908
            self clearErrorFlag. "ok, user wants it - so he'll get it"
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   909
            expr := UnaryNode receiver:receiver selector:sel fold:nil.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   910
        ].
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   911
        expr lineNumber:lNr.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   912
        lastSelectorElement node parent: expr.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   913
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   914
        self checkPlausibilityOf:expr from:pos to:pos2.
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   915
        parseForCode ifFalse:[
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   916
            self rememberSelectorUsed:sel receiver:receiver
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   917
        ].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   918
14384
a0021df16c3b class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 14299
diff changeset
   919
        receiver := expr.   "/ for next message
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   920
    ].
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   921
    lastSelectorElement := savedLastSelectorElement.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   922
    ^ receiver
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   923
11152
c9a386e4f1e0 refactored plausibility checks
Claus Gittinger <cg@exept.de>
parents: 10882
diff changeset
   924
    "Modified: / 19-01-2012 / 10:47:37 / cg"
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   925
    "Created: / 16-02-2012 / 23:50:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   926
! !
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   927
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   928
!SyntaxHighlighter2 methodsFor:'syntax detection'!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   929
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   930
markBlockArgumentIdentifierFrom:pos1 to:pos2
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   931
    "in addition to marking, remember the variable reference"
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   932
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   933
    | node |
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   934
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   935
    super markBlockArgumentIdentifierFrom:pos1 to:pos2.
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   936
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   937
    node := VariableNode blockArgumentNamed:(sourceText string copyFrom: pos1 to: pos2).
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   938
    node block:currentBlock.
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   939
    self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   940
!
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   941
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   942
markLocalVariableDeclaration: name from:pos1 to:pos2
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   943
    "in addition to marking, remember the variable reference"
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   944
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   945
    | type node |
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   946
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   947
    super markLocalVariableDeclaration: name from:pos1 to:pos2.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   948
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   949
    type := currentBlock notNil ifTrue:[#BlockVariable] ifFalse:[#MethodVariable].
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   950
    node := VariableNode type: type name: name.
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   951
    node block:currentBlock. "/ which is nil for method locals
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   952
    self rememberVariableElementFor: node from: pos1 to: pos2 assigned: false.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   953
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   954
    "Created: / 25-02-2014 / 20:22:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   955
!
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   956
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   957
markMethodArgumentIdentifierFrom:pos1 to:pos2
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   958
    "in addition to marking, remember the variable reference"
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   959
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   960
    | node |
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   961
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   962
    super markMethodArgumentIdentifierFrom:pos1 to:pos2.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   963
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   964
    node := VariableNode methodArgumentNamed:(sourceText string copyFrom: pos1 to: pos2).
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   965
    self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   966
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   967
    "Created: / 24-07-2010 / 09:25:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   968
    "Modified: / 21-08-2011 / 09:27:26 / cg"
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
   969
    "Modified: / 25-02-2014 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   970
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   971
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   972
markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode
12672
91288323803d class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 12636
diff changeset
   973
    | element selectorSymbol |
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   975
    "Special hack for Java class references - I would like to have them
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   976
     marked specially (and not as an error when the class is not yet loaded -
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   977
     the code is correct as JavaClassAccessor loads it lazily"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   978
    (aReceiverNode isJavaPackageReference) ifTrue:[
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   979
        self
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   980
            markFrom:pos1 to:pos2
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   981
            withEmphasis:preferences globalClassIdentifierEmphasis
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   982
            color: preferences globalClassIdentifierColor
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   983
    ] ifFalse:[
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   984
        super markSelector:selectorString from:pos1 to:pos2 receiverNode:aReceiverNode.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   985
    ].
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   986
12672
91288323803d class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 12636
diff changeset
   987
    "don't create symbols for partial typed selectors"
91288323803d class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 12636
diff changeset
   988
    selectorSymbol := selectorString asSymbolIfInterned.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
15714
cf4df6faaa96 class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 15580
diff changeset
   990
    element := elements newElementFor: (SelectorNode value: selectorSymbol ? selectorString from: pos1 to: pos2).
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   991
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   992
    (lastSelectorElement notNil "and:[lastSelectorElement value = selectorString]") ifTrue:[
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   993
        lastSelectorElement nextElement: element.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   994
    ].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   995
    elements add: element.
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   996
    lastSelectorElement := "(self isValidUnarySelector:tokenType)"false
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   997
                                ifTrue:[nil]
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
   998
                                ifFalse:[element].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   999
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1000
    "Created: / 14-02-2010 / 17:40:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1001
    "Modified: / 14-02-2010 / 19:24:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1002
    "Modified (format): / 21-08-2011 / 09:18:21 / cg"
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1003
    "Modified: / 19-04-2012 / 09:53:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1004
!
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1005
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1006
markSelfFrom:pos1 to:pos2
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1007
    "in addition to marking, remember the variable reference"
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1008
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1009
    | node |
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1010
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1011
    super markSelfFrom:pos1 to:pos2.
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1012
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1013
    node := SelfNode new.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1014
    node type: #Self.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1015
    self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1016
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1017
    "Created: / 21-08-2011 / 09:15:45 / cg"
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1018
    "Modified: / 25-02-2014 / 21:56:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1019
!
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1020
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1021
markSuperFrom:pos1 to:pos2
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1022
    "in addition to marking, remember the variable reference"
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1023
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1024
    | node |
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1025
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1026
    super markSuperFrom:pos1 to:pos2.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1027
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1028
    node := SuperNode new.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1029
    node type: #Super.
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1030
    self rememberVariableElementFor: node from:pos1 to:pos2 assigned:false
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1031
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1032
    "Created: / 25-02-2014 / 21:57:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1033
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1034
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1035
markUnknownIdentifierFrom:pos1 to:pos2
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1036
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1037
    ignoreBadIdentifier == true ifTrue:[ ^ self ].
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1038
13844
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1039
    super markUnknownIdentifierFrom:pos1 to:pos2
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1040
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1041
    "Created: / 31.3.1998 / 19:09:26 / cg"
c2938013239e merged in jv's chenges
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1042
    "Modified: / 31.3.1998 / 19:10:30 / cg"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
12911
6a562c9a975e class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12689
diff changeset
  1045
markVariable:v from:pos1 to:pos2 assigned:assigned
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1046
    self rememberVariableElementFor:v from:pos1 to:pos2 assigned:assigned.
12911
6a562c9a975e class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12689
diff changeset
  1047
    super markVariable:v from:pos1 to:pos2 assigned:assigned.
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1048
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
    "Created: / 25-06-2010 / 13:03:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1050
    "Modified: / 21-08-2011 / 09:26:30 / cg"
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1051
    "Modified: / 25-02-2014 / 14:07:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1052
!
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1053
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1054
rememberVariableElementFor:node from:pos1 to:pos2 assigned:assigned
15473
cab2f398e8da class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15456
diff changeset
  1055
    |name typeSymbol key element prev dict|
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1056
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1057
    node startPosition: pos1 endPosition: pos2.    
12911
6a562c9a975e class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12689
diff changeset
  1058
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1059
    name := node name.
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1060
    typeSymbol := key := node type.
15473
cab2f398e8da class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15456
diff changeset
  1061
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1062
    (typeSymbol == #BlockArg or:[typeSymbol == #BlockVariable]) ifTrue:[
15473
cab2f398e8da class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15456
diff changeset
  1063
        key := (typeSymbol -> currentBlock "node block")
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1064
    ].
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1065
15473
cab2f398e8da class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15456
diff changeset
  1066
    dict := lastVariableElements at:key ifAbsentPut:[Dictionary new].
cab2f398e8da class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15456
diff changeset
  1067
    prev := dict at:name ifAbsent:[nil].
12987
306d6dc6ffbb class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12984
diff changeset
  1068
    (prev notNil and:[prev start == pos1]) ifTrue:[
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1069
        "/ prev assigned:assigned.
12987
306d6dc6ffbb class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12984
diff changeset
  1070
        ^ self
306d6dc6ffbb class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12984
diff changeset
  1071
    ].
11458
8fdf55d6d1c8 changed: #rememberVariableElementFor:type:from:to:
Claus Gittinger <cg@exept.de>
parents: 11152
diff changeset
  1072
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1073
    element := elements newElementFor: node.
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1074
15456
44e323d6539f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15446
diff changeset
  1075
    prev notNil ifTrue:[prev nextElement:element].
15473
cab2f398e8da class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 15456
diff changeset
  1076
    dict at:name put:element.
10633
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1077
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1078
    elements add: element.
48c904090606 class definition
Claus Gittinger <cg@exept.de>
parents: 10428
diff changeset
  1079
14056
1b0f6f3c4bbd Cleanup - Use ParseTreeIndex consistently. Fixes some minor issues when building
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 13844
diff changeset
  1080
    "Created: / 25-02-2014 / 12:13:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1081
! !
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1082
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1083
!SyntaxHighlighter2 class methodsFor:'documentation'!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1084
12984
65d53f09f5ac class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1085
version
15714
cf4df6faaa96 class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 15580
diff changeset
  1086
    ^ '$Header$'
12984
65d53f09f5ac class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1087
!
65d53f09f5ac class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 12979
diff changeset
  1088
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1089
version_CVS
15714
cf4df6faaa96 class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 15580
diff changeset
  1090
    ^ '$Header$'
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1091
!
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1092
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1093
version_SVN
15714
cf4df6faaa96 class: SyntaxHighlighter2
Stefan Vogel <sv@exept.de>
parents: 15580
diff changeset
  1094
    ^ '$Id$'
10022
a51c7fd32748 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1095
! !
12636
520a881e7e0f class: SyntaxHighlighter2
Claus Gittinger <cg@exept.de>
parents: 11859
diff changeset
  1096