Index: ruby/trunk/adl_parser/lib/parser.y
===================================================================
--- ruby/trunk/adl_parser/lib/parser.y	(revision 18)
+++ ruby/trunk/adl_parser/lib/parser.y	(revision 19)
@@ -49,5 +49,6 @@
 
 arch_meta_data_items: arch_meta_data_item
-  | arch_meta_data_items ';' arch_meta_data_item
+  | arch_meta_data_items Semicolon_code arch_meta_data_item
+#  | arch_meta_data_items ';' arch_meta_data_item
 
 arch_meta_data_item: SYM_ADL_VERSION SYM_EQ V_VERSION_STRING
@@ -120,5 +121,6 @@
 #------------------------- node types -----------------------
 
-c_object: c_complex_object
+c_object: v_c_domain_type
+  | c_complex_object
   | archetype_internal_ref
   | archetype_slot
@@ -127,5 +129,5 @@
   | c_ordinal
   | c_primitive_object
-  | v_c_domain_type
+#  | v_c_domain_type
 #  | V_C_DOMAIN_TYPE
   #   this is an attempt to match a dADL section inside cADL. It will
@@ -180,5 +182,11 @@
 
 c_attr_head: V_ATTRIBUTE_IDENTIFIER c_existence
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
+  }
   | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}") 
+  }
 
 c_attr_values: c_object
@@ -224,11 +232,15 @@
 attr_vals: attr_val
   | attr_vals attr_val
-  | attr_vals ';' attr_val
+  | attr_vals Semicolon_code attr_val
+#  | attr_vals ';' attr_val
 
 attr_val: attr_id SYM_EQ object_block
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]}, object_block = #{val[1]} at #{@filename}:#{@lineno}")
+  }
 
 attr_id: V_ATTRIBUTE_IDENTIFIER
   {
-    @@log.info("dADL::V_ATTRIBUTE_IDENTIFIER: #{val[0]} at #{@filename}")
+    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
   }
   | V_ATTRIBUTE_IDENTIFIER error
@@ -253,4 +265,7 @@
 
 object_key: Left_bracket_code simple_value Right_bracket_code
+  {
+    @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
+  }
 
 single_attr_object_block: untyped_single_attr_object_block
@@ -268,13 +283,43 @@
   | term_code_list_value
 simple_value: string_value
+  {
+    @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | integer_value
+  {
+    @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | real_value
+  {
+    @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | boolean_value
+  {
+    @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | character_value
+  {
+    @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | date_value
+  {
+    @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | time_value
+  {
+    @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | date_time_value
+  {
+    @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | duration_value
+  {
+    @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | uri_value
+  {
+    @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
+  }
 simple_list_value: string_list_value
   | integer_list_value
@@ -295,9 +340,15 @@
 
 type_identifier: V_TYPE_IDENTIFIER
+  {
+    @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
+  }
   | V_GENERIC_TYPE_IDENTIFIER
+  {
+    @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
+  }
 
 string_value: V_STRING
   {
-    @@log.info("V_STRING: #{val[0]} at #{@filename}")
+    @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
   }
 
@@ -409,4 +460,7 @@
 
 duration_value: V_ISO8601_DURATION
+  {
+    @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
+  }
 
 duration_list_value: duration_value Comma_code duration_value
@@ -497,5 +551,11 @@
 
 path_segment: V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
+  }
   | V_ATTRIBUTE_IDENTIFIER
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
+  }
 
 
@@ -601,9 +661,11 @@
 c_boolean: c_boolean_spec
   | c_boolean_spec Semicolon_code boolean_value
-  | c_boolean_spec ';' error
+  | c_boolean_spec Semicolon_code error
+#  | c_boolean_spec ';' error
 
 c_ordinal: c_ordinal_spec
   | c_ordinal_spec Semicolon_code integer_value
-  | c_ordinal_spec ';' error
+  | c_ordinal_spec Semicolon_code error
+#  | c_ordinal_spec ';' error
 
 c_ordinal_spec: ordinal
@@ -631,4 +693,7 @@
 any_identifier: type_identifier
   | V_ATTRIBUTE_IDENTIFIER
+  {
+    @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
+  }
 
 
@@ -647,4 +712,5 @@
 require 'lib/util.rb'
 require 'lib/scanner.rb'
+require 'lib/model.rb'
 $DEBUG = true
 
@@ -655,4 +721,5 @@
 @@log = Logger.new('log/parser.log','daily')
 @@dadl_scanner = OpenEHR::ADL::Scanner::DADL::RootScanner.new
+@@cadl_scanner = OpenEHR::ADL::Scanner::CADL::RootScanner.new
 
 ###----------/* keywords */ --------------------------------------------- 
@@ -755,4 +822,5 @@
       when /\A--.*\n/ # single line comment
         @lineno += 1
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
       when /\Adescription/   # description
@@ -770,7 +838,8 @@
         word = $&
         if @@adl_reserved[word]
-          @@log.info("@@adl_reserved: #{@@adl_reserved[word]} at #{@filename}")
+          @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: @@adl_reserved = #{@@adl_reserved[word]} at #{@filename}:#{@lineno}")
           yield @@adl_reserved[word], @@adl_reserved[word]
         elsif #/\A[A-Z][a-zA-Z0-9_]*/
+          @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: V_ATTRIBUTE_IDENTIFIER = #{$&} at #{@filename}:#{@lineno}")
           yield :V_ATTRIBUTE_IDENTIFIER, $&
         end
@@ -801,4 +870,5 @@
       when /\A\{/   # {
         @adl_type.push(:cadl)
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
         yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
       when /\A\}/   # }
@@ -806,4 +876,5 @@
 #        puts "Escaping #{adl_type}"
         assert_at(__FILE__,__LINE__){adl_type == :cadl}
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
         yield :SYM_END_CBLOCK, $&
       when /\A\-/   # -
@@ -923,4 +994,16 @@
     when :cadl
 #      puts "Entering scan_cadl"
+      case scanned = @@cadl_scanner.parse(data)
+      when Yaparc::Result::OK
+        if scanned.value[0] == :START_V_C_DOMAIN_TYPE_BLOCK
+          @in_c_domain_type = true
+          @adl_type.push(:dadl)
+          yield scanned.value
+        else
+          yield scanned.value
+        end
+        data = scanned.input
+      end
+
       case data
       when /\A\n/ # carriage return
@@ -931,4 +1014,5 @@
       when /\A--.*\n/ # single line comment
         @lineno += 1
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
         ###----------/* symbols */ ------------------------------------------------- 
@@ -939,11 +1023,8 @@
       when /\A\<=/   # <=
         yield :SYM_LE, :SYM_LE
-      when /\A[A-Z][a-zA-Z0-9_]*[ \n]*\</   # V_C_DOMAIN_TYPE
-        @in_c_domain_type = true
-        @adl_type.push(:dadl)
-          yield :START_V_C_DOMAIN_TYPE_BLOCK, $&
-###         else
-###           raise
-###         end
+###       when /\A[A-Z][a-zA-Z0-9_]*[ \n]*\</   # V_C_DOMAIN_TYPE
+###         @in_c_domain_type = true
+###         @adl_type.push(:dadl)
+###         yield :START_V_C_DOMAIN_TYPE_BLOCK, $&
       when /\A\</   # <
         if @in_interval
@@ -1001,4 +1082,5 @@
       when /\A\{/   # {
         @adl_type.push(:cadl)
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
         yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
       when /\A\}/   # }
@@ -1006,4 +1088,5 @@
 #        puts "Escaping #{adl_type}"
         assert_at(__FILE__,__LINE__){adl_type == :cadl}
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
         yield :SYM_END_CBLOCK, :SYM_END_CBLOCK
       when /\A\$/   # $
@@ -1021,10 +1104,11 @@
         end
         yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
+
       when /\A\[[a-zA-Z0-9._\-]+::[a-zA-Z0-9._\-]+\]/   #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
         yield :V_QUALIFIED_TERM_CODE_REF, $&
       when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/   #ERR_V_QUALIFIED_TERM_CODE_REF
         yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
-#      when /\A\[([a-zA-Z0-9()._\-]+::[a-zA-Z0-9._\_-]+)\]/
-#        yield :V_TERM_CODE_CONSTRAINT, :V_TERM_CODE_CONSTRAINT
+      when /\A\[([a-zA-Z0-9()._\-]+::[a-zA-Z0-9._\_-]+)\]/
+        yield :V_TERM_CODE_CONSTRAINT, :V_TERM_CODE_CONSTRAINT
       when /\A\[[a-zA-Z0-9\(\)\._\-]+::[ \t\n]*/
         @adl_type.push(:term_constraint)
@@ -1049,4 +1133,5 @@
           yield @@cadl_reserved[word.downcase], @@cadl_reserved[word.downcase]
         else
+          @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}:#{@lineno}")
           yield :V_ATTRIBUTE_IDENTIFIER, word #V_ATTRIBUTE_IDENTIFIER /\A[a-z][a-zA-Z0-9_]*/
         end
@@ -1070,11 +1155,11 @@
       when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ /   #V_REAL
         yield :V_REAL, $&
-        #    when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
+           when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
       when /\A"([^"]*)"/m #V_STRING
         yield :V_STRING, $1
       when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
         yield :V_URI, $&
-      when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/   #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
-        yield :V_ISO8601_DURATION, $&
+###       when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/   #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
+###         yield :V_ISO8601_DURATION, $&
       when /\A\S/ #UTF8CHAR
         yield :UTF8CHAR, $&
@@ -1118,10 +1203,5 @@
         yield scanned.value
         data = scanned.input
-###       when Yaparc::Result::Fail
-###         raise "Scan Failed: #{scanned}"
-###       when Yaparc::Result::Error
-###         raise "Scan Error: #{scanned}"
       else
-        
       end
 
@@ -1134,4 +1214,5 @@
       when /\A--.*\n/ # single line comment
         @lineno += 1
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
         ###----------/* symbols */ ------------------------------------------------- 
@@ -1253,6 +1334,6 @@
       when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
         yield :V_URI, $&
-      when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/   #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
-        yield :V_ISO8601_DURATION, $&
+###       when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/   #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
+###         yield :V_ISO8601_DURATION, $&
       when /\A\S/ #UTF8CHAR
         yield :UTF8CHAR, $&
@@ -1351,4 +1432,5 @@
       when /\A--.*$/ # single line comment
         @lineno += 1
+        @@log.info("#{__FILE__}:#{__LINE__}: scan_term_constraint: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
       when /\A[a-zA-Z0-9\._\-]+[ \t]*,/ # match any line, with ',' termination
