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