Fix in TokenStream - correctly report CARET, EOF when there are no more tokens after cursor.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 15 May 2014 17:58:25 +0100
changeset 228 87ee1ba0e13f
parent 227 ff9860ceaa07
child 229 c82a22d2153d
Fix in TokenStream - correctly report CARET, EOF when there are no more tokens after cursor.
SmallSense__TokenStream.st
--- a/SmallSense__TokenStream.st	Mon May 19 17:02:57 2014 +0100
+++ b/SmallSense__TokenStream.st	Thu May 15 17:58:25 2014 +0100
@@ -4,7 +4,7 @@
 
 Object subclass:#TokenStream
 	instanceVariableNames:'scanner scannerSourceReadLimit tokens last position full
-		positionMax positionOfCursor'
+		positionMax positionOfCursor caretTokenReported'
 	classVariableNames:'BacklogSize'
 	poolDictionaries:''
 	category:'SmallSense-Utils-Matcher'
@@ -94,6 +94,7 @@
     full := false.
     position := 0.
     positionMax := 0.
+    caretTokenReported := false.
 
     positionOfCursor notNil ifTrue:[ 
         scannerArg sourceStream isExternalStream ifTrue:[ 
@@ -104,7 +105,7 @@
     ].
 
     "Created: / 15-05-2014 / 15:07:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 15-05-2014 / 16:07:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-05-2014 / 17:55:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !TokenStream methodsFor:'stream api'!
@@ -116,6 +117,16 @@
     "Modified: / 07-08-2013 / 01:49:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+contents
+    ^ Array streamContents:[ :s | 
+        [ self atEnd ] whileFalse:[ 
+            s nextPut: self next
+        ].
+    ].
+
+    "Created: / 15-05-2014 / 07:49:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 next
     | i t |
     position < positionMax ifTrue:[
@@ -143,10 +154,12 @@
                 yourself
     ].
     t type == #EOF ifTrue:[ 
-        scanner sourceStream position == positionOfCursor ifTrue:[ 
+        (caretTokenReported not and:[scanner sourceStream position == positionOfCursor]) ifTrue:[ 
             t type: #CARET.
+            t value: $|.
             t startPosition: positionOfCursor.
             t endPosition: positionOfCursor.
+            caretTokenReported := true.
             scanner sourceStream readLimit: scannerSourceReadLimit.
         ].
     ].
@@ -160,7 +173,7 @@
     ^ t
 
     "Created: / 14-03-2012 / 22:53:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 15-05-2014 / 16:24:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 15-05-2014 / 17:56:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 next: anInteger 
@@ -276,5 +289,12 @@
     "Modified: / 06-05-2014 / 15:33:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!TokenStream class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+
 
 TokenStream initialize!