compiler/PPCCompilationOptions.st
changeset 538 16e8536f5cfb
parent 535 a8feb0f47574
--- a/compiler/PPCCompilationOptions.st	Mon Sep 07 08:20:46 2015 +0100
+++ b/compiler/PPCCompilationOptions.st	Mon Sep 07 11:53:38 2015 +0100
@@ -9,16 +9,27 @@
 	category:'PetitCompiler-Core'
 !
 
-!PPCCompilationOptions class methodsFor:'as yet unclassified'!
+!PPCCompilationOptions class methodsFor:'instance creation'!
+
+from: aCollection
+    "Initialized options from an array containing option: value pairs.
+     Example:
 
-default
-    ^ self new
+         PPCCompilationOptions from: { #tokenize: true }
+    "
+    ^ self new initializeFrom: aCollection
+
+    "
+        PPCCompilationOptions from: #( tokenize: true )
+    "
+
+    "Created: / 07-09-2015 / 10:25:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 new
-    ^ self basicNew 
-        initialize;
-        yourself
+    "return an initialized instance"
+
+    ^ self basicNew initialize.
 ! !
 
 !PPCCompilationOptions methodsFor:'initialization'!
@@ -26,6 +37,26 @@
 initialize
     super initialize.
     options := IdentityDictionary new
+!
+
+initializeFrom: aSequenceableCollection
+    aSequenceableCollection size even ifFalse:[ 
+        self error: 'Invalid options'
+    ].
+    1 to: aSequenceableCollection size by: 2 do:[:i |  
+        | option value |
+
+        option := aSequenceableCollection at: i.
+        value  := aSequenceableCollection at: i + 1.
+
+        [ 
+            self perform: option asSymbol with: value
+        ] on: MessageNotUnderstood do:[:ex |    
+            self error: 'Invalid option: ', option storeString.
+        ]
+    ].
+
+    "Created: / 07-09-2015 / 10:36:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PPCCompilationOptions methodsFor:'options'!