GDBMIParser.st
changeset 73 f5fe22f56f10
parent 57 f27c9f059a08
child 79 303c4edc75ad
--- a/GDBMIParser.st	Wed Mar 18 14:19:37 2015 +0000
+++ b/GDBMIParser.st	Thu Mar 19 08:25:30 2015 +0000
@@ -343,23 +343,38 @@
             descriptor := command resultDescription.        
         ].
     ].
-    [ self peek == $, ] whileTrue:[
-        self next. "/ eat $,
-        propertyName := self parseVariable.
-        propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
-        self expect: $=.
-        propertyDescriptor isNil ifTrue:[ 
-            propertyValue := self parseValue.
-        ] ifFalse:[ 
-            propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
-        ]. 
-        result propertyAt: propertyName put: propertyValue.
-     ].             
+
+    descriptor klass isNil ifTrue:[ 
+        "/ Command result is not an object but list of properties...
+        [ self peek == $, ] whileTrue:[
+            self next. "/ eat $,
+            propertyName := self parseVariable.
+            propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
+            self expect: $=.
+            propertyDescriptor isNil ifTrue:[ 
+                propertyValue := self parseValue.
+            ] ifFalse:[ 
+                propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
+            ]. 
+            result propertyAt: propertyName put: propertyValue.
+         ].             
+    ] ifFalse:[ 
+        "/ Command result forms an object.
+        "/ Create an object and parse property list as its properties.
+        | object |
+
+        object := descriptor klass new.
+        self peek == $, ifTrue:[
+            self next. "/ eat first , following command status...
+            self parsePropertiesFor: object describedBy: descriptor.
+        ].
+        result propertyAt: #value put: object.
+    ].
     self parseNl.
     ^ GDBCommandResultEvent new result: result.
 
     "Created: / 30-05-2014 / 09:52:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 23-09-2014 / 23:37:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2015 / 08:16:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseToken
@@ -698,6 +713,27 @@
 
 !GDBMIParser methodsFor:'parsing-values-typed'!
 
+parsePropertiesFor: object describedBy: descriptor
+    | propertyName propertyValue propertyDescriptor |
+
+    [ 
+        propertyName := self parseVariable.
+        propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
+        self expect: $=.
+        propertyDescriptor isNil ifTrue:[ 
+            propertyValue := self parseValue.
+        ] ifFalse:[ 
+            propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
+        ].
+        object propertyAt: propertyName put: propertyValue
+    ] doWhile: [ 
+        (self peek == $,) ifTrue:[ self next. true ] ifFalse:[ false ]
+    ].
+    ^ object
+
+    "Created: / 19-03-2015 / 07:52:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 parseValueAsBoolean
     "
     bool → 'y' | 'n' | value
@@ -745,31 +781,19 @@
 !
 
 parseValueAsInstanceOf: class describedBy: descriptor
-    | object propertyName propertyValue propertyDescriptor |
+    | object |
 
     self peek ~~ ${ ifTrue:[ ^ self parseValue ].
-    self next. "/ eat ${
+    self next. "/ eat {
     object := class new.
     self peek ~~ $} ifTrue:[
-        [ 
-            propertyName := self parseVariable.
-            propertyDescriptor := descriptor propertyDescriptorAt: propertyName.
-            self expect: $=.
-            propertyDescriptor isNil ifTrue:[ 
-                propertyValue := self parseValue.
-            ] ifFalse:[ 
-                propertyValue := propertyDescriptor parseUsingGDBMIParser:self. 
-            ].
-            object propertyAt: propertyName put: propertyValue
-        ] doWhile: [ 
-            (self peek == $,) ifTrue:[ self next. true ] ifFalse:[ false ]
-        ].
+        self parsePropertiesFor: object describedBy: descriptor
     ].
     self expect: $}.
     ^ object
 
     "Created: / 18-06-2014 / 20:28:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 18-06-2014 / 23:34:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 19-03-2015 / 07:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseValueAsInteger