Scanner.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 19:09:53 +0200
changeset 263 3b21d0991eff
parent 254 edfcf93d821f
child 264 f10298cba622
permissions -rw-r--r--
documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    12
7ad01559b262 Initial revision
claus
parents:
diff changeset
    13
Object subclass:#Scanner
241
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    14
	instanceVariableNames:'source collectedSource token tokenType tokenPosition tokenValue
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    15
		tokenName tokenLineNr tokenRadix hereChar peekChar peekChar2
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    16
		requestor exitBlock errorFlag ignoreErrors ignoreWarnings
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
		saveComments currentComments warnSTXSpecialComment
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    18
		warnUnderscoreInIdentifier warnOldStyleAssignment outStream
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    19
		outCol'
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    20
	classVariableNames:'TypeArray ActionArray AllowUnderscoreInIdentifier Warnings
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    21
		WarnSTXSpecials WarnOldStyleAssignment WarnUnderscoreInIdentifier'
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    22
	poolDictionaries:''
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    23
	category:'System-Compiler'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    24
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    25
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    26
!Scanner class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    27
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    28
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    29
"
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    30
 COPYRIGHT (c) 1989 by Claus Gittinger
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
    31
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    32
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    33
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    34
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    36
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    37
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    38
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    39
"
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    40
!
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    41
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    42
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    43
"
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    44
    Scanner reads from a stream and returns individual smalltalk tokens
75
d8b9d6b39497 *** empty log message ***
claus
parents: 74
diff changeset
    45
d8b9d6b39497 *** empty log message ***
claus
parents: 74
diff changeset
    46
    TODO: some testers noticed, that ST-80's scanner methods are called
d8b9d6b39497 *** empty log message ***
claus
parents: 74
diff changeset
    47
    xLetter, xDigit etc. For code using these (internals), the nextNumber,
d8b9d6b39497 *** empty log message ***
claus
parents: 74
diff changeset
    48
    nextIdentifier etc. methods should be renamed.
120
claus
parents: 103
diff changeset
    49
    (to me, these seem to be internal private methods; their public use
claus
parents: 103
diff changeset
    50
     is not a good idea ..)
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    51
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    52
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
    53
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    54
"
41
62214c6ca833 allow turning off warnings
claus
parents: 38
diff changeset
    55
! !
62214c6ca833 allow turning off warnings
claus
parents: 38
diff changeset
    56
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    57
!Scanner class methodsFor:'initialization'!
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    58
60
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    59
initialize
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    60
    Warnings := true.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    61
    WarnSTXSpecials := true.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    62
    WarnUnderscoreInIdentifier := true.
87
claus
parents: 83
diff changeset
    63
    WarnOldStyleAssignment := true.
60
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    64
    AllowUnderscoreInIdentifier := false.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    65
!
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
    66
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    67
setupActions
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    68
    |block|
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    69
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    70
    ActionArray := Array new:256.
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    71
    TypeArray := Array new:256.
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    72
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    73
    block := [:s :char | s nextNumber].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    74
    ($0 asciiValue) to:($9 asciiValue) do:[:index |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
    75
	ActionArray at:index put:block
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    76
    ].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    77
87
claus
parents: 83
diff changeset
    78
    block := [:s :char | s nextSpecial].
89
claus
parents: 87
diff changeset
    79
    #( $& $- $+ $= $* $/ $\ $< $> $~ $@ $, $? "new:" $!! ) do:[:binop |
87
claus
parents: 83
diff changeset
    80
	TypeArray at:(binop asciiValue) put:#special.
claus
parents: 83
diff changeset
    81
	ActionArray at:(binop asciiValue) put:block
claus
parents: 83
diff changeset
    82
    ].
claus
parents: 83
diff changeset
    83
claus
parents: 83
diff changeset
    84
    block := [:s :char | s nextToken:char].
89
claus
parents: 87
diff changeset
    85
    #( $; $. $( $) $[ $] "$!!" $^ $| $_ ) do:[:ch |
87
claus
parents: 83
diff changeset
    86
	ActionArray at:(ch asciiValue) put:block
claus
parents: 83
diff changeset
    87
    ].
claus
parents: 83
diff changeset
    88
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    89
    block := [:s :char | s nextIdentifier].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    90
    ($a asciiValue) to:($z asciiValue) do:[:index |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
    91
	ActionArray at:index put:block
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    92
    ].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    93
    ($A asciiValue) to:($Z asciiValue) do:[:index |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
    94
	ActionArray at:index put:block
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    95
    ].
71
2aac7fbb5be0 *** empty log message ***
claus
parents: 69
diff changeset
    96
    AllowUnderscoreInIdentifier ifTrue:[
2aac7fbb5be0 *** empty log message ***
claus
parents: 69
diff changeset
    97
	ActionArray at:$_ asciiValue put:block
2aac7fbb5be0 *** empty log message ***
claus
parents: 69
diff changeset
    98
    ].
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
    99
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   100
    "kludge: action is characterToken, but type is special"
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   101
    TypeArray at:($| asciiValue) put:#special.
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   102
80
101b42803846 *** empty log message ***
claus
parents: 76
diff changeset
   103
    "kludge: action is nextColonOrAssign, but type is special"
101b42803846 *** empty log message ***
claus
parents: 76
diff changeset
   104
    TypeArray at:($: asciiValue) put:#special.
101b42803846 *** empty log message ***
claus
parents: 76
diff changeset
   105
33
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   106
    ActionArray at:($' asciiValue) put:[:s :char | s nextString].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   107
    ActionArray at:($$ asciiValue) put:[:s :char | s nextCharacter].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   108
    ActionArray at:($# asciiValue) put:[:s :char | s nextHash].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   109
    ActionArray at:($% asciiValue) put:[:s :char | s nextPrimitive].
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   110
    ActionArray at:($: asciiValue) put:[:s :char | s nextColonOrAssign]
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   111
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   112
    "
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   113
     Scanner setupActions
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   114
    "
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   115
! !
8985ec2f9e82 *** empty log message ***
claus
parents: 30
diff changeset
   116
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   117
!Scanner class methodsFor:'instance creation'!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   118
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   119
for:aStringOrStream
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   120
    "return a new scanner reading from aStringOrStream"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   121
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   122
    ^ (super new) initializeFor:aStringOrStream
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   123
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   124
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   125
!Scanner class methodsFor:'defaults'!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
allowUnderscoreInIdentifier
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   128
    "return true, if underscores are allowed in identifiers"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   130
    ^ AllowUnderscoreInIdentifier
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   133
allowUnderscoreInIdentifier:aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   134
    "this allows turning on/off underscores in identifiers.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
     If turned off (the default), underscores are not allowed in identifiers,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
     but instead scanned as assignment character (old ST/80 syntax).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   137
     If turned on, underscores are in identifiers are allowed, while extra
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
     underscores are still scanned as assignment.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
     If you have to fileIn VV-Vsn2 classes, 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
     add a line such as:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
	Compiler allowUnderscoreInIdentifiers:false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
     in your 'private.rc'/'smalltalk.rc' file"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
    AllowUnderscoreInIdentifier := aBoolean.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
    self setupActions
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
warnOldStyleAssignment
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   149
    "return true, if underscore-assignment (pre ST-80v4 syntax) are to be warned about"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   150
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   151
    ^ WarnOldStyleAssignment
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   152
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   153
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   154
warnOldStyleAssignment:aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   155
    "this allows turning on/off warnings about underscore-assignment (pre ST-80v4 syntax).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   156
     If you get bored by those warnings, turn them off by adding
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   157
     a line as:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   158
	Compiler warnOldStyleAssignment:false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   159
     in your 'private.rc' file"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   160
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   161
    WarnOldStyleAssignment := aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   162
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   163
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   164
warnSTXSpecials
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   165
    "return true, if ST/X specials are to be warned about"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   166
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   167
    ^ WarnSTXSpecials
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   168
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   169
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   170
warnSTXSpecials:aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   171
    "this allows turning on/off warnings about stx specials.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   172
     If you get bored by those warnings, turn them off by adding
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   173
     a line as:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   174
	Compiler warnSTXSpecials:false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   175
     in your 'private.rc' file"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   176
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   177
    WarnSTXSpecials := aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   178
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   179
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   180
warnUnderscoreInIdentifier
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   181
    "return true, if underscores in identifiers are to be warned about"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   182
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   183
    ^ WarnUnderscoreInIdentifier
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   184
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   185
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   186
warnUnderscoreInIdentifier:aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   187
    "this allows turning on/off warnings about underscores in identifiers.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   188
     If you get bored by those warnings, turn them off by adding
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   189
     a line as:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   190
	Compiler warnUnderscoreInIdentifier:false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   191
     in your 'private.rc' file"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   192
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   193
    WarnUnderscoreInIdentifier := aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   194
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   195
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   196
warnings
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   197
    "return true, if any warnings are to be shown"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   198
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   199
    ^ Warnings
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   200
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   201
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   202
warnings:aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   203
    "this allows turning on/off warnings; the default is on.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   204
     You can turn off warnings in your 'private.rc' file with
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   205
	 Compiler warnings:false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   206
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   207
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   208
    Warnings := aBoolean
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   209
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   210
98
claus
parents: 97
diff changeset
   211
!Scanner methodsFor:'ST-80 compatibility'!
claus
parents: 97
diff changeset
   212
claus
parents: 97
diff changeset
   213
endOfLastToken
claus
parents: 97
diff changeset
   214
    ^ source position
claus
parents: 97
diff changeset
   215
! !
claus
parents: 97
diff changeset
   216
254
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   217
!Scanner methodsFor:'accessing'!
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   218
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   219
comments
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   220
    ^ currentComments
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   221
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   222
    "Created: 20.4.1996 / 20:07:01 / cg"
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   223
!
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   224
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   225
saveComments:aBoolean
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   226
    saveComments := aBoolean
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   227
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   228
    "Created: 20.4.1996 / 20:03:56 / cg"
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   229
!
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   230
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   231
sourceStream
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   232
    ^ source
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   233
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   234
    "Created: 20.4.1996 / 19:59:58 / cg"
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   235
! !
edfcf93d821f changes to allow parsing for comments
Claus Gittinger <cg@exept.de>
parents: 241
diff changeset
   236
81
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   237
!Scanner methodsFor:'directives'!
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   238
74
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   239
parseDirective
81
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   240
    |directive packageName namespace list|
74
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   241
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   242
    source next.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   243
    source skipSeparatorsExceptCR.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   244
    hereChar := source peek.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   245
    hereChar isLetter ifTrue:[
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   246
	directive := source nextWord.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   247
	source peek == $: ifTrue:[
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   248
	    source next.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   249
	    source skipSeparatorsExceptCR.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   250
	    hereChar := source peek.
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   251
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   252
	    "
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   253
	     Package: 'name-of-package'
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   254
	    "
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   255
	    directive = 'Package' ifTrue:[
81
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   256
		packageName := self parseDirectiveStringArg.
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   257
		packageName notNil ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   258
		    (requestor respondsTo:#setPackage:) ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   259
			requestor setPackage:packageName
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   260
		    ].
74
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   261
		].
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   262
	    ].
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   263
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   264
	    "
81
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   265
	     Namespace: 'name-of-package'
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   266
	    "
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   267
	    directive = 'Namespace' ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   268
		namespace := self parseDirectiveStringArg.
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   269
		namespace notNil ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   270
		    (requestor respondsTo:#setNameSpace:) ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   271
			requestor setNameSpace:namespace 
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   272
		    ].
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   273
		].
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   274
	    ].
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   275
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   276
	    "
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   277
	     Uses: 'nameSpace1', ... , 'nameSpace2'
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   278
	    "
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   279
	    directive = 'Uses' ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   280
		list := self parseDirectiveStringListArg.
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   281
		(requestor respondsTo:#useNameSpaces:) ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   282
		    requestor useNameSpaces:list 
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   283
		].
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   284
	    ].
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   285
	    "
74
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   286
	     Prerequisites: 'name-of-package', ... , 'name-of-package'
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   287
	    "
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   288
	    directive = 'Prerequisites' ifTrue:[
81
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   289
		list := self parseDirectiveStringListArg.
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   290
		(requestor respondsTo:#requirePackages:) ifTrue:[
37ebe600119c *** empty log message ***
claus
parents: 80
diff changeset
   291
		    requestor requirePackages:list 
74
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   292
		].
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   293
	    ].
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   294
	]
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   295
    ].
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   296
    hereChar := source peek.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   297
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   298
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   299
parseDirectiveStringArg
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   300
    hereChar == $' ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   301
	self nextString.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   302
	tokenType == #String ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   303
	    ^ tokenValue
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   304
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   305
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   306
    ^ nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   307
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   308
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   309
parseDirectiveStringListArg
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   310
    |list|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   311
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   312
    list := OrderedCollection new.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   313
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   314
    [hereChar == $'] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   315
	list addLast:self parseDirectiveStringArg.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   316
	source skipSeparatorsExceptCR.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   317
	hereChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   318
	(hereChar == $,) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   319
	    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   320
	    source skipSeparatorsExceptCR.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   321
	    hereChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   322
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   323
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   324
    ^ list
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   325
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   326
7ad01559b262 Initial revision
claus
parents:
diff changeset
   327
!Scanner methodsFor:'error handling'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   328
7ad01559b262 Initial revision
claus
parents:
diff changeset
   329
notifyError:aMessage position:position to:endPos
7ad01559b262 Initial revision
claus
parents:
diff changeset
   330
    "notify requestor of an error - if there is no requestor
53
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   331
     put it on the transcript. Requestor is typically the CodeView
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   332
     in which the accept/doIt was triggered, or the PositionableStream
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   333
     which does the fileIn. The requestor may decide how to highlight the
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   334
     error (and/or to abort the compile).
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   335
     Return the result passed back by the requestor."
7ad01559b262 Initial revision
claus
parents:
diff changeset
   336
53
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   337
    ignoreErrors ifFalse:[
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   338
	requestor isNil ifTrue:[
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   339
	    self showErrorMessage:aMessage position:position.
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   340
	    ^ false
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   341
	].
83
claus
parents: 81
diff changeset
   342
	^ requestor error:aMessage position:position to:endPos from:self 
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   343
    ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   344
    ^ false
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   345
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   346
7ad01559b262 Initial revision
claus
parents:
diff changeset
   347
notifyWarning:aMessage position:position to:endPos
7ad01559b262 Initial revision
claus
parents:
diff changeset
   348
    "notify requestor of an warning - if there is no requestor
7ad01559b262 Initial revision
claus
parents:
diff changeset
   349
     put it on the transcript.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   350
     Return the result passed back by the requestor."
7ad01559b262 Initial revision
claus
parents:
diff changeset
   351
53
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   352
    ignoreWarnings ifFalse:[
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   353
	requestor isNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   354
	    self showErrorMessage:aMessage position:position.
53
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   355
	    ^ false
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   356
	].
83
claus
parents: 81
diff changeset
   357
	^ requestor warning:aMessage position:position to:endPos from:self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   358
    ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 49
diff changeset
   359
    ^ false
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   360
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   361
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   362
showErrorMessage:aMessage position:pos
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   363
    "show an errormessage on the Transcript"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   364
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   365
    ignoreErrors ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   366
	Smalltalk silentLoading == true ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   367
	    Transcript showCr:(pos printString , ' [line: ' , tokenLineNr printString , '] ' , aMessage)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   368
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   369
    ]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   370
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   371
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   372
syntaxError:aMessage
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   373
    "a syntax error happened - position is not known"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   374
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   375
    ^ self syntaxError:aMessage position:tokenPosition
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   376
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   377
7ad01559b262 Initial revision
claus
parents:
diff changeset
   378
syntaxError:aMessage position:position
7ad01559b262 Initial revision
claus
parents:
diff changeset
   379
    "a syntax error happened - only start position is known"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   380
7ad01559b262 Initial revision
claus
parents:
diff changeset
   381
    ^ self syntaxError:aMessage position:position to:nil
7ad01559b262 Initial revision
claus
parents:
diff changeset
   382
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   383
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   384
syntaxError:aMessage position:position to:endPos
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   385
    "a syntax error happened"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   386
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   387
    self notifyError:('Error:' , aMessage) position:position to:endPos.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   388
    exitBlock notNil ifTrue:[exitBlock value].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   389
    ^ false
87
claus
parents: 83
diff changeset
   390
!
claus
parents: 83
diff changeset
   391
claus
parents: 83
diff changeset
   392
warnOldStyleAssignmentAt:position
claus
parents: 83
diff changeset
   393
    ignoreWarnings ifFalse:[
claus
parents: 83
diff changeset
   394
	warnOldStyleAssignment ifTrue:[
claus
parents: 83
diff changeset
   395
	    self 
claus
parents: 83
diff changeset
   396
		warning:'old style assignment - please change to use '':='''
claus
parents: 83
diff changeset
   397
		position:position to:position.
claus
parents: 83
diff changeset
   398
	    "
claus
parents: 83
diff changeset
   399
	     only warn once (per method)
claus
parents: 83
diff changeset
   400
	    "
claus
parents: 83
diff changeset
   401
	    warnOldStyleAssignment := false
claus
parents: 83
diff changeset
   402
	]
claus
parents: 83
diff changeset
   403
    ]
claus
parents: 83
diff changeset
   404
!
claus
parents: 83
diff changeset
   405
claus
parents: 83
diff changeset
   406
warnUnderscoreAt:position
claus
parents: 83
diff changeset
   407
    ignoreWarnings ifFalse:[
claus
parents: 83
diff changeset
   408
	warnUnderscoreInIdentifier ifTrue:[
claus
parents: 83
diff changeset
   409
	    self 
claus
parents: 83
diff changeset
   410
		warning:'underscores in identifiers/symbols are nonportable' 
claus
parents: 83
diff changeset
   411
		position:position to:position.
claus
parents: 83
diff changeset
   412
	    "
claus
parents: 83
diff changeset
   413
	     only warn once (per method)
claus
parents: 83
diff changeset
   414
	    "
claus
parents: 83
diff changeset
   415
	    warnUnderscoreInIdentifier := false
claus
parents: 83
diff changeset
   416
	]
claus
parents: 83
diff changeset
   417
    ]
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   418
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   419
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   420
warning:aMessage
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   421
    "a warning - position is not known"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   422
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   423
    ^ self warning:aMessage position:tokenPosition
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   424
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   425
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   426
warning:aMessage position:position
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   427
    "a warning - only start position is known"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   428
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   429
    ^ self warning:aMessage position:position to:nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   430
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   431
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   432
warning:aMessage position:position to:endPos
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   433
    "a warning"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   434
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   435
    ^ self notifyWarning:('Warning: ' , aMessage) position:position to:endPos
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   436
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   437
17
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   438
!Scanner methodsFor:'general scanning'!
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   439
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   440
scanPositionsFor:aTokenString inString:aSourceString
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   441
    "scan aSourceString for occurrances of aTokenString.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   442
     Return a collection of start positions.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   443
     Added for VW compatibility (to support syntax-highlight)."
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   444
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   445
    |searchType searchName searchValue positions t|
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   446
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   447
    "
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   448
     first, look what kind of token we have to search for
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   449
    "
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   450
    self initializeFor:(ReadStream on:aTokenString).
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   451
    self nextToken.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   452
    searchType := tokenType.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   453
    searchName := tokenName.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   454
    searchValue := tokenValue.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   455
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   456
    "
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   457
     start the real work ...
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   458
    "
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   459
    self initializeFor:(ReadStream on:aSourceString).
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   460
    positions := OrderedCollection new.
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   461
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   462
    [(t := self nextToken) ~~ #EOF] whileTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   463
	searchType == t ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   464
	    (searchName isNil or:[tokenName = searchName]) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   465
		(searchValue isNil or:[tokenValue = searchValue]) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   466
		    positions add:tokenPosition.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   467
		]
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   468
	    ]
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   469
	]
17
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   470
    ].
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   471
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   472
    ^ positions
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   473
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   474
    "
30
26e2f849916a keep tokenRadix; accept E in floats
claus
parents: 20
diff changeset
   475
     Scanner new scanPositionsFor:'hello' inString:'foo bar hello baz hello' 
26e2f849916a keep tokenRadix; accept E in floats
claus
parents: 20
diff changeset
   476
     Scanner new scanPositionsFor:'3.14' inString:'foo 3.145 bar hello 3.14 baz hello 3.14' 
26e2f849916a keep tokenRadix; accept E in floats
claus
parents: 20
diff changeset
   477
     Scanner new scanPositionsFor:'16' inString:'foo 16 bar hello 16r10 baz hello 2r10000' 
17
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   478
    "
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   479
! !
f06d70d785dc *** empty log message ***
claus
parents: 15
diff changeset
   480
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   481
!Scanner methodsFor:'private'!
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   482
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   483
backupPosition
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   484
    "if reading from a stream, at the end we might have read
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   485
     one token too many"
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
   486
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   487
    (tokenType == #EOF) ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   488
	source position:tokenPosition
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   489
    ]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   490
!
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
   491
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   492
beginComment
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   493
    ^ self
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   494
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   495
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   496
collectedSource
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   497
    ^ collectedSource
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   498
!
74
fee7c3091f71 *** empty log message ***
claus
parents: 71
diff changeset
   499
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   500
endComment:comment
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   501
    saveComments ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   502
	currentComments isNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   503
	    currentComments := OrderedCollection with:comment
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   504
	] ifFalse:[
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   505
	    currentComments add:comment
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   506
	]
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   507
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   508
!
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   509
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   510
ignoreErrors
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   511
    "turn off notification of errors"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   512
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   513
    ignoreErrors := true
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   514
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   515
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   516
ignoreWarnings
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   517
    "turn off notification of warnings"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   518
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   519
    ignoreWarnings := true
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   520
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   521
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   522
initialize
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   523
    "prepare a scan"
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   524
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   525
    errorFlag := false.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   526
    tokenLineNr := 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   527
    currentComments := nil.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   528
    saveComments := false.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   529
    ignoreErrors := false.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   530
    ignoreWarnings := Warnings not.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   531
    warnSTXSpecialComment := WarnSTXSpecials.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   532
    warnUnderscoreInIdentifier := WarnUnderscoreInIdentifier.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   533
    warnOldStyleAssignment := WarnOldStyleAssignment.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   534
    ActionArray isNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   535
	self class setupActions
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   536
    ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   537
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   538
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   539
initializeFor:aStringOrStream
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   540
    "initialize -
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   541
     if this is the first time, setup character- and action tables"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   542
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   543
    self initialize.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   544
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   545
    aStringOrStream isStream ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   546
	source := ReadStream on:aStringOrStream
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   547
    ] ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   548
	source := aStringOrStream.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   549
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   550
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   551
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   552
notifying:anObject
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   553
    "set the requestor to be notified"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   554
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   555
    requestor := anObject
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   556
! !
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   557
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   558
!Scanner methodsFor:'reading next token'!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   559
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   560
nextCharacter
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   561
    "a $ has been read - return a character token"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   562
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   563
    |nextChar|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   564
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   565
    source next.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   566
    nextChar := source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   567
    nextChar notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   568
	tokenValue := nextChar.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   569
	tokenType := #Character
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   570
    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   571
	tokenType := #EOF
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   572
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   573
    ^ tokenType
7ad01559b262 Initial revision
claus
parents:
diff changeset
   574
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   575
7ad01559b262 Initial revision
claus
parents:
diff changeset
   576
nextColonOrAssign
7ad01559b262 Initial revision
claus
parents:
diff changeset
   577
    "colon has been read - look for = to make it an assign"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   578
120
claus
parents: 103
diff changeset
   579
    "/ special kludge for identifier:= (without spaces inbetween)
claus
parents: 103
diff changeset
   580
    "/ here we needed two characters lookahead after the identifier ...
claus
parents: 103
diff changeset
   581
claus
parents: 103
diff changeset
   582
    peekChar == $= ifTrue:[
claus
parents: 103
diff changeset
   583
	source next.
claus
parents: 103
diff changeset
   584
	peekChar := nil.
claus
parents: 103
diff changeset
   585
	tokenType := #':='.
claus
parents: 103
diff changeset
   586
	^ tokenType
claus
parents: 103
diff changeset
   587
    ].
claus
parents: 103
diff changeset
   588
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   589
    (source nextPeek == $=) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   590
	source next.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   591
	tokenType := $_
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   592
    ] ifFalse:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   593
	tokenType := $:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   594
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   595
    ^ tokenType
7ad01559b262 Initial revision
claus
parents:
diff changeset
   596
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   597
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   598
nextHash
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   599
    |nextChar string|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   600
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   601
    nextChar := source nextPeek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   602
    nextChar notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   603
	nextChar isLetterOrDigit ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   604
	    string := ''.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   605
	    [nextChar notNil and:[nextChar isLetterOrDigit]] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   606
		string := string , (source nextAlphaNumericWord "self nextId").
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   607
		nextChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   608
		AllowUnderscoreInIdentifier == true ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   609
		    nextChar == $_ ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   610
			self warnUnderscoreAt:source position.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   611
		    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   612
		    [nextChar == $_] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   613
			string := string copyWith:nextChar.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   614
			nextChar := source nextPeek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   615
			(nextChar isAlphaNumeric) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   616
			    string := string , source nextAlphaNumericWord.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   617
			    nextChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   618
			]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   619
		    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   620
		].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   621
		(nextChar == $:) ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   622
		    tokenValue := string asSymbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   623
		    tokenType := #Symbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   624
		    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   625
		].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   626
		string := string copyWith:nextChar.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   627
		nextChar := source nextPeek
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   628
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   629
	    tokenValue := string asSymbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   630
	    tokenType := #Symbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   631
	    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   632
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   633
	(nextChar == $( ) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   634
	    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   635
	    tokenType := #HashLeftParen.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   636
	    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   637
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   638
	(nextChar == $[ ) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   639
	    "it seems that ST-80 supports Constant ByteArrays as #[...]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   640
	     (seen in a PD program)"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   641
	    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   642
	    tokenType := #HashLeftBrack.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   643
	    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   644
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   645
	(nextChar == $' ) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   646
	    "it seems that ST-80 supports arbitrary symbols as #'...'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   647
	     (seen in a PD program)"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   648
	    self nextString.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   649
	    tokenValue := tokenValue asSymbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   650
	    tokenType := #Symbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   651
	    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   652
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   653
	((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   654
	    string := source next asString.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   655
	    nextChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   656
	    nextChar notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   657
		((TypeArray at:(nextChar asciiValue)) == #special) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   658
		    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   659
		    string := string copyWith:nextChar
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   660
		]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   661
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   662
	    tokenValue := string asSymbol.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   663
	    tokenType := #Symbol.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   664
	    ^ tokenType
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   665
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   666
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   667
    "this allows hash to be used as binop -
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   668
     I dont know, if this is correct ..."
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   669
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   670
    tokenName := '#'.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   671
    tokenType := #BinaryOperator.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   672
    ^ tokenType
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   673
"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   674
    self syntaxError:'unexpected end-of-input in Symbol'
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   675
	    position:tokenPosition to:(tokenPosition + 1).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   676
    ^ #Error
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   677
"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   678
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   679
7ad01559b262 Initial revision
claus
parents:
diff changeset
   680
nextId
7ad01559b262 Initial revision
claus
parents:
diff changeset
   681
    |nextChar string oldString 
7ad01559b262 Initial revision
claus
parents:
diff changeset
   682
     index "{ Class: SmallInteger }"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   683
     max   "{ Class: SmallInteger }" |
7ad01559b262 Initial revision
claus
parents:
diff changeset
   684
7ad01559b262 Initial revision
claus
parents:
diff changeset
   685
    nextChar := source peek.
96
claus
parents: 91
diff changeset
   686
    string := String basicNew:20.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   687
    index := 0.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   688
    max := 10.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   689
    [true] whileTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   690
	(nextChar notNil and:[nextChar isLetterOrDigit]) ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   691
	    ^ string copyTo:index
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   692
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   693
	(index == max) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   694
	    oldString := string.
96
claus
parents: 91
diff changeset
   695
	    string := String basicNew:(max * 2).
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   696
	    string replaceFrom:1 to:max with:oldString.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   697
	    max := max * 2
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   698
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   699
	index := index + 1.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   700
	string at:index put:nextChar.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   701
	nextChar := source nextPeek
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   702
    ]
7ad01559b262 Initial revision
claus
parents:
diff changeset
   703
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   704
7ad01559b262 Initial revision
claus
parents:
diff changeset
   705
nextIdentifier
97
claus
parents: 96
diff changeset
   706
    |nextChar string firstChar|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   707
87
claus
parents: 83
diff changeset
   708
    hereChar == $_ ifTrue:[
claus
parents: 83
diff changeset
   709
	"/
claus
parents: 83
diff changeset
   710
	"/ no need to check for AllowUnderscoreInIdentifier here;
claus
parents: 83
diff changeset
   711
	"/ could not arrive here if it was off
claus
parents: 83
diff changeset
   712
	"/
claus
parents: 83
diff changeset
   713
	nextChar := source nextPeek.
claus
parents: 83
diff changeset
   714
	(nextChar isAlphaNumeric or:[nextChar == $_]) ifFalse:[
claus
parents: 83
diff changeset
   715
	    "oops: a single underscore is an old-style assignement"
claus
parents: 83
diff changeset
   716
	    self warnOldStyleAssignmentAt:tokenPosition.
claus
parents: 83
diff changeset
   717
	    source next.
claus
parents: 83
diff changeset
   718
	    tokenType := $_.
claus
parents: 83
diff changeset
   719
	    ^ tokenType
claus
parents: 83
diff changeset
   720
	].
claus
parents: 83
diff changeset
   721
	string := '_'.
claus
parents: 83
diff changeset
   722
	self warnUnderscoreAt:tokenPosition.
claus
parents: 83
diff changeset
   723
	[nextChar == '_'] whileTrue:[
claus
parents: 83
diff changeset
   724
	    string := string copyWith:$_.
claus
parents: 83
diff changeset
   725
	    nextChar := source nextPeek.
claus
parents: 83
diff changeset
   726
	].
claus
parents: 83
diff changeset
   727
	string := string , source nextAlphaNumericWord.
claus
parents: 83
diff changeset
   728
    ] ifFalse:[
claus
parents: 83
diff changeset
   729
	string := source nextAlphaNumericWord "self nextId".
claus
parents: 83
diff changeset
   730
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   731
    nextChar := source peek.
87
claus
parents: 83
diff changeset
   732
60
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   733
    AllowUnderscoreInIdentifier ifTrue:[
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   734
	nextChar == $_ ifTrue:[
87
claus
parents: 83
diff changeset
   735
	    self warnUnderscoreAt:(source position).
60
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   736
	].
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   737
	[nextChar == $_] whileTrue:[
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   738
	    string := string copyWith:nextChar.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   739
	    nextChar := source nextPeek.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   740
	    (nextChar isAlphaNumeric) ifTrue:[
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   741
		string := string , source nextAlphaNumericWord.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   742
		nextChar := source peek.
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   743
	    ]
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   744
	].
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   745
    ].
0db697f03def *** empty log message ***
claus
parents: 53
diff changeset
   746
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   747
    (nextChar == $:) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   748
	source next.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   749
	(source peek == $=) ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   750
	    tokenName := string copyWith:nextChar.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   751
	    tokenType := #Keyword.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   752
	    ^ self
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   753
	].
120
claus
parents: 103
diff changeset
   754
	peekChar := $:.
claus
parents: 103
diff changeset
   755
	peekChar2 := $=.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   756
    ].
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
   757
    tokenName := string.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   758
    firstChar := string at:1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   759
    (firstChar == $s) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   760
	(string = 'self') ifTrue:[tokenType := #Self. ^self].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   761
	(string = 'super') ifTrue:[tokenType := #Super. ^self]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   762
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   763
    (firstChar == $n) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   764
	(string = 'nil') ifTrue:[tokenType := #Nil. ^self]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   765
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   766
    (firstChar == $t) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   767
	(string = 'true') ifTrue:[tokenType := #True. ^self].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   768
	(string = 'thisContext') ifTrue:[tokenType := #ThisContext. ^self]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   769
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   770
    (firstChar == $f) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   771
	(string = 'false') ifTrue:[tokenType := #False. ^self]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   772
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   773
    tokenType := #Identifier.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   774
    ^ tokenType
120
claus
parents: 103
diff changeset
   775
claus
parents: 103
diff changeset
   776
    "Created: 13.9.1995 / 12:56:42 / claus"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   777
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   778
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   779
nextMantissa:radix
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   780
    |nextChar value factor|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   781
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   782
    value := 0.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   783
    factor := 1.0 / radix.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   784
    nextChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   785
    [(nextChar notNil and:[nextChar isDigitRadix:radix])] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   786
	value := value + (nextChar digitValue * factor).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   787
	factor := factor / radix.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   788
	nextChar := source nextPeek
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   789
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   790
    ^ value
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   791
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   792
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   793
nextNumber
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   794
    |nextChar value s|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   795
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   796
    tokenRadix := 10.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   797
    value := Integer readFrom:source radix:tokenRadix.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   798
    nextChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   799
    (nextChar == $r) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   800
	tokenRadix := value.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   801
	source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   802
	s := 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   803
	source peek == $- ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   804
	    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   805
	    s := -1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   806
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   807
	value := Integer readFrom:source radix:tokenRadix.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   808
	value := value * s.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   809
	nextChar := source peek
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   810
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   811
    (nextChar == $.) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   812
	nextChar := source nextPeek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   813
	(nextChar notNil and:[nextChar isDigitRadix:tokenRadix]) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   814
	    value := value asFloat + (self nextMantissa:tokenRadix).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   815
	    nextChar := source peek
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   816
	] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   817
	    nextChar == (Character cr) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   818
		tokenLineNr := tokenLineNr + 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   819
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   820
	    peekChar := $.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   821
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   822
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   823
    ((nextChar == $e) or:[nextChar == $E]) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   824
	nextChar := source nextPeek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   825
	(nextChar notNil and:[(nextChar isDigitRadix:tokenRadix) or:['+-' includes:nextChar]]) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   826
	    s := 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   827
	    (nextChar == $+) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   828
		nextChar := source nextPeek
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   829
	    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   830
		(nextChar == $-) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   831
		    nextChar := source nextPeek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   832
		    s := s negated
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   833
		]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   834
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   835
	    value := value asFloat
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   836
		     * (10.0 raisedToInteger:((Integer readFrom:source radix:tokenRadix) * s))
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   837
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   838
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   839
    tokenValue := value.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   840
    (value isMemberOf:Float) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   841
	tokenType := #Float
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   842
    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   843
	tokenType := #Integer
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   844
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   845
    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   846
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   847
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   848
nextPrimitive
7ad01559b262 Initial revision
claus
parents:
diff changeset
   849
    |nextChar inPrimitive string 
7ad01559b262 Initial revision
claus
parents:
diff changeset
   850
     index "{ Class: SmallInteger }"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   851
     len   "{ Class: SmallInteger }" |
7ad01559b262 Initial revision
claus
parents:
diff changeset
   852
7ad01559b262 Initial revision
claus
parents:
diff changeset
   853
    nextChar := source nextPeek.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   854
    string := String new:500.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   855
    len := 500.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   856
    index := 1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   857
    (nextChar == ${) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   858
	nextChar := source nextPeek.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   859
	inPrimitive := true.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   860
	[inPrimitive] whileTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   861
	    [nextChar == $%] whileFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   862
		string at:index put:nextChar.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   863
		(index == len) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   864
		    string := string , (String new:len).
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   865
		    len := len * 2
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   866
		].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   867
		index := index + 1.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   868
		nextChar := source next
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   869
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   870
	    (source peek == $}) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   871
		inPrimitive := false
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   872
	    ] ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   873
		string at:index put:nextChar.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   874
		(index == len) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   875
		    string := string , (String new:len).
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   876
		    len := len * 2
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   877
		].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   878
		index := index + 1.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   879
		nextChar := source next
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   880
	    ]
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   881
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   882
	source next.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   883
	tokenValue := string copyTo:(index - 1).
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   884
	tokenType := #Primitive.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   885
	tokenLineNr := tokenLineNr + (tokenValue occurrencesOf:(Character cr)).
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   886
	^ tokenType
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   887
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   888
7ad01559b262 Initial revision
claus
parents:
diff changeset
   889
    "a % alone is a binary operator"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   890
    tokenName := '%'.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   891
    tokenType := #BinaryOperator.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   892
    ^ tokenType.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   893
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   894
    self syntaxError:('invalid character: ''' , nextChar asString , '''')
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   895
	    position:tokenPosition to:(tokenPosition + 1).
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   896
    ^ #Error
7ad01559b262 Initial revision
claus
parents:
diff changeset
   897
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   898
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   899
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   900
nextSpecial
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   901
    "a special character has been read, look for another one.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   902
     also -number is handled here"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   903
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   904
    |firstChar secondChar thirdChar string p|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   905
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   906
    firstChar := source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   907
    secondChar := source peek.
241
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   908
    ((firstChar == $-) and:[secondChar notNil]) ifTrue:[
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   909
        secondChar isDigit ifTrue:[
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   910
            self nextNumber.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   911
            tokenValue := tokenValue negated.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   912
            ^ tokenType
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   913
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   914
    ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   915
    string := firstChar asString.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   916
    secondChar notNil ifTrue:[
241
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   917
        ((TypeArray at:(secondChar asciiValue)) == #special) ifTrue:[
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   918
            (secondChar == $-) ifTrue:[
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   919
                "special- look if minus belongs to number following"
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   920
                p := source position.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   921
                source next.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   922
                thirdChar := source peek.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   923
                source position:p.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   924
                thirdChar isDigit ifTrue:[
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   925
                    tokenName := string.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   926
                    tokenType := #BinaryOperator.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   927
                    ^ tokenType
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   928
                ]
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   929
            ].
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   930
            source next.
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   931
            string := string copyWith:secondChar
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   932
        ].
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   933
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   934
    tokenName := string.
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   935
    tokenType := #BinaryOperator.
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   936
    ^ tokenType
241
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   937
418eb41350d3 no debugger when parsing '-' (which is wrong anyway ...)
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   938
    "Modified: 12.4.1996 / 15:05:19 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   939
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   940
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
   941
pos
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   942
     index "{ Class: SmallInteger }"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   943
     len   "{ Class: SmallInteger }"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   944
     inString|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   945
96
claus
parents: 91
diff changeset
   946
    string := String basicNew:20.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   947
    len := 20.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   948
    index := 1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   949
    pos := source position.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   950
    source next.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   951
    nextChar := source next.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   952
    inString := true.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   953
7ad01559b262 Initial revision
claus
parents:
diff changeset
   954
    [inString] whileTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   955
	nextChar isNil ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   956
	    self syntaxError:'unexpected end-of-input in String'
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   957
		    position:pos to:(source position - 1).
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   958
	    tokenType := #EOF.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   959
	    ^ tokenType
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   960
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   961
	(nextChar == Character cr) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   962
	    tokenLineNr := tokenLineNr + 1
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   963
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   964
	(nextChar == Character quote) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   965
	    (source peek == Character quote) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   966
		source next
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   967
	    ] ifFalse:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   968
		inString := false
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   969
	    ]
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   970
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   971
	inString ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   972
	    string at:index put:nextChar.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   973
	    (index == len) ifTrue:[
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   974
		string := string , (String new:len).
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   975
		len := len * 2
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   976
	    ].
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   977
	    index := index + 1.
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   978
	    nextChar := source next
e8331ba8ad5d *** empty log message ***
claus
parents: 41
diff changeset
   979
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   980
    ].
15
992c3d87edbf *** empty log message ***
claus
parents: 10
diff changeset
   981
    tokenValue := string copyTo:(index - 1).
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   982
    tokenType := #String.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   983
    ^ tokenType
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   984
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   985
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
   986
oken from the source-stream"
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   987
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   988
    |skipping actionBlock|
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   989
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   990
    peekChar notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   991
	hereChar := peekChar.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   992
	peekChar := peekChar2.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   993
	peekChar2 := nil
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   994
    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   995
	skipping := true.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   996
	[skipping] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   997
	    outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   998
		[(hereChar := source peek) == Character space] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   999
		    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1000
		    outStream space. 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1001
		    outCol := outCol + 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1002
		]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1003
	    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1004
		hereChar := source skipSeparatorsExceptCR.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1005
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1006
	    hereChar == (Character cr) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1007
		tokenLineNr := tokenLineNr + 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1008
		source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1009
		outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1010
		    outStream cr.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1011
		    outCol := 1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1012
		]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1013
	    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1014
		hereChar == (Character doubleQuote) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1015
		    "start of a comment"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1016
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1017
		    self skipComment.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1018
		    hereChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1019
		] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1020
		    skipping := false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1021
		]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1022
	    ]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1023
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1024
	hereChar isNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1025
	    tokenType := #EOF.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1026
	    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1027
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1028
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1029
    tokenPosition := source position.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1030
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1031
    actionBlock := ActionArray at:(hereChar asciiValue).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1032
    actionBlock notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1033
	^ actionBlock value:self value:hereChar
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1034
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1035
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1036
    self syntaxError:('invalid character: ''' , hereChar asString , ''' ',
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1037
		      '(' , hereChar asciiValue printString , ')')
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1038
	    position:tokenPosition to:tokenPosition.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1039
    tokenType := #Error.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1040
    ^ #Error
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1041
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1042
    "Modified: 13.9.1995 / 12:56:14 / claus"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1043
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1044
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
  1045
pe := aCharacter.
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1046
    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1047
    ^ tokenType
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1048
!
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1049
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
  1050
tartPos|
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1051
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1052
    saveComments ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1053
	commentStream := WriteStream on:''.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1054
	self beginComment.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1055
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1056
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1057
    outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1058
	outStream nextPut:Character doubleQuote.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1059
	outCol := outCol + 1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1060
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1061
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1062
    startPos := source position.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1063
    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1064
    hereChar := source peek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1065
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1066
    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1067
     special ST/X addition:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1068
     a $/ right after the initial double quote makes it an up-to-end-of-line comment,
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1069
     which is very useful to comment out parts of filed-in source code.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1070
     Since this is non-standard, use it in very rare cases only. 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1071
     (maybe the upcoming ansi-standard adds something similar - in this case, I will
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1072
      change it without notice)"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1073
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1074
    hereChar == $/ ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1075
	[hereChar notNil and:[hereChar ~~ Character cr]] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1076
	    saveComments ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1077
		commentStream nextPut:hereChar
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1078
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1079
	    outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1080
		outStream nextPut:hereChar.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1081
		outCol := outCol + 1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1082
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1083
	    hereChar := source nextPeek.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1084
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1085
	tokenLineNr := tokenLineNr + 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1086
	ignoreWarnings ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1087
	    warnSTXSpecialComment ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1088
		self warning:'end-of-line comments are a nonstandard feature of ST/X' 
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1089
		     position:startPos to:(source position).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1090
		"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1091
		 only warn once
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1092
		"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1093
		warnSTXSpecialComment := false
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1094
	    ]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1095
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1096
	outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1097
	    outStream cr.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1098
	    outCol := 1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1099
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1100
    ] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1101
	hereChar == ${ ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1102
	    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1103
	     special ST/X addition:
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1104
	     a ${ right after the initial double quote starts a directive
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1105
	    "
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1106
	    self parseDirective
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1107
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1108
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1109
	[hereChar notNil and:[hereChar ~~ (Character doubleQuote)]] whileTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1110
	    hereChar == (Character cr) ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1111
		tokenLineNr := tokenLineNr + 1.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1112
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1113
	    saveComments ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1114
		commentStream nextPut:hereChar
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1115
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1116
	    outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1117
		outStream nextPut:hereChar.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1118
		outCol := outCol + 1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1119
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1120
	    hereChar := source nextPeek
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1121
	].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1122
	hereChar isNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1123
	    self warning:'unclosed comment' position:startPos to:(source position)
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1124
	] ifFalse:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1125
	    outStream notNil ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1126
		outStream nextPut:(Character doubleQuote).
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1127
		outCol := outCol + 1
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1128
	    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1129
	]
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1130
    ].
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1131
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1132
    "skip final dQuote or cr"
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1133
    source next.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1134
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1135
    saveComments ifTrue:[
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1136
	self endComment:commentStream contents.
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1137
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1138
! !
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1139
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 141
diff changeset
  1140
!Scanner class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 141
diff changeset
  1141
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 254
diff changeset
  1142
VS/stx/libcomp/Scanner.st,v 1.40 1996/04/20 18:08:54 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 141
diff changeset
  1143
! !
141
d378d997aab0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1144
Scanner initialize!