[PATCH] stinst: Make RBScanner>>#scanNumber work for the ConcatenatedStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] stinst: Make RBScanner>>#scanNumber work for the ConcatenatedStream

Holger Freyther
From: Holger Hans Peter Freyther <[hidden email]>

The species of the ConcatenatedStream is Array so we will need to
convert the result of reading from the stream with >>#next: to a
String first before we can trim the separators.

2013-02-10  Holger Hans Peter Freyther  <[hidden email]>

        * RBParser.st: Change RBScanner>>#scanNumber to convert
        the result to a String.
        * RewriteTests.st: Add testcase for RBScanner>>#scanNumber.
        * package.xml: Add the new test to the testsuite.
---
 packages/stinst/parser/ChangeLog       |    7 +++++++
 packages/stinst/parser/RBParser.st     |    2 +-
 packages/stinst/parser/RewriteTests.st |   23 ++++++++++++++++++++++-
 packages/stinst/parser/package.xml     |    1 +
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
index 31a5b2e..c20da6c 100644
--- a/packages/stinst/parser/ChangeLog
+++ b/packages/stinst/parser/ChangeLog
@@ -1,3 +1,10 @@
+2013-02-10  Holger Hans Peter Freyther  <[hidden email]>
+
+ * RBParser.st: Change RBScanner>>#scanNumber to convert
+ the result to a String.
+ * RewriteTests.st: Add testcase for RBScanner>>#scanNumber.
+ * package.xml: Add the new test to the testsuite.
+
 2013-02-08  Holger Hans Peter Freyther  <[hidden email]>
 
  * RBFormatter.st: Use the RBToken>>#storeOn: for writing.
diff --git a/packages/stinst/parser/RBParser.st b/packages/stinst/parser/RBParser.st
index 6f2b1cb..258e039 100644
--- a/packages/stinst/parser/RBParser.st
+++ b/packages/stinst/parser/RBParser.st
@@ -1328,7 +1328,7 @@ Stream subclass: RBScanner [
 
         "Get the parsed source"
         stream position: tokenStart - 1.
-        string := (stream next: stop - start + 1) trimSeparators.
+        string := (stream next: stop - start + 1) asString trimSeparators.
         stream position: stop.
 
  ^RBNumberLiteralToken
diff --git a/packages/stinst/parser/RewriteTests.st b/packages/stinst/parser/RewriteTests.st
index 8964b07..47132e8 100644
--- a/packages/stinst/parser/RewriteTests.st
+++ b/packages/stinst/parser/RewriteTests.st
@@ -7,7 +7,7 @@
 
 "======================================================================
 |
-| Copyright (C) 2007 Free Software Foundation, Inc.
+| Copyright (C) 2007,2013 Free Software Foundation, Inc.
 | Written by Stephen Compall.
 |
 | This file is part of the GNU Smalltalk class library.
@@ -280,5 +280,26 @@ TestCase subclass: TestFormat [
     ]
 ]
 
+TestCase subclass: TestScanner [
+    <comment: 'Test aspects of the RBScanner'>
+
+    testScanner [
+        | scanner num |
+        scanner := RBScanner on: '3' readStream.
+        num := scanner next.
+        self assert: num value = 3.
+    ]
+
+    testScannerConcatStream [
+        | scanner num |
+        "This is different to >>#testScanner by using a different kind of stream with
+        a different species."
+
+        scanner := RBScanner on: (Kernel.ConcatenatedStream with: '3' readStream).
+        num := scanner next.
+        self assert: num value = 3.
+    ]
+]
+
 ]
 
diff --git a/packages/stinst/parser/package.xml b/packages/stinst/parser/package.xml
index 47c7fb6..f997197 100644
--- a/packages/stinst/parser/package.xml
+++ b/packages/stinst/parser/package.xml
@@ -29,6 +29,7 @@
    <namespace>STInST.Tests</namespace>
    <sunit>STInST.Tests.TestStandardRewrites</sunit>
    <sunit>STInST.Tests.TestFormat</sunit>
+   <sunit>STInST.Tests.TestScanner</sunit>
    <sunit>STInST.Tests.TestDefaultPoolResolution</sunit>
    <sunit>STInST.Tests.TestClassicPoolResolution</sunit>
    <filein>RewriteTests.st</filein>
--
1.7.10.4


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] stinst: Make RBScanner>>#scanNumber work for the ConcatenatedStream

Holger Freyther
On Sun, Feb 10, 2013 at 08:07:52PM +0100, Holger Hans Peter Freyther wrote:

> The species of the ConcatenatedStream is Array so we will need to
> convert the result of reading from the stream with >>#next: to a
> String first before we can trim the separators.

Hi,

the testcase is requiring the ConcatenatedStream to be fixed. I have
created a bug report earlier today with the command to reproduce the
issue. The other question is if the ConcatenatedStream should maybe
re-implement >>#species and return the species if all streams have the
species?

The previous stinst patch was against stable-3.2, this one is for master
and only master due the >>#scanNumber patch only being in master.

holger

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] stinst: Make RBScanner>>#scanNumber work for the ConcatenatedStream

Paolo Bonzini-2
In reply to this post by Holger Freyther
Il 10/02/2013 20:07, Holger Hans Peter Freyther ha scritto:
> From: Holger Hans Peter Freyther <[hidden email]>
>
> The species of the ConcatenatedStream is Array so we will need to
> convert the result of reading from the stream with >>#next: to a
> String first before we can trim the separators.

Should the species came from the current stream instead?

Paolo

> 2013-02-10  Holger Hans Peter Freyther  <[hidden email]>
>
> * RBParser.st: Change RBScanner>>#scanNumber to convert
> the result to a String.
> * RewriteTests.st: Add testcase for RBScanner>>#scanNumber.
> * package.xml: Add the new test to the testsuite.
> ---
>  packages/stinst/parser/ChangeLog       |    7 +++++++
>  packages/stinst/parser/RBParser.st     |    2 +-
>  packages/stinst/parser/RewriteTests.st |   23 ++++++++++++++++++++++-
>  packages/stinst/parser/package.xml     |    1 +
>  4 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
> index 31a5b2e..c20da6c 100644
> --- a/packages/stinst/parser/ChangeLog
> +++ b/packages/stinst/parser/ChangeLog
> @@ -1,3 +1,10 @@
> +2013-02-10  Holger Hans Peter Freyther  <[hidden email]>
> +
> + * RBParser.st: Change RBScanner>>#scanNumber to convert
> + the result to a String.
> + * RewriteTests.st: Add testcase for RBScanner>>#scanNumber.
> + * package.xml: Add the new test to the testsuite.
> +
>  2013-02-08  Holger Hans Peter Freyther  <[hidden email]>
>  
>   * RBFormatter.st: Use the RBToken>>#storeOn: for writing.
> diff --git a/packages/stinst/parser/RBParser.st b/packages/stinst/parser/RBParser.st
> index 6f2b1cb..258e039 100644
> --- a/packages/stinst/parser/RBParser.st
> +++ b/packages/stinst/parser/RBParser.st
> @@ -1328,7 +1328,7 @@ Stream subclass: RBScanner [
>  
>          "Get the parsed source"
>          stream position: tokenStart - 1.
> -        string := (stream next: stop - start + 1) trimSeparators.
> +        string := (stream next: stop - start + 1) asString trimSeparators.
>          stream position: stop.
>  
>   ^RBNumberLiteralToken
> diff --git a/packages/stinst/parser/RewriteTests.st b/packages/stinst/parser/RewriteTests.st
> index 8964b07..47132e8 100644
> --- a/packages/stinst/parser/RewriteTests.st
> +++ b/packages/stinst/parser/RewriteTests.st
> @@ -7,7 +7,7 @@
>  
>  "======================================================================
>  |
> -| Copyright (C) 2007 Free Software Foundation, Inc.
> +| Copyright (C) 2007,2013 Free Software Foundation, Inc.
>  | Written by Stephen Compall.
>  |
>  | This file is part of the GNU Smalltalk class library.
> @@ -280,5 +280,26 @@ TestCase subclass: TestFormat [
>      ]
>  ]
>  
> +TestCase subclass: TestScanner [
> +    <comment: 'Test aspects of the RBScanner'>
> +
> +    testScanner [
> +        | scanner num |
> +        scanner := RBScanner on: '3' readStream.
> +        num := scanner next.
> +        self assert: num value = 3.
> +    ]
> +
> +    testScannerConcatStream [
> +        | scanner num |
> +        "This is different to >>#testScanner by using a different kind of stream with
> +        a different species."
> +
> +        scanner := RBScanner on: (Kernel.ConcatenatedStream with: '3' readStream).
> +        num := scanner next.
> +        self assert: num value = 3.
> +    ]
> +]
> +
>  ]
>  
> diff --git a/packages/stinst/parser/package.xml b/packages/stinst/parser/package.xml
> index 47c7fb6..f997197 100644
> --- a/packages/stinst/parser/package.xml
> +++ b/packages/stinst/parser/package.xml
> @@ -29,6 +29,7 @@
>     <namespace>STInST.Tests</namespace>
>     <sunit>STInST.Tests.TestStandardRewrites</sunit>
>     <sunit>STInST.Tests.TestFormat</sunit>
> +   <sunit>STInST.Tests.TestScanner</sunit>
>     <sunit>STInST.Tests.TestDefaultPoolResolution</sunit>
>     <sunit>STInST.Tests.TestClassicPoolResolution</sunit>
>     <filein>RewriteTests.st</filein>
>


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] stinst: Make RBScanner>>#scanNumber work for the ConcatenatedStream

Holger Freyther
On Sun, Feb 10, 2013 at 09:46:51PM +0100, Paolo Bonzini wrote:
>
> Should the species came from the current stream instead?

I'm not sure about the best practises. Would it ever make sense
to mix the species? For the gst-convert case.. everything will
be a FileStream. I wonder if we should just return the species
of the first stream? I am still happy to have found an issue
in the >>#next: implementation of the concatenated stream.


holger



_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] stinst: Make RBScanner>>#scanNumber work for the ConcatenatedStream

Paolo Bonzini-2
Il 11/02/2013 00:14, Holger Hans Peter Freyther ha scritto:
>> > Should the species came from the current stream instead?
> I'm not sure about the best practises. Would it ever make sense
> to mix the species? For the gst-convert case.. everything will
> be a FileStream. I wonder if we should just return the species
> of the first stream? I am still happy to have found an issue
> in the >>#next: implementation of the concatenated stream.

I think returning the species of the current stream is okay.  For
example #copyFrom:to: only works within one stream.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk