Scanner.st
changeset 2140 f9b4ef3e9368
parent 2139 ff81d8aadd3f
child 2141 de005dc56384
equal deleted inserted replaced
2139:ff81d8aadd3f 2140:f9b4ef3e9368
    17 		requestor exitBlock errorFlag ignoreErrors ignoreWarnings
    17 		requestor exitBlock errorFlag ignoreErrors ignoreWarnings
    18 		saveComments currentComments collectedSource scanColonAsKeyword
    18 		saveComments currentComments collectedSource scanColonAsKeyword
    19 		outStream outCol inArrayLiteral lastDirective parserFlags
    19 		outStream outCol inArrayLiteral lastDirective parserFlags
    20 		didWarnAboutSTXSpecialComment didWarnAboutUnderscoreInIdentifier
    20 		didWarnAboutSTXSpecialComment didWarnAboutUnderscoreInIdentifier
    21 		didWarnAboutOldStyleAssignment didWarnAboutDollarInIdentifier'
    21 		didWarnAboutOldStyleAssignment didWarnAboutDollarInIdentifier'
    22 	classVariableNames:'TypeArray ActionArray Warnings EmptySourceNotificationSignal'
    22 	classVariableNames:'DefaultTypeArray DefaultActionArray Warnings
       
    23 		EmptySourceNotificationSignal'
    23 	poolDictionaries:''
    24 	poolDictionaries:''
    24 	category:'System-Compiler'
    25 	category:'System-Compiler'
       
    26 !
       
    27 
       
    28 Scanner class instanceVariableNames:'TypeArray ActionArray'
       
    29 
       
    30 "
       
    31  No other class instance variables are inherited by this class.
       
    32 "
    25 !
    33 !
    26 
    34 
    27 Object subclass:#Comment
    35 Object subclass:#Comment
    28 	instanceVariableNames:'commentType commentString'
    36 	instanceVariableNames:'commentType commentString'
    29 	classVariableNames:''
    37 	classVariableNames:''
   150 
   158 
   151 setupActions
   159 setupActions
   152     "initialize the scanners actionTables - these are used to dispatch
   160     "initialize the scanners actionTables - these are used to dispatch
   153      into scanner methods as characters are read"
   161      into scanner methods as characters are read"
   154 
   162 
   155     |block|
   163     |block actionArray typeArray|
   156 
   164 
   157     ActionArray := Array new:256.
   165     actionArray := Array new:256.
   158     TypeArray := Array new:256.
   166     typeArray := Array new:256.
   159 
   167 
   160     "/ TODO: later versions should be configurable w.r.t separators.
   168     "/ TODO: later versions should be configurable w.r.t separators.
   161     "/ #(9 10 12 13 26 32) do: [:i | TypeArray at:(i+1) put: #separator].
   169     "/ #(9 10 12 13 26 32) do: [:i | TypeArray at:(i+1) put: #separator].
   162 
   170 
   163     block := [:s :char | s nextNumber].
   171     block := [:s :char | s nextNumber].
   164     ($0 codePoint) to:($9 codePoint) do:[:index |
   172     ($0 codePoint) to:($9 codePoint) do:[:index |
   165         ActionArray at:index put:block
   173         actionArray at:index put:block
   166     ].
   174     ].
   167 
   175 
   168     block := [:s :char | s nextSpecial].
   176     block := [:s :char | s nextSpecial].
   169     self binarySelectorCharacters do:[:binop |
   177     self binarySelectorCharacters do:[:binop |
   170         TypeArray at:(binop codePoint) put:#special.
   178         typeArray at:(binop codePoint) put:#special.
   171         ActionArray at:(binop codePoint) put:block
   179         actionArray at:(binop codePoint) put:block
   172     ].
   180     ].
   173     block := [:s :char | s nextExtendedSpecial].
   181     block := [:s :char | s nextExtendedSpecial].
   174     self extendedBinarySelectorCharacters do:[:binop |
   182     self extendedBinarySelectorCharacters do:[:binop |
   175         TypeArray at:(binop codePoint) put:#extendedSpecial.
   183         typeArray at:(binop codePoint) put:#extendedSpecial.
   176         ActionArray at:(binop codePoint) put:block
   184         actionArray at:(binop codePoint) put:block
   177     ].
   185     ].
   178 
   186 
   179     "/ that one is a special case (both binarySelector AND syntax).
   187     "/ that one is a special case (both binarySelector AND syntax).
   180     TypeArray at:($| codePoint) put:nil.
   188     typeArray at:($| codePoint) put:nil.
   181 
   189 
   182     block := [:s :char | s nextToken:char].
   190     block := [:s :char | s nextToken:char].
   183     ';.^|()[]{}' do:[:ch |
   191     ';.^|()[]{}' do:[:ch |
   184         ActionArray at:(ch codePoint) put:block
   192         actionArray at:(ch codePoint) put:block
   185     ].
   193     ].
   186 
   194 
   187     block := [:s :char | s nextIdentifier].
   195     block := [:s :char | s nextIdentifier].
   188     ($a codePoint) to:($z codePoint) do:[:index |
   196     ($a codePoint) to:($z codePoint) do:[:index |
   189         ActionArray at:index put:block
   197         actionArray at:index put:block
   190     ].
   198     ].
   191     ($A codePoint) to:($Z codePoint) do:[:index |
   199     ($A codePoint) to:($Z codePoint) do:[:index |
   192         ActionArray at:index put:block
   200         actionArray at:index put:block
   193     ].
   201     ].
   194 
   202 
   195     "kludge: action is characterToken, but type is special"
   203     "kludge: action is characterToken, but type is special"
   196     TypeArray at:($| codePoint) put:#special.
   204     typeArray at:($| codePoint) put:#special.
   197 
   205 
   198     "kludge: action is nextColonOrAssign, but type is special"
   206     "kludge: action is nextColonOrAssign, but type is special"
   199     TypeArray at:($: codePoint) put:#special.
   207     typeArray at:($: codePoint) put:#special.
   200 
   208 
   201     ActionArray at:($' codePoint) put:[:s :char | s nextString:char].
   209     actionArray at:($' codePoint) put:[:s :char | s nextString:char].
   202     ActionArray at:($$ codePoint) put:[:s :char | s nextCharacter].
   210     actionArray at:($$ codePoint) put:[:s :char | s nextCharacter].
   203     ActionArray at:($# codePoint) put:[:s :char | s nextHash].
   211     actionArray at:($# codePoint) put:[:s :char | s nextHash].
   204     ActionArray at:($!! codePoint) put:[:s :char | s nextExcla].
   212     actionArray at:($!! codePoint) put:[:s :char | s nextExcla].
   205     ActionArray at:($% codePoint) put:[:s :char | s nextPrimitive].
   213     actionArray at:($% codePoint) put:[:s :char | s nextPrimitive].
   206     ActionArray at:($: codePoint) put:[:s :char | s nextColonOrAssign].
   214     actionArray at:($: codePoint) put:[:s :char | s nextColonOrAssign].
   207     ActionArray at:($_ codePoint) put:[:s :char | s nextUnderline].
   215     actionArray at:($_ codePoint) put:[:s :char | s nextUnderline].
       
   216 
       
   217     ActionArray := DefaultActionArray := actionArray.
       
   218     TypeArray := DefaultTypeArray := typeArray.
   208 
   219 
   209     "
   220     "
   210      Scanner setupActions
   221      Scanner setupActions
   211     "
   222     "
   212 
   223 
   240 
   251 
   241 emptySourceNotificationSignal
   252 emptySourceNotificationSignal
   242     ^ EmptySourceNotificationSignal
   253     ^ EmptySourceNotificationSignal
   243 
   254 
   244     "Created: / 16.5.1998 / 15:55:14 / cg"
   255     "Created: / 16.5.1998 / 15:55:14 / cg"
       
   256 ! !
       
   257 
       
   258 !Scanner class methodsFor:'accessing'!
       
   259 
       
   260 actionArray
       
   261     ActionArray isNil ifTrue:[
       
   262         self setupActions
       
   263     ].
       
   264     ^ ActionArray ? DefaultActionArray
       
   265 !
       
   266 
       
   267 typeArray
       
   268     TypeArray isNil ifTrue:[
       
   269         self setupActions
       
   270     ].
       
   271     ^ TypeArray ? DefaultTypeArray
   245 ! !
   272 ! !
   246 
   273 
   247 !Scanner class methodsFor:'class initialization'!
   274 !Scanner class methodsFor:'class initialization'!
   248 
   275 
   249 initialize
   276 initialize
  1700 
  1727 
  1701     "Modified: / 19-10-2006 / 11:36:15 / cg"
  1728     "Modified: / 19-10-2006 / 11:36:15 / cg"
  1702 !
  1729 !
  1703 
  1730 
  1704 initializeActionTable
  1731 initializeActionTable
  1705     ActionArray isNil ifTrue:[
  1732     actionArray := self class actionArray.
  1706         self class setupActions
  1733     typeArray := self class typeArray.
  1707     ].
       
  1708     actionArray := ActionArray.
       
  1709     typeArray := TypeArray.
       
  1710 
  1734 
  1711     "Created: / 18-10-2006 / 23:10:55 / cg"
  1735     "Created: / 18-10-2006 / 23:10:55 / cg"
  1712 !
  1736 !
  1713 
  1737 
  1714 initializeFlagsFrom:aScanner
  1738 initializeFlagsFrom:aScanner
  3180 ! !
  3204 ! !
  3181 
  3205 
  3182 !Scanner class methodsFor:'documentation'!
  3206 !Scanner class methodsFor:'documentation'!
  3183 
  3207 
  3184 version
  3208 version
  3185     ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.241 2008-12-16 12:42:27 cg Exp $'
  3209     ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.242 2008-12-16 14:31:01 cg Exp $'
  3186 ! !
  3210 ! !
  3187 
  3211 
  3188 Scanner initialize!
  3212 Scanner initialize!