Scanner.st
changeset 1856 209089a85ed3
parent 1781 3d5065c74df5
child 1900 66c65b0abf72
equal deleted inserted replaced
1855:61936f01108e 1856:209089a85ed3
  1174     self parseError:message.
  1174     self parseError:message.
  1175     "/ if proceeded, install method anyway (used with non-st/x primitives)
  1175     "/ if proceeded, install method anyway (used with non-st/x primitives)
  1176     errorFlag := false.
  1176     errorFlag := false.
  1177 !
  1177 !
  1178 
  1178 
       
  1179 invalidCharacter:ch
       
  1180     |errMsg v|
       
  1181 
       
  1182     v := ch codePoint.
       
  1183     ch isPrintable ifTrue:[
       
  1184         errMsg := 'Invalid character: ''' , ch asString , ''' ', '(' , (v radixPrintStringRadix:16) , ').'.
       
  1185     ] ifFalse:[
       
  1186         errMsg := 'Invalid character: ' , (v radixPrintStringRadix:16) , '.'.
       
  1187     ].
       
  1188     v > 16r7F ifTrue:[
       
  1189         errMsg := errMsg , '\\Notice: only 7-bit ascii allowed (for compatibility).' withCRs.
       
  1190     ].
       
  1191     self syntaxError:errMsg position:tokenPosition to:tokenPosition.
       
  1192     source next.
       
  1193     tokenName := token := nil.
       
  1194     tokenType := #Error.
       
  1195     ^ #Error
       
  1196 
       
  1197     "Modified: / 22-08-2006 / 14:26:21 / cg"
       
  1198 !
       
  1199 
  1179 lastTokenLineNumber
  1200 lastTokenLineNumber
  1180     "return the line number of the token which was just read."
  1201     "return the line number of the token which was just read."
  1181 
  1202 
  1182     ^ tokenLineNr
  1203     ^ tokenLineNr
  1183 
  1204 
  1203 
  1224 
  1204         Parser::ParseError isHandled ifTrue:[
  1225         Parser::ParseError isHandled ifTrue:[
  1205             err := Parser::ParseError new.
  1226             err := Parser::ParseError new.
  1206             err errorMessage:aMessage startPosition:position endPosition:endPos.
  1227             err errorMessage:aMessage startPosition:position endPosition:endPos.
  1207             err parameter:self.
  1228             err parameter:self.
  1208             err lineNumber:lineNr.
  1229             err lineNumber:tokenLineNr "lineNr".
  1209             err raiseRequest.
  1230             err raiseRequest.
  1210             ^ self
  1231             ^ self
  1211         ].
  1232         ].
  1212         self showErrorMessage:aMessage position:position.
  1233         self showErrorMessage:aMessage position:position.
  1213     ].
  1234     ].
       
  1235 
       
  1236     "Modified: / 22-08-2006 / 14:10:16 / cg"
  1214 !
  1237 !
  1215 
  1238 
  1216 notifyWarning:aMessage doNotShowAgainAction:doNotShowAgainAction position:position to:endPos
  1239 notifyWarning:aMessage doNotShowAgainAction:doNotShowAgainAction position:position to:endPos
  1217     "notify requestor of an warning - if there is no requestor, just ignore it.
  1240     "notify requestor of an warning - if there is no requestor, just ignore it.
  1218      Return the result passed back from the requestor (or false, if there is none)."
  1241      Return the result passed back from the requestor (or false, if there is none)."
  1262 !
  1285 !
  1263 
  1286 
  1264 parseError:aMessage position:position to:endPos
  1287 parseError:aMessage position:position to:endPos
  1265     "report an error"
  1288     "report an error"
  1266 
  1289 
  1267     |m|
  1290     |m fullMessage|
  1268 
  1291 
       
  1292     "/ fullMessage := (self errorMessagePrefix) , ' ' , (aMessage ? '???').
       
  1293     fullMessage := (aMessage ? 'Unspecified error').
  1269     self errorFlag:true.
  1294     self errorFlag:true.
  1270     m := (self errorMessagePrefix) , ' ' , (aMessage ? '???').
  1295     self notifyError:fullMessage position:position to:endPos.
  1271     self notifyError:m position:position to:endPos.
       
  1272     exitBlock value.
  1296     exitBlock value.
  1273     ^ false
  1297     ^ false
  1274 
  1298 
  1275     "Created: / 13.5.1998 / 16:44:55 / cg"
  1299     "Created: / 13-05-1998 / 16:44:55 / cg"
  1276     "Modified: / 28.9.1998 / 19:29:27 / cg"
  1300     "Modified: / 22-08-2006 / 14:13:11 / cg"
  1277 !
  1301 !
  1278 
  1302 
  1279 showErrorMessage:aMessage position:pos
  1303 showErrorMessage:aMessage position:pos
  1280     "show an errormessage on the Transcript"
  1304     "show an errormessage on the Transcript"
  1281 
  1305 
  1301 !
  1325 !
  1302 
  1326 
  1303 syntaxError:aMessage position:position to:endPos
  1327 syntaxError:aMessage position:position to:endPos
  1304     "a syntax error happened"
  1328     "a syntax error happened"
  1305 
  1329 
  1306     self notifyError:((self errorMessagePrefix) , ' ' , aMessage) position:position to:endPos.
  1330     |fullMessage|
       
  1331 
       
  1332     "/ fullMessage := self errorMessagePrefix , ' ' , aMessage.
       
  1333     fullMessage := aMessage.
       
  1334     self notifyError:fullMessage position:position to:endPos.
  1307     exitBlock value.
  1335     exitBlock value.
  1308     ^ false
  1336     ^ false
       
  1337 
       
  1338     "Modified: / 22-08-2006 / 14:05:45 / cg"
  1309 !
  1339 !
  1310 
  1340 
  1311 warnCommonMistake:msg at:position
  1341 warnCommonMistake:msg at:position
  1312     "warn about a common beginners mistake"
  1342     "warn about a common beginners mistake"
  1313 
  1343 
  1873 
  1903 
  1874 setSyntax:aSyntax
  1904 setSyntax:aSyntax
  1875 ! !
  1905 ! !
  1876 
  1906 
  1877 !Scanner methodsFor:'reading next token'!
  1907 !Scanner methodsFor:'reading next token'!
  1878 
       
  1879 invalidCharacter:ch
       
  1880     |errMsg v|
       
  1881 
       
  1882     v := ch codePoint.
       
  1883     ch isPrintable ifTrue:[
       
  1884         errMsg := 'Scanner - invalid character: ''' , ch asString , ''' ', '(' , (v radixPrintStringRadix:16) , ').'.
       
  1885     ] ifFalse:[
       
  1886         errMsg := 'Scanner - invalid character: ' , (v radixPrintStringRadix:16) , '.'.
       
  1887     ].
       
  1888     v > 16r7F ifTrue:[
       
  1889         errMsg := errMsg , '\\Notice: only 7-bit ascii allowed (for compatibility).' withCRs.
       
  1890     ].
       
  1891     self syntaxError:errMsg position:tokenPosition to:tokenPosition.
       
  1892     source next.
       
  1893     tokenName := token := nil.
       
  1894     tokenType := #Error.
       
  1895     ^ #Error
       
  1896 !
       
  1897 
  1908 
  1898 nextCharacter
  1909 nextCharacter
  1899     "a $ has been read - return a character token"
  1910     "a $ has been read - return a character token"
  1900 
  1911 
  1901     |nextChar t|
  1912     |nextChar t|
  2661     tokenValue := token := string copyTo:(index - 1).
  2672     tokenValue := token := string copyTo:(index - 1).
  2662     tokenType := #String.
  2673     tokenType := #String.
  2663     ^ tokenType
  2674     ^ tokenType
  2664 
  2675 
  2665     "Created: / 01-08-2006 / 14:56:07 / cg"
  2676     "Created: / 01-08-2006 / 14:56:07 / cg"
       
  2677     "Modified: / 22-08-2006 / 14:10:26 / cg"
  2666 !
  2678 !
  2667 
  2679 
  2668 nextSymbolAfterHash
  2680 nextSymbolAfterHash
  2669     "helper: a # has been read - return #Symbol token or nil"
  2681     "helper: a # has been read - return #Symbol token or nil"
  2670 
  2682 
  3080 ! !
  3092 ! !
  3081 
  3093 
  3082 !Scanner class methodsFor:'documentation'!
  3094 !Scanner class methodsFor:'documentation'!
  3083 
  3095 
  3084 version
  3096 version
  3085     ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.221 2006-08-01 14:34:40 cg Exp $'
  3097     ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.222 2006-08-22 12:42:47 cg Exp $'
  3086 ! !
  3098 ! !
  3087 
  3099 
  3088 Scanner initialize!
  3100 Scanner initialize!