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