# HG changeset patch # User Claus Gittinger # Date 1444148749 -7200 # Node ID 498b1d7e697ef2463f269d1d3b99eba63ab61865 # Parent 8271065cb89ac09069f53874fb910de0240b8555 #UI_ENHANCEMENT class: ResourcePack changed: #readFromResourceStream:in: more walkback in case of errors diff -r 8271065cb89a -r 498b1d7e697e ResourcePack.st --- a/ResourcePack.st Tue Oct 06 17:44:06 2015 +0200 +++ b/ResourcePack.st Tue Oct 06 18:25:49 2015 +0200 @@ -1386,17 +1386,17 @@ printError fileName pushedSkipValues| fileName := (inStream isFileStream - ifTrue:[inStream pathName asFilename baseName] - ifFalse:['---']). + ifTrue:[inStream pathName asFilename baseName] + ifFalse:['---']). printError := [:message | - 'ResourcePack [warning]: ' errorPrint. - message errorPrint. - ' in file:' errorPrint. - fileName errorPrint. - ' line: ' errorPrint. - lineNumber errorPrintCR - ]. + 'ResourcePack [warning]: ' errorPrint. + message errorPrint. + ' in file:' errorPrint. + fileName errorPrint. + ' line: ' errorPrint. + lineNumber errorPrintCR + ]. printError := [:message | ]. @@ -1409,136 +1409,140 @@ pushedSkipValues := OrderedCollection new. errorHandler := [:ex | - |con| + |con| - Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". - Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR". - con := ex suspendedContext. - Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". - con := con sender. - Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". - con := con sender. - Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". - value := nil. - ok := false. - ]. + Transcript showCR:('ResourcePack [warning]: ''' , ex description , '''') "errorPrintCR". + Transcript showCR:('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') "errorPrintCR". + con := ex suspendedContext. + Transcript showCR:('ResourcePack [info]: in: ' , con fullPrintString) "errorPrintCR". + con := con sender. + Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". + 20 timesRepeat:[ + con notNil ifTrue:[ + con := con sender. + Transcript showCR:('ResourcePack [info]: : ' , con fullPrintString) "errorPrintCR". + ]. + ]. + value := nil. + ok := false. + ]. [inStream atEnd] whileFalse:[ - lineString := inStream nextLine. lineNumber := lineNumber + 1. - [lineString notNil and:[lineString endsWith:$\]] whileTrue:[ - lineString := lineString copyButLast:1. - l := inStream nextLine. lineNumber := lineNumber + 1. - l notNil ifTrue:[ - lineString := lineString , l. - ]. - ]. + lineString := inStream nextLine. lineNumber := lineNumber + 1. + [lineString notNil and:[lineString endsWith:$\]] whileTrue:[ + lineString := lineString copyButLast:1. + l := inStream nextLine. lineNumber := lineNumber + 1. + l notNil ifTrue:[ + lineString := lineString , l. + ]. + ]. - (lineString size > 0) ifTrue:[ - first := lineString at:1. - "/ - "/ for your convenience: treat both ';' AND '"/' as comment-line - "/ - ((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ - ((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ - "/ a directive - lineString := (lineString copyFrom:2) withoutSpaces. + (lineString size > 0) ifTrue:[ + first := lineString at:1. + "/ + "/ for your convenience: treat both ';' AND '"/' as comment-line + "/ + ((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ + ((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ + "/ a directive + lineString := (lineString copyFrom:2) withoutSpaces. - (lineString startsWith:'if') ifTrue:[ - pushedSkipValues add:skipping. - skipping ifFalse:[ - rest := lineString copyFrom:3. - Error, UserInformation - handle:errorHandler - do:[ - value := Compiler evaluate:rest compile:false. - ]. - (value == #Error) ifTrue:[ - printError value:('error in resource:' , lineString). - ]. - (value == false) ifTrue:[ - skipping := true - ] - ]. - ifLevel := ifLevel + 1 - ] ifFalse:[ - (lineString startsWith:'endif') ifTrue:[ - ifLevel == 0 ifTrue:[ - printError value:('if/endif nesting error'). - ] ifFalse:[ - ifLevel := ifLevel - 1. - skipping := pushedSkipValues removeLast. - ] - ] ifFalse:[ - (lineString startsWith:'else') ifTrue:[ - (pushedSkipValues includes:true) ifFalse:[ - skipping := skipping not - ] - ] ifFalse:[ - skipping ifFalse:[ - (lineString startsWith:'superpack') ifTrue:[ - rest := lineString copyFrom:('superpack' size + 1). - value := Compiler evaluate:rest compile:false. - (value isKindOf:ResourcePack) ifTrue:[ - superPack := value - ] - ] ifFalse:[ - (lineString startsWith:'include') ifTrue:[ - (lineString startsWith:'includeResourcesFor') ifTrue:[ - "/ include those resources ... - rest := lineString copyFrom:('includeResourcesFor' size + 1). - value := Compiler evaluate:rest compile:false. - value isBehavior ifTrue:[ - pack := self class for:value. - pack notNil ifTrue:[ - self addAll:pack. - ] - ] - ] ifFalse:[ - rest := lineString copyFrom:('include' size + 1). - value := Compiler evaluate:rest compile:false. - value isString ifFalse:[ - printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). - ] ifTrue:[ - self readFromFile:value directory:dirName - ] - ] - ] ifFalse:[ - (lineString startsWith:'encoding') ifTrue:[ + (lineString startsWith:'if') ifTrue:[ + pushedSkipValues add:skipping. + skipping ifFalse:[ + rest := lineString copyFrom:3. + Error, UserInformation + handle:errorHandler + do:[ + value := Compiler evaluate:rest compile:false. + ]. + (value == #Error) ifTrue:[ + printError value:('error in resource:' , lineString). + ]. + (value == false) ifTrue:[ + skipping := true + ] + ]. + ifLevel := ifLevel + 1 + ] ifFalse:[ + (lineString startsWith:'endif') ifTrue:[ + ifLevel == 0 ifTrue:[ + printError value:('if/endif nesting error'). + ] ifFalse:[ + ifLevel := ifLevel - 1. + skipping := pushedSkipValues removeLast. + ] + ] ifFalse:[ + (lineString startsWith:'else') ifTrue:[ + (pushedSkipValues includes:true) ifFalse:[ + skipping := skipping not + ] + ] ifFalse:[ + skipping ifFalse:[ + (lineString startsWith:'superpack') ifTrue:[ + rest := lineString copyFrom:('superpack' size + 1). + value := Compiler evaluate:rest compile:false. + (value isKindOf:ResourcePack) ifTrue:[ + superPack := value + ] + ] ifFalse:[ + (lineString startsWith:'include') ifTrue:[ + (lineString startsWith:'includeResourcesFor') ifTrue:[ + "/ include those resources ... + rest := lineString copyFrom:('includeResourcesFor' size + 1). + value := Compiler evaluate:rest compile:false. + value isBehavior ifTrue:[ + pack := self class for:value. + pack notNil ifTrue:[ + self addAll:pack. + ] + ] + ] ifFalse:[ + rest := lineString copyFrom:('include' size + 1). + value := Compiler evaluate:rest compile:false. + value isString ifFalse:[ + printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). + ] ifTrue:[ + self readFromFile:value directory:dirName + ] + ] + ] ifFalse:[ + (lineString startsWith:'encoding') ifTrue:[ "/decoder notNil ifTrue:[self halt:'oops - encoding change in file']. - encoding := self class extractEncodingFromLine:lineString. - decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. - ] - ] - ] - ] - ] - ] - ]. - ] ifFalse:[ - skipping ifFalse:[ - Error, UserInformation - handle:errorHandler - do:[ - (lineString at:1) == $!! ifTrue:[ - "/ evaluate the rest - Compiler evaluate:(lineString copyFrom:2) - receiver:self - notifying:nil - compile:false. - ] ifFalse:[ - "/ process as resource - self - processLine:lineString - encoding:decoder - file:(inStream isFileStream - ifTrue:[inStream pathName] - ifFalse:['---']) - printErrorWith:printError - ]] - ] - ] - ] - ] + encoding := self class extractEncodingFromLine:lineString. + decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. + ] + ] + ] + ] + ] + ] + ]. + ] ifFalse:[ + skipping ifFalse:[ + Error, UserInformation + handle:errorHandler + do:[ + (lineString at:1) == $!! ifTrue:[ + "/ evaluate the rest + Compiler evaluate:(lineString copyFrom:2) + receiver:self + notifying:nil + compile:false. + ] ifFalse:[ + "/ process as resource + self + processLine:lineString + encoding:decoder + file:(inStream isFileStream + ifTrue:[inStream pathName] + ifFalse:['---']) + printErrorWith:printError + ]] + ] + ] + ] + ] ]. ^ ok