Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13769-Image-hangs-when-copying-a-text-from-Transcript #13840

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion src/NumberParser/NumberParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ Class {
'scale',
'nDigits',
'lastNonZero',
'failBlock'
'failBlock',
'maxExponent'
],
#classVars : [
'MaxExponent'
],
#category : #'NumberParser-Base'
}
Expand All @@ -41,6 +45,18 @@ NumberParser class >> isNumber: aStringOrStream [
^ stream atEnd
]

{ #category : #accessing }
NumberParser class >> maxExponent [

^ MaxExponent ifNil: [ MaxExponent := 10000 ]
]

{ #category : #accessing }
NumberParser class >> maxExponent: aValue [

MaxExponent := aValue
]

{ #category : #'instance creation' }
NumberParser class >> on: aStringOrStream [
^self new on: aStringOrStream
Expand All @@ -61,6 +77,19 @@ NumberParser class >> parse: aStringOrStream onError: failBlock [
nextNumber
]

{ #category : #accessing }
NumberParser class >> settingsOn: aBuilder [

<systemsettings>

(aBuilder setting: #maxExponent)
parent: #compiler;
default: 10000;
label: 'Max Exponent when parsing numbers';
description: 'This is the max exponent to parse when parsing numbers in the shape of 1e22. It is the absolute value';
target: self
]

{ #category : #'instance creation' }
NumberParser class >> squeezeNumberOutOfString: stringOrStream [
"Try and find a number in this string. First, look if the string
Expand Down Expand Up @@ -181,6 +210,18 @@ NumberParser >> makeScaledDecimalWithNumberOfNonZeroFractionDigits: numberOfNonZ
^decimalFraction asScaledDecimal: scale
]

{ #category : #accessing }
NumberParser >> maxExponent [

^ maxExponent ifNil: [ self class maxExponent ]
]

{ #category : #accessing }
NumberParser >> maxExponent: aValue [

maxExponent := aValue
]

{ #category : #'private - parsing - large int' }
NumberParser >> nextElementaryLargeIntegerBase: aRadix [
"Form an unsigned integer with incoming digits from sourceStream.
Expand Down Expand Up @@ -462,12 +503,21 @@ NumberParser >> readExponent [
epos := eneg not
and: [ self allowPlusSignInExponent and: [ sourceStream peekFor: $+ ] ].
exponent := self nextUnsignedIntegerOrNilBase: 10.

exponent
ifNil: [
"Oops, there was no digit after the exponent letter.Ungobble the letter"
exponent := 0.
sourceStream skip: ((eneg or: [ epos ]) ifTrue: [ -2 ] ifFalse: [ -1 ]).
^ false ].

"If the exponent is bigger than our max exponent, we return an error".
exponent > self maxExponent
ifTrue: [
self expected: 'Exponent is larger than ' , self maxExponent printString , ' (Check Settings)'.
exponent := 0.
^ false ].

eneg ifTrue: [ exponent := exponent negated ].
^ true
]
Expand Down