Index: ruby/trunk/adl_parser/lib/parser.y
===================================================================
--- ruby/trunk/adl_parser/lib/parser.y	(revision 20)
+++ ruby/trunk/adl_parser/lib/parser.y	(revision 26)
@@ -28,30 +28,75 @@
 
 input: archetype EOF
+  { 
+    result = val[0]
+  }
   | error
 
-archetype: arch_identification
-  arch_specialisation
-  arch_concept
-  arch_language
-  arch_description
-  arch_definition
-  arch_invariant
-  arch_ontology
+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
+    
+    archetype_id = val[0][:archetype_id]
+    adl_version = val[0][:arch_head][:arch_meta_data][:adl_version]
+    concept = val[2]
+    language = val[3][:arch_language]
+    archetype = OpenEHR::AM::Archetype::ARCHETYPE.create(
+                                                         :archetype_id => archetype_id,
+                                                         :adl_version => adl_version,
+                                                         :concept => concept,
+                                                         :description => val[4],
+                                                         :definition => val[5],
+                                                         :ontology => val[7]
+                                                         ) do |archetype|
+      archetype.original_language = language
+    end
+    @@log.info("#{__FILE__}:#{__LINE__}: archetype = #{archetype} at #{@filename}:#{@lineno}")
+    result = archetype
+  }
 
 
 arch_identification: arch_head V_ARCHETYPE_ID
+  { 
+    result = {:arch_head => val[0], :archetype_id => val[1] }
+  }
   | SYM_ARCHETYPE error
+  { 
+    raise
+  }
 
 arch_head: SYM_ARCHETYPE
+  { 
+    result = {:arch_meta_data => nil }
+  }
   | SYM_ARCHETYPE arch_meta_data
+  { 
+    result = val[1]
+  }
 
 arch_meta_data: Left_parenthesis_code arch_meta_data_items Right_parenthesis_code
+  { 
+    result = {:arch_meta_data => val[1] }
+  }
 
 arch_meta_data_items: arch_meta_data_item
+  { 
+    result = val[0]
+  }
   | arch_meta_data_items Semicolon_code arch_meta_data_item
-#  | arch_meta_data_items ';' arch_meta_data_item
+  { 
+    result = val[0].merge(val[2])
+  }
+
 
 arch_meta_data_item: SYM_ADL_VERSION SYM_EQ V_VERSION_STRING
+  { 
+    result = {:adl_version => val[2], :is_controlled => false }
+  }
   | SYM_IS_CONTROLLED
+  { 
+    result = {:is_controlled => true }
+  }
 
 # Define specialization in which its constraints are narrower than those of the parent.
@@ -62,4 +107,7 @@
 
 arch_concept: SYM_CONCEPT V_LOCAL_TERM_CODE_REF
+  { 
+    result = {:arch_concept => val[1] }
+  }
   | SYM_CONCEPT error
 
@@ -69,7 +117,10 @@
 
 arch_language: #-- empty is ok for ADL 1.4 tools
+  {
+    result = {:arch_language => nil}
+  }
     | SYM_LANGUAGE dadl_section
   {
-    result = {:language => val[1]}
+    result = {:arch_language => val[1]}
   }
   | SYM_LANGUAGE error
@@ -81,9 +132,15 @@
 arch_description: #-- no meta-data ok
     | SYM_DESCRIPTION dadl_section
-    | SYM_DESCRIPTION error
-
+  { 
+    result = OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION.new(:details => val[1])
+  }
+  | SYM_DESCRIPTION error
+  
 #arch_definition: SYM_DEFINITION V_CADL_TEXT
 #  | SYM_DEFINITION error
 arch_definition: SYM_DEFINITION cadl_section
+  { 
+    result = val[1]
+  }
   | SYM_DEFINITION error
 
@@ -91,30 +148,54 @@
 ### cADL section
 cadl_section: c_complex_object
+  { 
+    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT)}
+    @@log.info("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
+  }
   | assertions
+  { 
+    result = val[0]
+  }
 #  | error
 
 #c_complex_object: c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK
 c_complex_object: c_complex_object_head SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
+      c_complex_object.node_id = val[0][:c_complex_object_id][:local_term_code_ref]
+      c_complex_object.rm_type_name = val[0][:c_complex_object_id][:type_identifier]
+      c_complex_object.occurrences = val[0][:c_occurrences]
+    end
+  }
     | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK
-#     | c_complex_object_head error SYM_END_CBLOCK
-#   {
-#     @adl_type.push(:cadl)
-#     yyerror
-#   }
+  { 
+    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
+      c_complex_object.node_id = val[0][:c_complex_object_id][:local_term_code_ref]
+      c_complex_object.rm_type_name = val[0][:c_complex_object_id][:type_identifier]
+      c_complex_object.occurrences = val[0][:c_occurrences]
+    end
+  }
+#    | c_complex_object_head error SYM_END_CBLOCK
 #    | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body c_invariants SYM_END_CBLOCK
 
 c_complex_object_head: c_complex_object_id c_occurrences
+  {
+    result = {:c_complex_object_id => val[0], :c_occurrences => val[1]}
+  }
 
 c_complex_object_id: type_identifier
   {
-    result = {:c_complex_object_id => {:type_identifier => val[0]}}
+    result = {:type_identifier => val[0]}
   }
   | type_identifier V_LOCAL_TERM_CODE_REF
   {
-    result = {:c_complex_object_id => {:type_identifier => val[0], :V_LOCAL_TERM_CODE_REF => val[1]}}
+    result = {:type_identifier => val[0], :local_term_code_ref => val[1]}
   }
 
 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])
+  }
 
 
@@ -122,11 +203,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
@@ -141,4 +246,7 @@
 
 v_c_domain_type: START_V_C_DOMAIN_TYPE_BLOCK dadl_section END_V_C_DOMAIN_TYPE_BLOCK
+  { 
+    result = val[1]
+  }
 
 # 'archetype_internal_ref' is a node that refers to a previously defined object node in the same archetype.
@@ -157,13 +265,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}:#{@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
@@ -173,10 +318,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]
+  }
 
 
@@ -184,13 +349,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
@@ -220,4 +405,8 @@
 
 arch_ontology: SYM_ONTOLOGY dadl_section
+  { 
+    dadl_section = val[1]
+    result = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
+  }
   | SYM_ONTOLOGY error
 
@@ -231,11 +420,20 @@
 
 attr_vals: attr_val
+  {
+    result = Array[val[0]]
+  }
   | attr_vals attr_val
+  {
+    result = (val[0] << val[1])
+  }
   | attr_vals Semicolon_code attr_val
-#  | attr_vals ';' attr_val
+  {
+    result = (val[0] << val[2])
+  }
 
 attr_val: attr_id SYM_EQ object_block
   {
     @@log.info("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
+    result = {:attr_id => val[0], :object_block => val[2]}
   }
 
@@ -243,29 +441,59 @@
   {
     @@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 = {:untyped_multiple_attr_object_block => val[0]}
+  }
   | type_identifier untyped_multiple_attr_object_block
+  { 
+    result = {:type_identifier => val[0], :untyped_multiple_attr_object_block => val[1]}
+  }
 
 untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK
+  { 
+    result = {:multiple_attr_object_block_head => val[0], :keyed_objects => val[1]}
+  }
 
 multiple_attr_object_block_head: SYM_START_DBLOCK
-  {
+  { 
     @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
 keyed_objects: keyed_object
+  { 
+    result = Array[val[0]]
+  }
   | keyed_objects keyed_object
+  { 
+    result = (val[0] << val[1])
+  }
 
 keyed_object: object_key SYM_EQ object_block
   {
     @@log.info("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
+    result = {:object_key => val[0], :object_block => val[1]}
   }
 
@@ -273,62 +501,113 @@
   {
     @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
+    result = val[1]
   }
 
 single_attr_object_block: untyped_single_attr_object_block
+  {
+    result = {:untyped_single_attr_object_block => val[0]}
+  }
   | type_identifier untyped_single_attr_object_block
+  {
+    result = {:type_identifier => val[0], :untyped_single_attr_object_block => val[1]}
+  }
+
 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 = {:single_attr_object_complex_head => 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 = {:single_attr_object_complex_head => val[0], :attr_vals => val[1]}
+  }
 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 = {:untyped_primitive_object_block => 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 = {:type_identifier => val[0], :untyped_primitive_object_block => val[1]}
+  }
 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
@@ -351,8 +630,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]
   }
 
@@ -360,4 +641,5 @@
   {
     @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -367,6 +649,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
@@ -387,8 +693,30 @@
 
 real_value: V_REAL
+  {
+    begin
+      real = Float(val[0])
+    rescue
+      raise
+    end
+    result = real
+  }
   | Plus_code V_REAL
+  {
+    begin
+      real = Float(val[1])
+    rescue
+      raise
+    end
+    result = real
+  }
   | Minus_code V_REAL
-#  | '+' V_REAL
-#  | '-' V_REAL
+  {
+    begin
+      real = Float(val[1])
+    rescue
+      raise
+    end
+    result = - real
+  }
 
 real_list_value: real_value Comma_code real_value
@@ -408,5 +736,11 @@
 
 boolean_value: SYM_TRUE
+  { 
+    result = true
+  }
   | SYM_FALSE
+  { 
+    result = false
+  }
 
 boolean_list_value: boolean_value Comma_code boolean_value
@@ -471,4 +805,5 @@
   {
     @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -490,4 +825,5 @@
   {
     @@log.info("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -499,4 +835,5 @@
   {
     @@log.info("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
+    result = val[0]
   }
 
@@ -581,10 +918,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
@@ -603,4 +966,7 @@
 c_occurrences:  #-- default to 1..1
   | SYM_OCCURRENCES SYM_MATCHES SYM_START_CBLOCK occurrence_spec SYM_END_CBLOCK
+  { 
+    result = val[3]
+  }
   | SYM_OCCURRENCES error
 
@@ -670,21 +1036,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
@@ -722,4 +1106,7 @@
 
 duration_pattern: V_ISO8601_DURATION_CONSTRAINT_PATTERN
+  { 
+    result = val[0]
+  }
 
 
@@ -731,5 +1118,6 @@
 require 'lib/util.rb'
 require 'lib/scanner.rb'
-require 'lib/model.rb'
+require 'rubygems'
+require 'am.rb'
 $DEBUG = true
 
@@ -737,4 +1125,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')
