'From Squeak3.2alpha of 7 October 2001 [latest update: #4567] on 6 January 2002 at 3:08:27 pm'! "Change Set: SyntaxErrorNotification Date: 6 January 2002 Author: Leandro Caniglia This change set adds the exception SyntaxErrorNotification so that syntax errors can be handled under the exception framework. Simple TestCase included "! Notification subclass: #SyntaxErrorNotification instanceVariableNames: 'inClass code doitFlag debugger ' classVariableNames: '' poolDictionaries: '' category: 'System-Exceptions Extensions'! TestCase subclass: #SyntaxErrorNotificationTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'System-Exceptions Tests'! !SyntaxErrorNotificationTest commentStamp: 'LC 1/6/2002 15:03' prior: 0! TestRunner open! !Compiler methodsFor: 'error handling' stamp: 'LC 1/6/2002 13:53'! notify: aString at: location "Refer to the comment in Object|notify:." requestor == nil ifTrue: [^SyntaxErrorNotification inClass: class withCode: (sourceStream contents copyReplaceFrom: location to: location - 1 with: aString) doitFlag: false] ifFalse: [^requestor notify: aString at: location in: sourceStream]! ! !Parser methodsFor: 'error handling' stamp: 'LC 1/6/2002 14:30'! notify: string at: location requestor isNil ifTrue: [(encoder == self or: [encoder isNil]) ifTrue: [^ self fail "failure setting up syntax error"]. SyntaxErrorNotification inClass: encoder classEncoding withCode: (source contents copyReplaceFrom: location to: location - 1 with: string , ' ->') doitFlag: doitFlag] ifFalse: [requestor notify: string , ' ->' at: location in: source]. ^self fail! ! !SyntaxErrorNotification methodsFor: 'accessing' stamp: 'LC 1/6/2002 13:50'! messageText ^ super messageText ifNil: [messageText _ self syntaxError contents]! ! !SyntaxErrorNotification methodsFor: 'accessing' stamp: 'LC 1/6/2002 13:44'! setClass: aClass code: codeString debugger: aDebugger doitFlag: aBoolean inClass _ aClass. code _ codeString. debugger _ aDebugger. doitFlag _ aBoolean ! ! !SyntaxErrorNotification methodsFor: 'accessing' stamp: 'LC 1/6/2002 13:45'! syntaxError ^ SyntaxError new setClass: inClass code: code debugger: debugger doitFlag: doitFlag! ! !SyntaxErrorNotification methodsFor: 'exceptionDescription' stamp: 'LC 1/6/2002 13:47'! defaultAction | s | s _ self syntaxError. ^ s class open: s ! ! !SyntaxErrorNotification class methodsFor: 'exceptionInstantiator' stamp: 'LC 1/6/2002 13:52'! inClass: aClass withCode: codeString doitFlag: doitFlag ^ (self new setClass: aClass code: codeString debugger: (Debugger context: thisContext) doitFlag: doitFlag) signal! ! !SyntaxErrorNotificationTest methodsFor: 'running' stamp: 'LC 1/6/2002 15:05'! testCompiling | block | block _ [Compiler new parse: '[2 + ]' in: nil class notifying: nil]. block on: SyntaxErrorNotification do: [:ex | ^ self assert: ex class == SyntaxErrorNotification]. self assert: false ! ! !SyntaxErrorNotificationTest methodsFor: 'running' stamp: 'LC 1/6/2002 15:02'! testParsing | block | block _ [Parser new parse: '[2 + ]' readStream class: nil class noPattern: true context: nil notifying: nil ifFail: []]. block on: SyntaxErrorNotification do: [:ex | ^ self assert: ex class == SyntaxErrorNotification]. self assert: false ! ! !SyntaxErrorNotification reorganize! ('accessing' messageText setClass:code:debugger:doitFlag: syntaxError) ('exceptionDescription' defaultAction) !