s/BenchmarkRunner.st
changeset 204 97b7cdaeb0e8
parent 190 ab1b88f52b93
child 205 63a0130d7951
--- a/s/BenchmarkRunner.st	Fri Feb 28 17:12:59 2014 +0000
+++ b/s/BenchmarkRunner.st	Sat Mar 08 16:02:47 2014 +0000
@@ -79,11 +79,7 @@
                 argumentsF exists ifFalse:[
                     self error:'no such file: ', arguments.
                 ].
-                argumentsF readingFileDo:[:s|
-                    [ s atEnd ] whileFalse:[
-                        argv add: s nextLine.
-                    ]
-                ].
+                argumentsF readingFileDo:[:f | self parseArguments: f into: argv ].
                 i := i + 1.
             ].  
                          
@@ -189,7 +185,7 @@
             write: result on: BenchmarkPlatform current stdout
     ].
 
-    "Modified: / 19-09-2013 / 22:44:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 11:00:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 options
@@ -201,7 +197,7 @@
   -o FILE ................ write output to FILE instead of to standard output (default: stdout)
   -n RUNS ................ how many times to run each bechmark (default: 5)
   -r REPORTCLASS ......... user REPORTCLASS to generate report (default: BenchmarkReportText)
-  --arguments FILE ....... read additional arguments from FOLE, one argument per line.
+  --arguments FILE ....... read additional arguments from FILE
   --text ................. generate text report (equivalent to -r BenchmarkReportText)
   --json ................. generate JSON report (equivalent to -r BenchmarkReportJSON)
   --tag TAG .............. tag for the current benchmark set (default: "default")
@@ -217,7 +213,108 @@
 '
 
     "Created: / 06-06-2013 / 11:01:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-09-2013 / 23:29:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 10:49:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!BenchmarkRunner methodsFor:'private-parsing'!
+
+parseArgument:stream 
+    | c |
+
+    [
+        c := stream peek.
+        c == $#
+    ] whileTrue:[
+        self parseComment:stream.
+        stream skipSeparators.
+        stream atEnd ifTrue:[ ^ nil ].
+    ].
+    c == $\ ifTrue:[
+        stream next.
+        [
+            stream peek == Character space or:[ stream peek == Character tab ]
+        ] whileTrue:[ stream next. ].
+        stream peek == Character cr ifTrue:[
+            stream skipSeparators.
+            ^ self parseArgument:stream.
+        ] ifFalse:[ ^ '\' ].
+    ].
+    c == $" ifTrue:[
+        ^ self parseQuoted1:stream
+    ].
+    c == $' ifTrue:[
+        ^ self parseQuoted2:stream
+    ].
+    ^ self parseToken:stream
+
+    "Created: / 08-03-2014 / 11:01:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 15:59:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseArguments: stream into: argv
+    [ stream skipSeparators. stream atEnd ] whileFalse:[
+        | arg |
+
+        arg := (self parseArgument: stream).
+        arg notNil ifTrue:[ argv add: arg ]
+    ].
+
+    "Created: / 08-03-2014 / 10:59:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 15:59:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseComment: stream 
+    stream nextLine.
+
+    "Created: / 08-03-2014 / 11:18:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseQuoted1:stream
+    "Parse string quoted by $" 
+    stream next. "/ eat $"
+    ^ String streamContents:[:s|
+        [ stream peek == $"] whileFalse:[ 
+            stream peek == $\ ifTrue:[ 
+                stream next.
+            ].
+            stream atEnd ifTrue:[ 
+                self error:'Unterminated string'.
+            ].
+            s nextPut: stream next.
+        ].
+        stream next "/ eat $"
+    ].
+
+    "Created: / 08-03-2014 / 11:18:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 15:44:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseQuoted2:stream
+    "Parse string quoted by $'" 
+    stream next. "/ eat $'
+    ^ String streamContents:[:s|
+        [ stream peek == $'] whileFalse:[ 
+            stream atEnd ifTrue:[ 
+                self error:'Unterminated string'.
+            ].
+            s nextPut: stream next.
+        ].
+        stream next. "/ eat $'       
+    ].
+
+    "Created: / 08-03-2014 / 11:18:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 15:44:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+parseToken: stream
+    ^ String streamContents:[:s|
+        [ stream atEnd or:[stream peek isSeparator] ] whileFalse:[ 
+            s nextPut: stream next.
+        ].
+    ].
+
+    "Created: / 08-03-2014 / 11:18:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-03-2014 / 15:36:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !BenchmarkRunner class methodsFor:'documentation'!