Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.395.mcz ==================== Summary ==================== Name: Kernel-nice.395 Author: nice Time: 13 February 2010, 2:29:51.4 am UUID: 1f313115-2fff-1a4c-93f1-d6bbfecb3ad5 Ancestors: Kernel-nice.394 Arrange for ExtendedNumberParser to return the valid leading number instead of failing because of invalid radix Example: '1r' -> 1 '2r3' -> 2 =============== Diff against Kernel-nice.394 =============== Item was changed: ----- Method: ExtendedNumberParser>>nextNumber (in category 'parsing-public') ----- nextNumber "main method for reading a number. This one can read Float Integer and ScaledDecimal" | numberOfTrailingZeroInIntegerPart | base := 10. neg := self peekSignIsMinus. integerPart := self nextUnsignedIntegerOrNilBase: base. integerPart ifNil: [(sourceStream peekFor: $.) ifTrue: [ "Try .1 syntax" ^self readNumberWithoutIntegerPart] ifFalse: [ "This is not a regular number beginning with a digit It is time to check for exceptional condition NaN and Infinity" ^self readNamedFloatOrFail]]. numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero. (sourceStream peekFor: $r) ifTrue: ["<base>r<integer>" + | oldNeg pos | + pos := sourceStream position. (base := integerPart) < 2 + ifTrue: ["A radix currently need to be greater than 1, ungobble the r and return the integer part" + sourceStream skip: -1. + ^neg + ifTrue: [base negated] + ifFalse: [base]]. + oldNeg := neg. + self peekSignIsMinus ifTrue: [neg := neg not]. - ifTrue: [^ self expected: 'an integer greater than 1 as valid radix']. - (self peekSignIsMinus) - ifTrue: [neg := neg not]. integerPart := self nextUnsignedIntegerOrNilBase: base. integerPart ifNil: [ + (sourceStream peekFor: $.) ifTrue: [self readNumberWithoutIntegerPartOrNil ifNotNil: [:aNumber | ^aNumber]]. + sourceStream position: pos. + ^oldNeg + ifTrue: [base negated] + ifFalse: [base]]. - (sourceStream peekFor: $.) ifTrue: [^self readNumberWithoutIntegerPart]. - ^self expected: ('a digit between 0 and ' copyWith: (Character digitValue: base - 1))]. numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero]. ^ (sourceStream peekFor: $.) ifTrue: [self readNumberWithFractionPartNumberOfTrailingZeroInIntegerPart: numberOfTrailingZeroInIntegerPart] ifFalse: [self makeIntegerOrScaledInteger]! Item was added: + ----- Method: ExtendedNumberParser>>readNumberWithoutIntegerPartOrNil (in category 'parsing-private') ----- + readNumberWithoutIntegerPartOrNil + "at this stage, sign followed by a decimal point have been read, but no intergerPart + try and form a number with a fractionPart" + + | numberOfNonZeroFractionDigits numberOfTrailingZeroInFractionPart mantissa value | + integerPart := 0. + fractionPart := self nextUnsignedIntegerOrNilBase: base. + fractionPart ifNil: [ + "No integer part, no fractionPart, this does not look like a number..." + ^nil]. + numberOfNonZeroFractionDigits := lastNonZero. + numberOfTrailingZeroInFractionPart := nDigits - lastNonZero. + self readExponent + ifFalse: [self readScale + ifTrue: [^self makeScaledDecimalWithNumberOfNonZeroFractionDigits: numberOfNonZeroFractionDigits + andNumberOfTrailingZeroInFractionPart: numberOfTrailingZeroInFractionPart]]. + + fractionPart isZero + ifTrue: [mantissa := 0] + ifFalse: [mantissa := (fractionPart // (base raisedToInteger: numberOfTrailingZeroInFractionPart)). + exponent := exponent - numberOfNonZeroFractionDigits]. + + value := self makeFloatFromMantissa: mantissa exponent: exponent base: base. + ^ neg + ifTrue: [value isZero + ifTrue: [Float negativeZero] + ifFalse: [value negated]] + ifFalse: [value]! Item was changed: ----- Method: ExtendedNumberParser>>readNumberWithoutIntegerPart (in category 'parsing-private') ----- readNumberWithoutIntegerPart "at this stage, sign followed by a decimal point have been read, but no intergerPart try and form a number with a fractionPart" + ^self readNumberWithoutIntegerPartOrNil ifNil: [ - | numberOfNonZeroFractionDigits numberOfTrailingZeroInFractionPart mantissa value | - integerPart := 0. - fractionPart := self nextUnsignedIntegerOrNilBase: base. - fractionPart ifNil: [ "No integer part, no fractionPart, this does not look like a number..." + ^self expected: 'a digit between 0 and 9'].! - ^self expected: 'a digit between 0 and 9']. - numberOfNonZeroFractionDigits := lastNonZero. - numberOfTrailingZeroInFractionPart := nDigits - lastNonZero. - self readExponent - ifFalse: [self readScale - ifTrue: [^self makeScaledDecimalWithNumberOfNonZeroFractionDigits: numberOfNonZeroFractionDigits - andNumberOfTrailingZeroInFractionPart: numberOfTrailingZeroInFractionPart]]. - - fractionPart isZero - ifTrue: [mantissa := 0] - ifFalse: [mantissa := (fractionPart // (base raisedToInteger: numberOfTrailingZeroInFractionPart)). - exponent := exponent - numberOfNonZeroFractionDigits]. - - value := self makeFloatFromMantissa: mantissa exponent: exponent base: base. - ^ neg - ifTrue: [value isZero - ifTrue: [Float negativeZero] - ifFalse: [value negated]] - ifFalse: [value]! |
Free forum by Nabble | Edit this page |