GDBParser.st
changeset 27 e7e01078d9c4
parent 25 58e042a191a9
child 32 d9c96b33afd6
--- a/GDBParser.st	Tue Jun 24 09:23:18 2014 +0100
+++ b/GDBParser.st	Tue Jun 24 23:42:44 2014 +0100
@@ -184,6 +184,16 @@
     "Modified: / 31-05-2014 / 00:38:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+parseNonBlankSequence
+    ^ String streamContents:[ :buffer | 
+        [ self peek isNil or: [ self peek isSeparator ] ] whileFalse:[
+            buffer nextPut: self next.
+        ]
+    ]
+
+    "Created: / 24-06-2014 / 23:19:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 parseOutput
     "
     output → ( out-of-band-record )* [ result-record ] '(gdb)' nl
@@ -375,6 +385,58 @@
     "Modified: / 19-06-2014 / 21:43:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GDBParser methodsFor:'parsing-commands'!
+
+parseCommand
+
+    self peek isDigit ifTrue:[ 
+        self parseToken
+    ].
+
+    ^ self peek == $- ifTrue:[ 
+        self parseCommandMI
+    ] ifFalse:[ 
+        self parseCommandCLI
+    ].
+
+    "Created: / 24-06-2014 / 23:08:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseCommandCLI
+    "raise an error: this method should be implemented (TODO)"
+
+    ^ GDBCLICommand new
+        token: token;
+        value: self nextLine;
+        yourself
+
+    "Created: / 24-06-2014 / 23:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseCommandMI
+    "raise an error: this method should be implemented (TODO)"
+
+    | operation className class args |
+
+    self next. "/ eat $-.
+    operation := self parseVariable.
+    className := ('GDBMI_' , (operation copyReplaceAll: $- with: $_)) asSymbol.
+    class := Smalltalk at: className.
+    args := OrderedCollection new.
+    [ self peek isNil or:[ self peek == Character cr ] ] whileFalse:[  
+        self skipSeparators.
+        self peek == $" ifTrue:[ 
+            args add: self parseCString
+        ] ifFalse:[ 
+            args add: self parseNonBlankSequence
+        ].
+    ].
+    self next. "/ eat CR.
+    ^ class arguments: args asArray.
+
+    "Created: / 24-06-2014 / 23:10:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBParser methodsFor:'parsing-misc'!
 
 parseResult
@@ -395,13 +457,13 @@
 
 parseString
     ^ String streamContents:[:s|
-        [ self peek isLetterOrDigit or:['-_' includes: self peek ] ]  whileTrue:[
+        [ self peek notNil and:[self peek isLetterOrDigit or:['-_' includes: self peek ] ] ] whileTrue:[
             s nextPut: self next.
         ]
     ].
 
     "Created: / 30-05-2014 / 10:32:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 20-06-2014 / 09:20:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-06-2014 / 23:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseVariable
@@ -734,15 +796,18 @@
 
 nextLine
     | line |
+
+    line := lookahead notNil 
+                ifTrue:[ lookahead asString ,  source nextLine ] 
+                ifFalse:[ source nextLine ].
     lookahead := nil.
-    line := source nextLine.
     recorder notNil ifTrue:[ 
         recorder recordResponse: line.  
     ].
     ^ line
 
     "Created: / 23-10-2012 / 11:05:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-06-2014 / 21:56:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-06-2014 / 23:28:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 peek
@@ -770,10 +835,9 @@
 !
 
 skipSeparators
-    lookahead := nil.
-    source skipSeparators
+    [ self peek notNil and:[ self peek isSeparator ] ] whileTrue:[ self next ]
 
     "Created: / 19-11-2012 / 20:05:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 28-05-2014 / 00:21:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-06-2014 / 23:31:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !