[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] [PATCH 07/15] stinst: Fix parsing of negated number
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] [PATCH 07/15] stinst: Fix parsing of negated numbers with the new RBNumberLiteralToken |
Date: |
Sun, 14 Apr 2013 15:42:08 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 |
Il 08/04/2013 11:30, Holger Hans Peter Freyther ha scritto:
> From: Holger Hans Peter Freyther <address@hidden>
>
> 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 <address@hidden>
> +
> + * RBParser.st: Fix RBParser>>#parsedNegatedNumber.
> + * RBToken.st: Add RBNumberLiteralToken>>#makeNegative.
> + * RewriteTests.st: Add testcase for RBParser>>#parseNegatedNumber.
> +
> 2013-02-17 Holger Hans Peter Freyther <address@hidden>
>
> * 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 [
>
Ok.
Paolo
- [Help-smalltalk] [PATCH 08/15] stinst: Avoid running into recursion in ProxyNamespace, (continued)
- [Help-smalltalk] [PATCH 08/15] stinst: Avoid running into recursion in ProxyNamespace, Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 06/15] stinst: Fix the sourcecode extraction in RBScanner>>#scanNumber, Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 04/15] kernel: Remove unused variable from the StarPackage class, Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 02/15] misc: Fix compiler warnings in libgst., Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 07/15] stinst: Fix parsing of negated numbers with the new RBNumberLiteralToken, Holger Hans Peter Freyther, 2013/04/08
- Re: [Help-smalltalk] [PATCH 07/15] stinst: Fix parsing of negated numbers with the new RBNumberLiteralToken,
Paolo Bonzini <=
- [Help-smalltalk] [PATCH 05/15] kernel: Introduce the DirPackage packages to help with development, Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 10/15] gtktools: Move GtkListModel from VisualGST to GTKTools, Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 09/15] gtktools: Introduce a GTKTools package with helper classes, Holger Hans Peter Freyther, 2013/04/08
- [Help-smalltalk] [PATCH 15/15] tooling: Introduce a helper for a Monticello export, Holger Hans Peter Freyther, 2013/04/08