Index: /ruby/trunk/adl_parser/lib/parser.rb
===================================================================
--- /ruby/trunk/adl_parser/lib/parser.rb	(revision 21)
+++ /ruby/trunk/adl_parser/lib/parser.rb	(revision 22)
@@ -27,5 +27,11 @@
     class Parser < Racc::Parser
 
-module_eval <<'..end lib/parser.y modeval..id0eaae3c06b', 'lib/parser.y', 758
+module_eval <<'..end lib/parser.y modeval..idc7c14292e8', 'lib/parser.y', 1010
+
+def assert_at(file,line, message = "")
+  unless yield
+    raise "Assertion failed !: #{file}, #{line}: #{message}"
+  end
+end
 
 @@log = Logger.new('log/parser.log','daily')
@@ -814,5 +820,5 @@
 
 
-..end lib/parser.y modeval..id0eaae3c06b
+..end lib/parser.y modeval..idc7c14292e8
 
 ##### racc 1.4.5 generates ###
@@ -853,13 +859,13 @@
  2, 115, :_reduce_32,
  1, 114, :_reduce_none,
- 1, 114, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
- 1, 120, :_reduce_none,
+ 1, 114, :_reduce_34,
+ 1, 120, :_reduce_35,
+ 1, 120, :_reduce_36,
+ 1, 120, :_reduce_37,
+ 1, 120, :_reduce_38,
+ 1, 120, :_reduce_39,
+ 1, 120, :_reduce_40,
+ 1, 120, :_reduce_41,
+ 1, 120, :_reduce_42,
  1, 120, :_reduce_none,
  1, 120, :_reduce_none,
@@ -872,24 +878,24 @@
  3, 132, :_reduce_none,
  2, 132, :_reduce_none,
- 1, 127, :_reduce_none,
+ 1, 127, :_reduce_53,
  1, 133, :_reduce_54,
- 1, 133, :_reduce_none,
- 1, 133, :_reduce_none,
- 1, 133, :_reduce_none,
- 1, 133, :_reduce_none,
- 1, 133, :_reduce_none,
- 1, 133, :_reduce_none,
- 1, 133, :_reduce_none,
+ 1, 133, :_reduce_55,
+ 1, 133, :_reduce_56,
+ 1, 133, :_reduce_57,
+ 1, 133, :_reduce_58,
+ 1, 133, :_reduce_59,
+ 1, 133, :_reduce_60,
+ 1, 133, :_reduce_61,
  1, 118, :_reduce_none,
- 1, 119, :_reduce_none,
- 2, 119, :_reduce_none,
- 5, 142, :_reduce_none,
- 5, 142, :_reduce_none,
- 5, 142, :_reduce_none,
+ 1, 119, :_reduce_63,
+ 2, 119, :_reduce_64,
+ 5, 142, :_reduce_65,
+ 5, 142, :_reduce_66,
+ 5, 142, :_reduce_67,
  2, 143, :_reduce_68,
  3, 143, :_reduce_69,
- 1, 144, :_reduce_none,
- 2, 144, :_reduce_none,
- 1, 144, :_reduce_none,
+ 1, 144, :_reduce_70,
+ 2, 144, :_reduce_71,
+ 1, 144, :_reduce_72,
  0, 130, :_reduce_none,
  2, 130, :_reduce_none,
@@ -904,5 +910,5 @@
  2, 103, :_reduce_none,
  2, 103, :_reduce_none,
- 2, 104, :_reduce_none,
+ 2, 104, :_reduce_85,
  2, 104, :_reduce_none,
  1, 109, :_reduce_none,
@@ -915,11 +921,11 @@
  1, 155, :_reduce_94,
  2, 155, :_reduce_none,
- 1, 156, :_reduce_none,
- 1, 156, :_reduce_none,
- 1, 153, :_reduce_none,
- 1, 153, :_reduce_none,
- 1, 159, :_reduce_none,
- 2, 159, :_reduce_none,
- 3, 160, :_reduce_none,
+ 1, 156, :_reduce_96,
+ 1, 156, :_reduce_97,
+ 1, 153, :_reduce_98,
+ 1, 153, :_reduce_99,
+ 1, 159, :_reduce_100,
+ 2, 159, :_reduce_101,
+ 3, 160, :_reduce_102,
  1, 161, :_reduce_103,
  1, 162, :_reduce_none,
@@ -929,15 +935,15 @@
  1, 158, :_reduce_none,
  2, 158, :_reduce_none,
- 2, 166, :_reduce_none,
- 3, 166, :_reduce_none,
+ 2, 166, :_reduce_110,
+ 3, 166, :_reduce_111,
  1, 167, :_reduce_none,
- 1, 157, :_reduce_none,
- 2, 157, :_reduce_none,
+ 1, 157, :_reduce_113,
+ 2, 157, :_reduce_114,
  3, 168, :_reduce_115,
- 1, 169, :_reduce_none,
- 1, 169, :_reduce_none,
- 1, 169, :_reduce_none,
- 1, 169, :_reduce_none,
- 1, 169, :_reduce_none,
+ 1, 169, :_reduce_116,
+ 1, 169, :_reduce_117,
+ 1, 169, :_reduce_118,
+ 1, 169, :_reduce_119,
+ 1, 169, :_reduce_120,
  1, 165, :_reduce_121,
  1, 165, :_reduce_122,
@@ -971,7 +977,7 @@
  3, 184, :_reduce_none,
  3, 184, :_reduce_none,
- 1, 175, :_reduce_none,
- 2, 175, :_reduce_none,
- 2, 175, :_reduce_none,
+ 1, 175, :_reduce_152,
+ 2, 175, :_reduce_153,
+ 2, 175, :_reduce_154,
  3, 185, :_reduce_none,
  3, 185, :_reduce_none,
@@ -1109,9 +1115,9 @@
  2, 206, :_reduce_288,
  1, 206, :_reduce_289,
- 0, 145, :_reduce_none,
- 5, 145, :_reduce_none,
- 1, 207, :_reduce_none,
- 3, 207, :_reduce_none,
- 5, 146, :_reduce_none,
+ 0, 145, :_reduce_290,
+ 5, 145, :_reduce_291,
+ 1, 207, :_reduce_292,
+ 3, 207, :_reduce_293,
+ 5, 146, :_reduce_294,
  1, 208, :_reduce_none,
  3, 208, :_reduce_none,
@@ -1172,11 +1178,11 @@
  3, 140, :_reduce_none,
  3, 140, :_reduce_none,
- 1, 219, :_reduce_none,
- 1, 219, :_reduce_none,
- 3, 219, :_reduce_none,
- 3, 219, :_reduce_none,
- 1, 141, :_reduce_none,
- 3, 141, :_reduce_none,
- 3, 141, :_reduce_none,
+ 1, 219, :_reduce_353,
+ 1, 219, :_reduce_354,
+ 3, 219, :_reduce_355,
+ 3, 219, :_reduce_356,
+ 1, 141, :_reduce_357,
+ 3, 141, :_reduce_358,
+ 3, 141, :_reduce_359,
  1, 126, :_reduce_none,
  3, 126, :_reduce_none,
@@ -2023,9 +2029,14 @@
  # reduce 2 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 41
+module_eval <<'.,.,', 'lib/parser.y', 46
   def _reduce_3( val, _values, result )
+    assert_at(__FILE__,__LINE__) do
+      val[4].instance_of?(OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION) and val[5].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT) and val[7].instance_of?(OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY) 
+    end
+    
     result = OpenEHR::AM::Archetype::ARCHETYPE.new(
                                                    :description => val[4],
-                                                   :definition => val[5]
+                                                   :definition => val[5],
+                                                   :ontology => val[7]
                                                    )
    result
@@ -2063,5 +2074,5 @@
  # reduce 18 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 76
+module_eval <<'.,.,', 'lib/parser.y', 81
   def _reduce_19( val, _values, result )
     result = {:language => val[1]}
@@ -2074,5 +2085,5 @@
  # reduce 21 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 87
+module_eval <<'.,.,', 'lib/parser.y', 92
   def _reduce_22( val, _values, result )
     result = OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION.new(:details => val[1])
@@ -2083,5 +2094,5 @@
  # reduce 23 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 95
+module_eval <<'.,.,', 'lib/parser.y', 100
   def _reduce_24( val, _values, result )
     result = val[1]
@@ -2092,6 +2103,8 @@
  # reduce 25 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 103
+module_eval <<'.,.,', 'lib/parser.y', 110
   def _reduce_26( val, _values, result )
+    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT)}
+                      
     result = val[0]
    result
@@ -2101,5 +2114,5 @@
  # reduce 27 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 111
+module_eval <<'.,.,', 'lib/parser.y', 118
   def _reduce_28( val, _values, result )
     result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
@@ -2108,7 +2121,10 @@
 .,.,
 
-module_eval <<'.,.,', 'lib/parser.y', 115
+module_eval <<'.,.,', 'lib/parser.y', 125
   def _reduce_29( val, _values, result )
-    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(
+                                                                            :assumed_value => val[0],
+                                                                            :attributes => val[2]
+                                                                            )
    result
   end
@@ -2117,12 +2133,12 @@
  # reduce 30 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 124
+module_eval <<'.,.,', 'lib/parser.y', 134
   def _reduce_31( val, _values, result )
-    result = {:c_complex_object_id => {:type_identifier => val[0]}}
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 128
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 138
   def _reduce_32( val, _values, result )
     result = {:c_complex_object_id => {:type_identifier => val[0], :V_LOCAL_TERM_CODE_REF => val[1]}}
@@ -2133,21 +2149,66 @@
  # reduce 33 omitted
 
- # reduce 34 omitted
-
- # reduce 35 omitted
-
- # reduce 36 omitted
-
- # reduce 37 omitted
-
- # reduce 38 omitted
-
- # reduce 39 omitted
-
- # reduce 40 omitted
-
- # reduce 41 omitted
-
- # reduce 42 omitted
+module_eval <<'.,.,', 'lib/parser.y', 144
+  def _reduce_34( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(:attributes => val[0])
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 152
+  def _reduce_35( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 156
+  def _reduce_36( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 160
+  def _reduce_37( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 164
+  def _reduce_38( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 168
+  def _reduce_39( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 172
+  def _reduce_40( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 176
+  def _reduce_41( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 180
+  def _reduce_42( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
 
  # reduce 43 omitted
@@ -2171,59 +2232,163 @@
  # reduce 52 omitted
 
- # reduce 53 omitted
-
-module_eval <<'.,.,', 'lib/parser.y', 177
+module_eval <<'.,.,', 'lib/parser.y', 212
+  def _reduce_53( val, _values, result )
+    assert_at(__FILE__,__LINE__){val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE)}
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_PRIMITIVE_OBJECT.new(:item => val[0])
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 218
   def _reduce_54( val, _values, result )
-    @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}")
-    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_Integer.new
-   result
-  end
-.,.,
-
- # reduce 55 omitted
-
- # reduce 56 omitted
-
- # reduce 57 omitted
-
- # reduce 58 omitted
-
- # reduce 59 omitted
-
- # reduce 60 omitted
-
- # reduce 61 omitted
+    @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 223
+  def _reduce_55( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_REAL.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 228
+  def _reduce_56( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 233
+  def _reduce_57( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_TIME.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 238
+  def _reduce_58( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE_TIME.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 243
+  def _reduce_59( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DURATION.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 248
+  def _reduce_60( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING.new
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 254
+  def _reduce_61( val, _values, result )
+    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN)}
+    @@log.info("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+   result
+  end
+.,.,
 
  # reduce 62 omitted
 
- # reduce 63 omitted
-
- # reduce 64 omitted
-
- # reduce 65 omitted
-
- # reduce 66 omitted
-
- # reduce 67 omitted
-
-module_eval <<'.,.,', 'lib/parser.y', 203
+module_eval <<'.,.,', 'lib/parser.y', 264
+  def _reduce_63( val, _values, result )
+    result = [val[0]]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 268
+  def _reduce_64( val, _values, result )
+    result = (val[0] << val[1])
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 277
+  def _reduce_65( val, _values, result )
+    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
+    c_attribute = val[0]
+    c_attribute.children = val[3]
+    result = c_attribute
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 282
+  def _reduce_66( val, _values, result )
+    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 287
+  def _reduce_67( val, _values, result )
+    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 298
   def _reduce_68( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 207
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_SINGLE_ATTRIBUTE.new(
+                                                                              :rm_attribute_name => val[0],
+                                                                              :existence => val[1]
+                                                                              )
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 308
   def _reduce_69( val, _values, result )
-    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}")
-   result
-  end
-.,.,
-
- # reduce 70 omitted
-
- # reduce 71 omitted
-
- # reduce 72 omitted
+    assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY) }
+    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}") 
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_MULTIPLE_ATTRIBUTE.new(
+                                                                                :rm_attribute_name => val[0],
+                                                                                :existence => val[1],
+                                                                                :cardinality => val[2]
+                                                                                )
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 313
+  def _reduce_70( val, _values, result )
+    result = Array[val[0]]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 317
+  def _reduce_71( val, _values, result )
+    result = (val[0] << val[1])
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 321
+  def _reduce_72( val, _values, result )
+    result = Array[val[0]]
+   result
+  end
+.,.,
 
  # reduce 73 omitted
@@ -2251,5 +2416,10 @@
  # reduce 84 omitted
 
- # reduce 85 omitted
+module_eval <<'.,.,', 'lib/parser.y', 351
+  def _reduce_85( val, _values, result )
+    result = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
+   result
+  end
+.,.,
 
  # reduce 86 omitted
@@ -2267,5 +2437,5 @@
  # reduce 92 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 257
+module_eval <<'.,.,', 'lib/parser.y', 370
   def _reduce_93( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
@@ -2274,7 +2444,8 @@
 .,.,
 
-module_eval <<'.,.,', 'lib/parser.y', 262
+module_eval <<'.,.,', 'lib/parser.y', 376
   def _reduce_94( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
    result
   end
@@ -2283,21 +2454,57 @@
  # reduce 95 omitted
 
- # reduce 96 omitted
-
- # reduce 97 omitted
-
- # reduce 98 omitted
-
- # reduce 99 omitted
-
- # reduce 100 omitted
-
- # reduce 101 omitted
-
- # reduce 102 omitted
-
-module_eval <<'.,.,', 'lib/parser.y', 279
+module_eval <<'.,.,', 'lib/parser.y', 382
+  def _reduce_96( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 386
+  def _reduce_97( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 391
+  def _reduce_98( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 395
+  def _reduce_99( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 400
+  def _reduce_100( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 404
+  def _reduce_101( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 409
+  def _reduce_102( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 415
   def _reduce_103( val, _values, result )
     @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
    result
   end
@@ -2308,5 +2515,5 @@
  # reduce 105 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 287
+module_eval <<'.,.,', 'lib/parser.y', 423
   def _reduce_106( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
@@ -2315,7 +2522,8 @@
 .,.,
 
-module_eval <<'.,.,', 'lib/parser.y', 292
+module_eval <<'.,.,', 'lib/parser.y', 429
   def _reduce_107( val, _values, result )
     @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
+    result = val[1]
    result
   end
@@ -2326,97 +2534,157 @@
  # reduce 109 omitted
 
- # reduce 110 omitted
-
- # reduce 111 omitted
+module_eval <<'.,.,', 'lib/parser.y', 437
+  def _reduce_110( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 442
+  def _reduce_111( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]}, attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
+    result = val[0]
+   result
+  end
+.,.,
 
  # reduce 112 omitted
 
- # reduce 113 omitted
-
- # reduce 114 omitted
-
-module_eval <<'.,.,', 'lib/parser.y', 304
+module_eval <<'.,.,', 'lib/parser.y', 448
+  def _reduce_113( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 453
+  def _reduce_114( val, _values, result )
+    @@log.info("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 458
   def _reduce_115( val, _values, result )
-    @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[2]}> at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
- # reduce 116 omitted
-
- # reduce 117 omitted
-
- # reduce 118 omitted
-
- # reduce 119 omitted
-
- # reduce 120 omitted
-
-module_eval <<'.,.,', 'lib/parser.y', 313
+    @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
+    result = val[1]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 462
+  def _reduce_116( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 466
+  def _reduce_117( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 470
+  def _reduce_118( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 474
+  def _reduce_119( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 478
+  def _reduce_120( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 483
   def _reduce_121( val, _values, result )
     @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 317
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 488
   def _reduce_122( val, _values, result )
     @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 321
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 493
   def _reduce_123( val, _values, result )
     @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 325
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 498
   def _reduce_124( val, _values, result )
     @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 329
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 503
   def _reduce_125( val, _values, result )
     @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 333
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 508
   def _reduce_126( val, _values, result )
     @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 337
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 513
   def _reduce_127( val, _values, result )
     @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 341
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 518
   def _reduce_128( val, _values, result )
     @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 345
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 523
   def _reduce_129( val, _values, result )
     @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 349
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 528
   def _reduce_130( val, _values, result )
     @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
    result
   end
@@ -2453,21 +2721,24 @@
  # reduce 145 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 370
+module_eval <<'.,.,', 'lib/parser.y', 551
   def _reduce_146( val, _values, result )
     @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 374
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 556
   def _reduce_147( val, _values, result )
     @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
-   result
-  end
-.,.,
-
-module_eval <<'.,.,', 'lib/parser.y', 379
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 562
   def _reduce_148( val, _values, result )
     @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
    result
   end
@@ -2480,9 +2751,39 @@
  # reduce 151 omitted
 
- # reduce 152 omitted
-
- # reduce 153 omitted
-
- # reduce 154 omitted
+module_eval <<'.,.,', 'lib/parser.y', 576
+  def _reduce_152( val, _values, result )
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = integer
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 585
+  def _reduce_153( val, _values, result )
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = integer
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 594
+  def _reduce_154( val, _values, result )
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = - integer
+   result
+  end
+.,.,
 
  # reduce 155 omitted
@@ -2636,7 +2937,8 @@
  # reduce 229 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 490
+module_eval <<'.,.,', 'lib/parser.y', 698
   def _reduce_230( val, _values, result )
     @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
    result
   end
@@ -2667,5 +2969,5 @@
  # reduce 242 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 509
+module_eval <<'.,.,', 'lib/parser.y', 717
   def _reduce_243( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2680,5 +2982,5 @@
  # reduce 246 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 518
+module_eval <<'.,.,', 'lib/parser.y', 726
   def _reduce_247( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2767,5 +3069,5 @@
  # reduce 287 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 587
+module_eval <<'.,.,', 'lib/parser.y', 795
   def _reduce_288( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
@@ -2774,5 +3076,5 @@
 .,.,
 
-module_eval <<'.,.,', 'lib/parser.y', 591
+module_eval <<'.,.,', 'lib/parser.y', 799
   def _reduce_289( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
@@ -2781,13 +3083,49 @@
 .,.,
 
- # reduce 290 omitted
-
- # reduce 291 omitted
-
- # reduce 292 omitted
-
- # reduce 293 omitted
-
- # reduce 294 omitted
+module_eval <<'.,.,', 'lib/parser.y', 810
+  def _reduce_290( val, _values, result )
+    result = Range.new(1,1)
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 814
+  def _reduce_291( val, _values, result )
+    result = val[3]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 824
+  def _reduce_292( val, _values, result )
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = integer
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 834
+  def _reduce_293( val, _values, result )
+    begin
+      from_integer = Integer(val[0])
+      to_integer = Integer(val[2])
+    rescue
+      raise
+    end
+    result = Range.new(from_integer,to_integer)
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 839
+  def _reduce_294( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new
+   result
+  end
+.,.,
 
  # reduce 295 omitted
@@ -2907,17 +3245,52 @@
  # reduce 352 omitted
 
- # reduce 353 omitted
-
- # reduce 354 omitted
-
- # reduce 355 omitted
-
- # reduce 356 omitted
-
- # reduce 357 omitted
-
- # reduce 358 omitted
-
- # reduce 359 omitted
+module_eval <<'.,.,', 'lib/parser.y', 925
+  def _reduce_353( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true)
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 929
+  def _reduce_354( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false)
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 933
+  def _reduce_355( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 937
+  def _reduce_356( val, _values, result )
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 942
+  def _reduce_357( val, _values, result )
+    result = val[0]
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 946
+  def _reduce_358( val, _values, result )
+    raise 'Not implemented yet'
+   result
+  end
+.,.,
+
+module_eval <<'.,.,', 'lib/parser.y', 950
+  def _reduce_359( val, _values, result )
+    raise 'Not implemented yet'
+   result
+  end
+.,.,
 
  # reduce 360 omitted
@@ -2931,5 +3304,5 @@
  # reduce 364 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 711
+module_eval <<'.,.,', 'lib/parser.y', 963
   def _reduce_365( val, _values, result )
     @in_interval = false
@@ -2955,5 +3328,5 @@
  # reduce 373 omitted
 
-module_eval <<'.,.,', 'lib/parser.y', 733
+module_eval <<'.,.,', 'lib/parser.y', 985
   def _reduce_374( val, _values, result )
     @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
Index: /ruby/trunk/adl_parser/lib/parser.y
===================================================================
--- /ruby/trunk/adl_parser/lib/parser.y	(revision 21)
+++ /ruby/trunk/adl_parser/lib/parser.y	(revision 22)
@@ -35,7 +35,12 @@
 archetype: arch_identification arch_specialisation arch_concept arch_language arch_description arch_definition arch_invariant arch_ontology
   { 
+    assert_at(__FILE__,__LINE__) do
+      val[4].instance_of?(OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION) and val[5].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT) and val[7].instance_of?(OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY) 
+    end
+    
     result = OpenEHR::AM::Archetype::ARCHETYPE.new(
                                                    :description => val[4],
-                                                   :definition => val[5]
+                                                   :definition => val[5],
+                                                   :ontology => val[7]
                                                    )
   }
@@ -100,4 +105,6 @@
 cadl_section: c_complex_object
   { 
+    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT)}
+                      
     result = val[0]
   }
@@ -112,5 +119,8 @@
     | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK
   { 
-    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(
+                                                                            :assumed_value => val[0],
+                                                                            :attributes => val[2]
+                                                                            )
   }
 #    | c_complex_object_head error SYM_END_CBLOCK
@@ -121,5 +131,5 @@
 c_complex_object_id: type_identifier
   {
-    result = {:c_complex_object_id => {:type_identifier => val[0]}}
+    result = val[0]
   }
   | type_identifier V_LOCAL_TERM_CODE_REF
@@ -130,4 +140,7 @@
 c_complex_object_body: c_any #-- used to indicate that any value of a type is ok
   | c_attributes
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(:attributes => val[0])
+  }
 
 
@@ -135,11 +148,35 @@
 
 c_object: v_c_domain_type
+  { 
+    result = val[0]
+  }
   | c_complex_object
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
+  }
   | archetype_internal_ref
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.new
+  }
   | archetype_slot
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.new
+  }
   | constraint_ref
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.new
+  }
   | c_code_phrase
+  { 
+    result = val[0]
+  }
   | c_ordinal
+  { 
+    result = val[0]
+  }
   | c_primitive_object
+  { 
+    result = val[0]
+  }
 #  | v_c_domain_type
 #  | V_C_DOMAIN_TYPE
@@ -170,17 +207,50 @@
 # 'c_primitive_object' is an node representing a constraint on a primitive object type.
 c_primitive_object: c_primitive
+  {
+    assert_at(__FILE__,__LINE__){val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE)}
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_PRIMITIVE_OBJECT.new(:item => val[0])
+  }
 
 c_primitive: c_integer
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}")
-    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_Integer.new
+    @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.new
   }
   | c_real
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_REAL.new
+  }
   | c_date
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE.new
+  }
   | c_time
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_TIME.new
+  }
   | c_date_time
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE_TIME.new
+  }
   | c_duration
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DURATION.new
+  }
   | c_string
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING.new
+  }
   | c_boolean
+  {
+    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN)}
+    @@log.info("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+  }
 
 c_any: Star_code
@@ -190,10 +260,30 @@
 
 c_attributes: c_attribute
+  { 
+    result = [val[0]]
+  }
   | c_attributes c_attribute
+  { 
+    result = (val[0] << val[1])
+  }
 
 # 'c_attribute' is a node representing a constraint on an attribute in an object model.
 c_attribute: c_attr_head SYM_MATCHES SYM_START_CBLOCK c_attr_values SYM_END_CBLOCK
+  { 
+    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
+    c_attribute = val[0]
+    c_attribute.children = val[3]
+    result = c_attribute
+  }
   | c_attr_head SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
+  { 
+    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
+    result = val[0]
+  }
   | c_attr_head SYM_MATCHES SYM_START_CBLOCK error SYM_END_CBLOCK
+  { 
+    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
+    result = val[0]
+  }
 
 
@@ -201,13 +291,33 @@
   {
     @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_SINGLE_ATTRIBUTE.new(
+                                                                              :rm_attribute_name => val[0],
+                                                                              :existence => val[1]
+                                                                              )
+
   }
   | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality
   {
+    assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY) }
     @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}") 
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_MULTIPLE_ATTRIBUTE.new(
+                                                                                :rm_attribute_name => val[0],
+                                                                                :existence => val[1],
+                                                                                :cardinality => val[2]
+                                                                                )
   }
 
 c_attr_values: c_object
+  { 
+    result = Array[val[0]]
+  }
   | c_attr_values c_object
+  { 
+    result = (val[0] << val[1])
+  }
   | c_any #	-- to allow a property to have any value
+  { 
+    result = Array[val[0]]
+  }
 
 ### c_includes: #-- Empty
@@ -237,4 +347,7 @@
 
 arch_ontology: SYM_ONTOLOGY dadl_section
+  { 
+    result = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
+  }
   | SYM_ONTOLOGY error
 
@@ -260,21 +373,44 @@
   {
     @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | V_ATTRIBUTE_IDENTIFIER error
 
 object_block: complex_object_block
+  { 
+    result = val[0]
+  }
   | primitive_object_block
+  { 
+    result = val[0]
+  }
 
 complex_object_block: single_attr_object_block
+  { 
+    result = val[0]
+  }
   | multiple_attr_object_block
+  { 
+    result = val[0]
+  }
 
 multiple_attr_object_block: untyped_multiple_attr_object_block
+  { 
+    result = val[0]
+  }
   | type_identifier untyped_multiple_attr_object_block
+  { 
+    result = val[0]
+  }
 
 untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK
+  { 
+    result = val[0]
+  }
 
 multiple_attr_object_block_head: SYM_START_DBLOCK
-  {
+  { 
     @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -290,4 +426,5 @@
   {
     @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
+    result = val[1]
   }
 
@@ -295,57 +432,100 @@
   | type_identifier untyped_single_attr_object_block
 untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # <>
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+  }
   | single_attr_object_complex_head attr_vals SYM_END_DBLOCK
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]}, attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
+    result = val[0]
+  }
 single_attr_object_complex_head: SYM_START_DBLOCK
 primitive_object_block: untyped_primitive_object_block
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+  }
   | type_identifier untyped_primitive_object_block
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
+    result = val[0]
+  }
 untyped_primitive_object_block: SYM_START_DBLOCK primitive_object_value SYM_END_DBLOCK
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[2]}> at #{@filename}:#{@lineno}")
+    @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
+    result = val[1]
   }
 primitive_object_value: simple_value
+  {
+    result = val[0]
+  }
   | simple_list_value
+  {
+    result = val[0]
+  }
   | simple_interval_value
+  {
+    result = val[0]
+  }
   | term_code
+  {
+    result = val[0]
+  }
   | term_code_list_value
+  {
+    result = val[0]
+  }
 simple_value: string_value
   {
     @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | integer_value
   {
     @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | real_value
   {
     @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | boolean_value
   {
     @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | character_value
   {
     @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | date_value
   {
     @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | time_value
   {
     @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | date_time_value
   {
     @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | duration_value
   {
     @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | uri_value
   {
     @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
-  }
+    result = val[0]
+  }
+
 simple_list_value: string_list_value
   | integer_list_value
@@ -368,8 +548,10 @@
   {
     @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
   | V_GENERIC_TYPE_IDENTIFIER
   {
     @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -377,4 +559,5 @@
   {
     @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -384,6 +567,30 @@
 
 integer_value: V_INTEGER
+  { 
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = integer
+  }
   | Plus_code V_INTEGER
+  {
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = integer
+  }
   | Minus_code V_INTEGER
+  {
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = - integer
+  }
 ###   | '+' V_INTEGER
 ###   | '-' V_INTEGER
@@ -488,4 +695,5 @@
   {
     @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -598,10 +806,36 @@
 
 c_existence: #-- default to 1..1
-    | SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK
+    { 
+    result = Range.new(1,1)
+  }
+  | SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK
+  { 
+    result = val[3]
+  }
 
 existence_spec:  V_INTEGER #-- can only be 0 or 1
+  { 
+    begin
+      integer = Integer(val[0])
+    rescue
+      raise
+    end
+    result = integer
+  }
   | V_INTEGER SYM_ELLIPSIS V_INTEGER #-- can only be 0..0, 0..1, 1..1
+  { 
+    begin
+      from_integer = Integer(val[0])
+      to_integer = Integer(val[2])
+    rescue
+      raise
+    end
+    result = Range.new(from_integer,to_integer)
+  }
 
 c_cardinality: SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new
+  }
 
 cardinality_spec: occurrence_spec
@@ -687,21 +921,39 @@
 
 c_boolean_spec: SYM_TRUE
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true)
+  }
   | SYM_FALSE
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false)
+  }
   | SYM_TRUE Comma_code SYM_FALSE
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
+  }
   | SYM_FALSE Comma_code SYM_TRUE
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
+  }
 
 c_boolean: c_boolean_spec
+  { 
+    result = val[0]
+  }
   | c_boolean_spec Semicolon_code boolean_value
+  {
+    raise 'Not implemented yet'
+  }
   | c_boolean_spec Semicolon_code error
-#  | c_boolean_spec ';' error
+  {
+    raise 'Not implemented yet'
+  }
 
 c_ordinal: c_ordinal_spec
   | c_ordinal_spec Semicolon_code integer_value
   | c_ordinal_spec Semicolon_code error
-#  | c_ordinal_spec ';' error
 
 c_ordinal_spec: ordinal
   | c_ordinal_spec Comma_code ordinal
-#  | c_ordinal_spec ',' ordinal
 
 ordinal: integer_value SYM_INTERVAL_DELIM V_QUALIFIED_TERM_CODE_REF
@@ -756,4 +1008,10 @@
 
 ---- inner
+
+def assert_at(file,line, message = "")
+  unless yield
+    raise "Assertion failed !: #{file}, #{line}: #{message}"
+  end
+end
 
 @@log = Logger.new('log/parser.log','daily')
Index: /ruby/trunk/adl_parser/tests/parser_test.rb
===================================================================
--- /ruby/trunk/adl_parser/tests/parser_test.rb	(revision 21)
+++ /ruby/trunk/adl_parser/tests/parser_test.rb	(revision 22)
@@ -20,123 +20,125 @@
     end
 
-#     apgar = File.read('tests/openEHR-EHR-OBSERVATION.apgar.v1.adl')
-#     assert_nothing_raised do
-#       result = @parser.parse(apgar, 'openEHR-EHR-OBSERVATION.apgar.v1.adl')
-#       #       assert_equal "", result
-#     end
+    apgar = File.read('tests/openEHR-EHR-OBSERVATION.apgar.v1.adl')
+    assert_nothing_raised do
+      result = @parser.parse(apgar, 'openEHR-EHR-OBSERVATION.apgar.v1.adl')
+      assert_instance_of OpenEHR::AM::Archetype::ARCHETYPE, result
+      assert_instance_of OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION, result.description
+      assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT, result.definition
+    end
 
-#     evaluation = File.read('tests/openEHR-EHR-EVALUATION.adverse.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(evaluation, 'openEHR-EHR-EVALUATION.adverse.v1.adl')
-#     end
+    evaluation = File.read('tests/openEHR-EHR-EVALUATION.adverse.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(evaluation, 'openEHR-EHR-EVALUATION.adverse.v1.adl')
+    end
 
 
 
-#     referral = File.read('tests/openEHR-EHR-ITEM_TREE.referral.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(referral, 'openEHR-EHR-ITEM_TREE.referral.v1.adl')
-#     end
+    referral = File.read('tests/openEHR-EHR-ITEM_TREE.referral.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(referral, 'openEHR-EHR-ITEM_TREE.referral.v1.adl')
+    end
 
-#     exam_fetus = File.read('tests/openEHR-EHR-CLUSTER.exam-fetus.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_fetus, 'openEHR-EHR-CLUSTER.exam-fetus.v1.adl')
-#     end
+    exam_fetus = File.read('tests/openEHR-EHR-CLUSTER.exam-fetus.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_fetus, 'openEHR-EHR-CLUSTER.exam-fetus.v1.adl')
+    end
 
-#     exam_uterine_cervix = File.read('tests/openEHR-EHR-CLUSTER.exam-uterine_cervix.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_uterine_cervix, 'openEHR-EHR-CLUSTER.exam-uterine_cervix.v1.adl')
-#     end
+    exam_uterine_cervix = File.read('tests/openEHR-EHR-CLUSTER.exam-uterine_cervix.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_uterine_cervix, 'openEHR-EHR-CLUSTER.exam-uterine_cervix.v1.adl')
+    end
 
-#     imaging = File.read('tests/openEHR-EHR-ACTION.imaging.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(imaging, 'openEHR-EHR-ACTION.imaging.v1.adl')
-#     end
+    imaging = File.read('tests/openEHR-EHR-ACTION.imaging.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(imaging, 'openEHR-EHR-ACTION.imaging.v1.adl')
+    end
 
-#     exam_nervous_system = File.read('tests/openEHR-EHR-CLUSTER.exam-nervous_system.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_nervous_system, 'openEHR-EHR-CLUSTER.exam-nervous_system.v1.adl')
-#     end
-#     exam_generic = File.read('tests/openEHR-EHR-CLUSTER.exam-generic.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_generic, 'openEHR-EHR-CLUSTER.exam-generic.v1.adl')
-#     end
-#     exam_generic_mass = File.read('tests/openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_generic_mass, 'openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
-#     end
-#     exam_generic_lymphnode = File.read('tests/openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_generic_lymphnode, 'openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
-#     end
-#     exam_generic_joint = File.read('tests/openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_generic_joint, 'openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
-#     end
-#     exam_chest = File.read('tests/openEHR-EHR-CLUSTER.exam-chest.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_chest, 'openEHR-EHR-CLUSTER.exam-chest.v1.adl')
-#     end
-#     exam_abdomen = File.read('tests/openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(exam_abdomen, 'openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
-#     end
-#     cluster_auscultation = File.read('tests/openEHR-EHR-CLUSTER.auscultation.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(cluster_auscultation, 'openEHR-EHR-CLUSTER.auscultation.v1.adl')
-#     end
-#     cluster_auscultation_chest = File.read('tests/openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(cluster_auscultation_chest, 'openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
-#     end
-#     vital_signs = File.read('tests/openEHR-EHR-SECTION.vital_signs.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(vital_signs, 'openEHR-EHR-SECTION.vital_signs.v1')
-#     end
-#     summary = File.read('tests/openEHR-EHR-SECTION.summary.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(summary, 'openEHR-EHR-SECTION.summary.v1.adl')
-#     end
+    exam_nervous_system = File.read('tests/openEHR-EHR-CLUSTER.exam-nervous_system.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_nervous_system, 'openEHR-EHR-CLUSTER.exam-nervous_system.v1.adl')
+    end
+    exam_generic = File.read('tests/openEHR-EHR-CLUSTER.exam-generic.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_generic, 'openEHR-EHR-CLUSTER.exam-generic.v1.adl')
+    end
+    exam_generic_mass = File.read('tests/openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_generic_mass, 'openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
+    end
+    exam_generic_lymphnode = File.read('tests/openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_generic_lymphnode, 'openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
+    end
+    exam_generic_joint = File.read('tests/openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_generic_joint, 'openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
+    end
+    exam_chest = File.read('tests/openEHR-EHR-CLUSTER.exam-chest.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_chest, 'openEHR-EHR-CLUSTER.exam-chest.v1.adl')
+    end
+    exam_abdomen = File.read('tests/openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(exam_abdomen, 'openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
+    end
+    cluster_auscultation = File.read('tests/openEHR-EHR-CLUSTER.auscultation.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(cluster_auscultation, 'openEHR-EHR-CLUSTER.auscultation.v1.adl')
+    end
+    cluster_auscultation_chest = File.read('tests/openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(cluster_auscultation_chest, 'openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
+    end
+    vital_signs = File.read('tests/openEHR-EHR-SECTION.vital_signs.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(vital_signs, 'openEHR-EHR-SECTION.vital_signs.v1')
+    end
+    summary = File.read('tests/openEHR-EHR-SECTION.summary.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(summary, 'openEHR-EHR-SECTION.summary.v1.adl')
+    end
 
-#     findings = File.read('tests/openEHR-EHR-SECTION.findings.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(findings, 'openEHR-EHR-SECTION.findings.v1.adl')
-#     end
+    findings = File.read('tests/openEHR-EHR-SECTION.findings.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(findings, 'openEHR-EHR-SECTION.findings.v1.adl')
+    end
 
-#     reason_for_encounter = File.read('tests/openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(reason_for_encounter, 'openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
-#     end
+    reason_for_encounter = File.read('tests/openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(reason_for_encounter, 'openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
+    end
 
-#     imaging = File.read('tests/openEHR-EHR-ITEM_TREE.imaging.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(imaging, 'openEHR-EHR-ITEM_TREE.imaging.v1.adl')
-#     end
-#     instruction_referral = File.read('tests/openEHR-EHR-INSTRUCTION.referral.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(instruction_referral, 'openEHR-EHR-INSTRUCTION.referral.v1.adl')
-#     end
-#     instruction_medication = File.read('tests/openEHR-EHR-INSTRUCTION.medication.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(instruction_medication, 'openEHR-EHR-INSTRUCTION.medication.v1.adl')
-#     end
-#     action_referral = File.read('tests/openEHR-EHR-ACTION.referral.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(action_referral, 'openEHR-EHR-ACTION.referral.v1.adl')
-#     end
+    imaging = File.read('tests/openEHR-EHR-ITEM_TREE.imaging.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(imaging, 'openEHR-EHR-ITEM_TREE.imaging.v1.adl')
+    end
+    instruction_referral = File.read('tests/openEHR-EHR-INSTRUCTION.referral.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(instruction_referral, 'openEHR-EHR-INSTRUCTION.referral.v1.adl')
+    end
+    instruction_medication = File.read('tests/openEHR-EHR-INSTRUCTION.medication.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(instruction_medication, 'openEHR-EHR-INSTRUCTION.medication.v1.adl')
+    end
+    action_referral = File.read('tests/openEHR-EHR-ACTION.referral.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(action_referral, 'openEHR-EHR-ACTION.referral.v1.adl')
+    end
 
-#     dimensions_circumference = File.read('tests/openEHR-EHR-CLUSTER.dimensions.v1.adl')
-#     assert_nothing_raised do
-#       @parser.parse(dimensions_circumference, 'openEHR-EHR-CLUSTER.dimensions.v1.adl')
-#     end
+    dimensions_circumference = File.read('tests/openEHR-EHR-CLUSTER.dimensions.v1.adl')
+    assert_nothing_raised do
+      @parser.parse(dimensions_circumference, 'openEHR-EHR-CLUSTER.dimensions.v1.adl')
+    end
 
-#     discharge = File.read('tests/openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
-#     assert_nothing_raised do
-#       @parser.parse(discharge, 'openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
-#     end
+    discharge = File.read('tests/openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
+    assert_nothing_raised do
+      @parser.parse(discharge, 'openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
+    end
 
-#     encounter = File.read('tests/openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
-#     assert_nothing_raised do
-#       @parser.parse(encounter, 'openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
-#     end
+    encounter = File.read('tests/openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
+    assert_nothing_raised do
+      @parser.parse(encounter, 'openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
+    end
 
 
