Parser.st
changeset 4498 1a3bc6bdbfab
parent 4486 d239b024e8bf
child 4515 f5b6e8b93331
--- a/Parser.st	Mon Aug 19 16:21:27 2019 +0200
+++ b/Parser.st	Tue Aug 20 15:34:47 2019 +0200
@@ -5570,7 +5570,6 @@
     selector := aParser selector.
 ! !
 
-
 !Parser methodsFor:'obsolete'!
 
 correctByDeleting
@@ -6867,11 +6866,23 @@
 
 arrayIndexingExpression
     "parse an array index expression; this is a squeak/stx extension.
-     foo[x] is syntactic sugar for 'foo at:x'
-     and foo[x] := expr is syntactic sugar for 'foo at:x put:expr';
-     with commas, foo[x , y] generates foo at:x at:y.
-     This syntax extension must be enabled in the parserFlags as
-     allowArrayIndexSyntaxExtension (disabled by default)"
+        foo[x] is syntactic sugar for 'foo at:x'
+     and 
+        foo[x] := expr is syntactic sugar for 'foo at:x put:expr'
+     With multiple dimensions, 
+        foo[x . y] or foo[x][y] generates foo at:x at:y
+     and
+        foo[x . y] := expr or foo[x][y] := expr generates foo at:x at:y put:expr.
+
+     This syntax extension must be enabled 
+     in the parserFlags as allowArrayIndexSyntaxExtension 
+     or via a pragma <pargma: +ArrayIndexSyntaxExtension>
+     (disabled by default).
+
+     This general form of the synthetic selector is: _at:idx1 at:idx2 ...
+     or _at:idx1 at:idx2 put:expr.
+     Notice that the getters are also implemented in the SeqColl meta class, 
+     as instance creators for Vectors, Matrices etc."
 
     |receiver argList selectorStream valNode|
 
@@ -6896,7 +6907,9 @@
             argList isEmpty ifTrue:[selectorStream nextPutAll:'_'].
             selectorStream nextPutAll:'at:'.
             argList add: indexNode.
-            (tokenType == #BinaryOperator ) and:[ token = ',']
+            "/ rubbish: cannot use comma here
+            "/ (tokenType == #BinaryOperator ) and:[ token = ',']
+            (tokenType == $. )
         ] whileTrue.
 
         tokenType == $] ifFalse:[
@@ -6905,13 +6918,14 @@
         ].
         self nextToken.
 
-        tokenType == $[ ifTrue:[
-            receiver := MessageNode
-                    receiver:receiver
-                    selector:(selectorStream contents)
-                    args:argList.
-            selectorStream := WriteStream on: (String new: 32).
-        ].
+"/        tokenType == $[ ifTrue:[
+"/            receiver := MessageNode
+"/                    receiver:receiver
+"/                    selector:(selectorStream contents)
+"/                    args:argList.
+"/            selectorStream := WriteStream on: (String new: 32).
+"/            argList := OrderedCollection new.
+"/        ].
         tokenType == $[
     ] whileTrue.
 
@@ -6944,18 +6958,64 @@
     "
 
     "
+     <pragma: +ArrayIndexSyntaxExtension>
      |foo|
 
      foo := Array new:10 withAll:2.
-     1 + foo[1].
-    "
-    "
+     1 + foo[1]. 
+    "
+
+    "
+     <pragma: +ArrayIndexSyntaxExtension>
+     |foo|
+
+     foo := Array new:10.
+     foo[1] := 'hello'.
+     foo[2]. 
+     foo[1].     
+    "
+
+    "
+     <pragma: +ArrayIndexSyntaxExtension>
      |foo|
 
      foo := Array new:10.
      foo[1] := 'hello'.
-     foo[2].
+     foo[1][2].     
+    "
+    "
+     <pragma: +ArrayIndexSyntaxExtension>
+     |foo|
+
+     foo := Array new:10.
+     foo[1] := 'hello' copy.
+     foo[1][2] := $E.
      foo[1].
+     foo[1][2].  
+    "
+    "
+     <pragma: +ArrayIndexSyntaxExtension>
+     |foo|
+
+     foo := Array new:10.
+     foo[1] := 'hello' copy.
+     foo[1 . 2] := $E.
+     foo[1].  
+     foo[1][2].  
+     foo[1 . 2].  
+    "
+    "
+     <pragma: +ArrayIndexSyntaxExtension>
+     |m|
+
+     m := Array[2][3].
+     m[1][1] := 11.
+     m[1][2] := 12.
+     m[1][3] := 13.
+     m[2][1] := 21.
+     m[2][2] := 22.
+     m[2][3] := 23.
+     m.
     "
 
     "Modified: / 08-08-2017 / 16:56:33 / cg"
@@ -10101,7 +10161,7 @@
         ^  self
     ].
 
-    self parseError:'+/- expected'.
+    self parseError:'"+/-"<flagName> expected'.
     ^ self
 
     "Modified: / 09-06-2019 / 15:06:45 / Claus Gittinger"