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