From: Holger Hans Peter Freyther <[email protected]> Negative numbers are not directly parsed in the RBScanner>>#scanNumber but are made negative from within the RBParser>>#parseNegatedNumber. This was done to help to differentiate a binary selector from the number. Add a testcase for the formatting, make the number negative inside the number literal token and prepend the $- to the source.
The start/stop of the token has been wrong before this commit and is still wrong. This needs to be fixed in the future. --- packages/stinst/parser/ChangeLog | 6 ++++++ packages/stinst/parser/RBParser.st | 2 +- packages/stinst/parser/RBToken.st | 9 +++++++++ packages/stinst/parser/RewriteTests.st | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog index 94dab52..24bf131 100644 --- a/packages/stinst/parser/ChangeLog +++ b/packages/stinst/parser/ChangeLog @@ -1,3 +1,9 @@ +2013-02-23 Holger Hans Peter Freyther <[email protected]> + + * RBParser.st: Fix RBParser>>#parsedNegatedNumber. + * RBToken.st: Add RBNumberLiteralToken>>#makeNegative. + * RewriteTests.st: Add testcase for RBParser>>#parseNegatedNumber. + 2013-02-17 Holger Hans Peter Freyther <[email protected]> * RBParser.st: Fix RBScanner>>#scanNumber. diff --git a/packages/stinst/parser/RBParser.st b/packages/stinst/parser/RBParser.st index 7be57d6..1877e6b 100644 --- a/packages/stinst/parser/RBParser.st +++ b/packages/stinst/parser/RBParser.st @@ -544,7 +544,7 @@ Object subclass: RBParser [ ^self parserError: 'Number expected' ]. token value negative ifTrue: [ ^self parserError: 'Positive number expected' ]. - token value: token value negated. + token makeNegative. self step. ^RBLiteralNode literalToken: token ] diff --git a/packages/stinst/parser/RBToken.st b/packages/stinst/parser/RBToken.st index e77252d..399a6db 100644 --- a/packages/stinst/parser/RBToken.st +++ b/packages/stinst/parser/RBToken.st @@ -297,6 +297,15 @@ RBLiteralToken subclass: RBNumberLiteralToken [ source: aSource; yourself ] + makeNegative [ + <category: 'creation'> + "Help with RBParser>>#parseNegatedNumber to make the value and the + code match. The token start and stop is still wrong." + self + value: value negated; + source: '-', self source. + ] + source: aSource [ <category: 'creation'> source := aSource diff --git a/packages/stinst/parser/RewriteTests.st b/packages/stinst/parser/RewriteTests.st index d38b69b..a7005f9 100644 --- a/packages/stinst/parser/RewriteTests.st +++ b/packages/stinst/parser/RewriteTests.st @@ -312,6 +312,23 @@ TestCase subclass: TestFormat [ assert: inp value = 2.0; assert: inp formattedCode = '20q-1'. ] + + testNegativeNumbers [ + | inp | + inp := RBParser parseExpression: '-3'. + self assert: inp value = -3. + self assert: inp token source = '-3'. + self assert: inp formattedCode = '-3'. + ] + + testNumberExpressionParsing [ + | inp | + inp := RBParser parseExpression: '2-2'. + self + assert: inp receiver value = 2; + assert: inp selector = #-; + assert: inp arguments first value = 2. + ] ] TestCase subclass: TestScanner [ -- 1.7.10.4 _______________________________________________ help-smalltalk mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-smalltalk
