Index: ruby/trunk/lib/adl_parser/lib/parser.y
===================================================================
--- ruby/trunk/lib/adl_parser/lib/parser.y	(revision 258)
+++ ruby/trunk/lib/adl_parser/lib/parser.y	(revision 261)
@@ -55,5 +55,5 @@
       archetype.original_language = language
     end
-    @@log.info("#{__FILE__}:#{__LINE__}: archetype = #{archetype} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: archetype = #{archetype} at #{@filename}:#{@lineno}")
     result = archetype
   }
@@ -155,5 +155,5 @@
   {
     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}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -206,12 +206,18 @@
 
 #------------------------- node types -----------------------
-
-c_object: v_c_domain_type
-  {
-    result = val[0]
-  }
-  | c_complex_object
-  {
-    @@log.info("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0].inspect} at #{@filename}:#{@lineno}")
+### http://www.openehr.org/svn/ref_impl_eiffel/TRUNK/components/adl_parser/src/syntax/cadl/parser/cadl_validator.html
+### c_object:  c_complex_object
+### | archetype_internal_ref
+### | archetype_slot
+### | constraint_ref
+### | c_code_phrase
+### | c_ordinal
+### | c_primitive_object
+### | V_C_DOMAIN_TYPE
+### | ERR_C_DOMAIN_TYPE
+### | error
+c_object: c_complex_object
+  {
+    @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0].inspect} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -246,4 +252,9 @@
     result = val[0]
   }
+  | v_c_domain_type
+  {
+    result = val[0]
+  }
+
 #  | v_c_domain_type
 #  | V_C_DOMAIN_TYPE
@@ -302,5 +313,5 @@
 c_primitive: c_integer
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
     result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.create do |c_integer|
       c_integer.list
@@ -311,30 +322,30 @@
   | c_real
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
     result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING.new
   }
@@ -342,5 +353,5 @@
   {
     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}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -382,5 +393,5 @@
 c_attr_head: V_ATTRIBUTE_IDENTIFIER c_existence
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
+    @@logger.debug("#{__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],
@@ -392,5 +403,5 @@
   {
     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}") 
+    @@logger.debug("#{__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],
@@ -474,5 +485,5 @@
 attr_val: attr_id SYM_EQ object_block
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]} at #{@filename}:#{@lineno}")
     result = {:attr_id => val[0], :object_block => val[2]}
   }
@@ -480,5 +491,5 @@
 attr_id: V_ATTRIBUTE_IDENTIFIER
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -519,5 +530,5 @@
 multiple_attr_object_block_head: SYM_START_DBLOCK
   { 
-    @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -534,5 +545,5 @@
 keyed_object: object_key SYM_EQ object_block
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]} at #{@filename}:#{@lineno}")
     result = {:object_key => val[0], :object_block => val[1]}
   }
@@ -540,5 +551,5 @@
 object_key: Left_bracket_code simple_value Right_bracket_code
   {
-    @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
+    @@logger.debug("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
     result = val[1]
   }
@@ -555,10 +566,10 @@
 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}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
     result = {:single_attr_object_complex_head => val[0], :attr_vals => val[1]}
   }
@@ -566,15 +577,15 @@
 primitive_object_block: untyped_primitive_object_block
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__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}")
+    @@logger.debug("#{__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[1]}> at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
     result = val[1]
   }
@@ -601,50 +612,50 @@
 simple_value: string_value
   {
-    @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("string_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | integer_value
   {
-    @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | real_value
   {
-    @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("real_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | boolean_value
   {
-    @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | character_value
   {
-    @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("character_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | date_value
   {
-    @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("date_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | time_value
   {
-    @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("time_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | date_time_value
   {
-    @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | duration_value
   {
-    @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
   | uri_value
   {
-    @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -669,10 +680,10 @@
 type_identifier: V_TYPE_IDENTIFIER
   {
-    @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("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}")
+    @@logger.debug("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -680,5 +691,5 @@
 string_value: V_STRING
   {
-    @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -844,5 +855,5 @@
 duration_value: V_ISO8601_DURATION
   {
-    @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -864,5 +875,5 @@
 term_code: V_QUALIFIED_TERM_CODE_REF
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -874,5 +885,5 @@
 uri_value: V_URI
   {
-    @@log.info("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
     result = val[0]
   }
@@ -944,9 +955,9 @@
 path_segment: V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF
   {
-    @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
+    @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
   }
   | V_ATTRIBUTE_IDENTIFIER
   {
-    @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
+    @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
   }
 
@@ -1121,5 +1132,5 @@
   {
     @in_interval = false
-    @@log.info("#{__FILE__}:#{__LINE__}, #{val[0]}|#{val[2]} at #{@filename}") 
+    @@logger.debug("#{__FILE__}:#{__LINE__}, #{val[0]}|#{val[2]} at #{@filename}") 
   }
 
@@ -1134,10 +1145,17 @@
   }
 
-#term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body Right_bracket_code
+#                             [[a-zA-Z0-9\(\)\._\-]+::[ \t\n]*          [[a-zA-Z0-9\._\-]*[ \t]*]
 term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body END_TERM_CODE_CONSTRAINT
+  {
+    @@logger.debug("#{__FILE__}:#{__LINE__}, START_TERM_CODE_CONSTRAINT = #{val[0]} at #{@filename}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}, term_code_body = #{val[1]}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}, END_TERM_CODE_CONSTRAINT = #{val[2]}")
+    result = val[1]
+  }
+
+
 term_code_body: # empty
   | TERM_CODE
   | term_code_body TERM_CODE
-### term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body END_TERM_CODE_CONSTRAINT
 ### term_code_body: TERM_CODE
 ###   | term_code_body TERM_CODE
@@ -1155,5 +1173,5 @@
   | V_ATTRIBUTE_IDENTIFIER
   {
-    @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
+    @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
       result = val[0]
   }
@@ -1194,9 +1212,9 @@
 
 if $DEBUG
-  @@log = Logger.new('log/parser.log','daily')
-  @@log.level = Logger::INFO
+  @@logger = Logger.new('log/parser.log','daily')
+  @@logger.level = Logger::INFO
 else
-  @@log = Logger.new(STDOUT)
-  @@log.level = Logger::WARN
+  @@logger = Logger.new(STDOUT)
+  @@logger.level = Logger::WARN
 end
 
@@ -1263,4 +1281,5 @@
 
 def scan
+  @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan at #{@filename}:#{@lineno}:")
   until @data.nil?  do
     case @adl_type.last
@@ -1279,4 +1298,9 @@
     when :regexp
       @data = scan_regexp(@data) do |sym, val|
+        yield sym, val
+      end
+    when :term_constraint
+      @@logger.debug("#{__FILE__}:#{__LINE__}: scan: Entering scan_term_constraint at #{@filename}:#{@lineno}: data = #{data.inspect}")
+      @data = scan_term_constraint(@data) do |sym, val|
         yield sym, val
       end
@@ -1291,8 +1315,8 @@
 
 def scan_adl(data)
+  @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan_adl at #{@filename}:#{@lineno}: data = #{data.inspect}")
   until data.nil?  do
     case @adl_type.last
     when :adl
-#      puts "Entering scan_adl"
       case data
       when /\A\n/ # carriage return
@@ -1303,5 +1327,5 @@
       when /\A--.*\n/ # single line comment
         @lineno += 1
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_adl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
       when /\Adescription/   # description
@@ -1309,10 +1333,9 @@
       when /\Adefinition/   # definition
         yield :SYM_DEFINITION, :SYM_DEFINITION
-#        @adl_type.push(:cadl)
         ###----------/* symbols */ ------------------------------------------------- 
       when /\A[A-Z][a-zA-Z0-9_]*/
         yield :V_TYPE_IDENTIFIER, $&
 #      when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/   #V_ARCHETYPE_ID
-      when /\A(\w+)-(\w+)-(\w+)\.(\w+)(-\w+)?\.(v[0-9]+)/   #V_ARCHETYPE_ID
+      when /\A(\w+)-(\w+)-(\w+)\.(\w+)(-\w+)?\.(v\w+)/   #V_ARCHETYPE_ID
         object_id, rm_originator, rm_name, rm_entity, concept_name, specialisation, version_id = $&, $1, $2, $3, $4, $5, $6
         archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new(object_id, concept_name, rm_name, rm_entity, rm_originator, specialisation, version_id)
@@ -1323,8 +1346,8 @@
         word = $&
         if @@adl_reserved[word]
-          @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: @@adl_reserved = #{@@adl_reserved[word]} at #{@filename}:#{@lineno}")
+          @@logger.debug("#{__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}")
+          @@logger.debug("#{__FILE__}:#{__LINE__}: scan_adl: V_ATTRIBUTE_IDENTIFIER = #{$&} at #{@filename}:#{@lineno}")
           yield :V_ATTRIBUTE_IDENTIFIER, $&
         end
@@ -1349,5 +1372,4 @@
         else
           adl_type = @adl_type.pop
-#          puts "Escaping #{adl_type}"
           assert_at(__FILE__,__LINE__){adl_type == :dadl}
           yield :SYM_END_DBLOCK, :SYM_END_DBLOCK
@@ -1355,5 +1377,5 @@
       when /\A\{/   # {
         @adl_type.push(:cadl)
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
         yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
       when /\A\}/   # }
@@ -1361,5 +1383,5 @@
 #        puts "Escaping #{adl_type}"
         assert_at(__FILE__,__LINE__){adl_type == :cadl}
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
         yield :SYM_END_CBLOCK, $&
       when /\A\-/   # -
@@ -1446,20 +1468,18 @@
       data = $' # variable $' receives the string after the match
     when :dadl
-#      puts "Entering scan_dadl"
       data = scan_dadl(data) do |sym, val|
         yield sym, val
       end
     when :cadl
-#      puts "Entering scan_cadl"
       data = scan_cadl(data) do |sym, val|
         yield sym, val
       end
     when :regexp
-#      puts "Entering scan_regexp"
       data = scan_regexp(data) do |sym, val|
         yield sym, val
       end
     when :term_constraint
-#      puts "Entering scan_term_constraint"
+      @@logger.debug("#{__FILE__}:#{__LINE__}: scan_adl: Entering scan_term_constraint at #{@filename}:#{@lineno}: data = #{data.inspect}")
+
       data = scan_term_constraint(data) do |sym, val|
         yield sym, val
@@ -1473,8 +1493,8 @@
 
 def scan_cadl(data)
+  @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan_cadl at #{@filename}:#{@lineno}: data = #{data.inspect}")
   until data.nil?  do
     case @adl_type.last
     when :cadl
-#      puts "Entering scan_cadl"
       case scanned = @@cadl_scanner.parse(data)
       when Yaparc::Result::OK
@@ -1497,5 +1517,5 @@
       when /\A--.*\n/ # single line comment
         @lineno += 1
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
         ###----------/* symbols */ ------------------------------------------------- 
@@ -1565,5 +1585,5 @@
       when /\A\{/   # {
         @adl_type.push(:cadl)
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
         yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
       when /\A\}/   # }
@@ -1571,5 +1591,5 @@
 #        puts "Escaping #{adl_type}"
         assert_at(__FILE__,__LINE__){adl_type == :cadl}
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
         yield :SYM_END_CBLOCK, :SYM_END_CBLOCK
       when /\A\$/   # $
@@ -1580,5 +1600,5 @@
         yield :Question_mark_code, :Question_mark_code
       when /\A\|/   # |
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
         if @in_interval
           @in_interval = false
@@ -1587,16 +1607,15 @@
           @in_interval = true
         end
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
         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]
+      when /\A\[[a-zA-Z0-9()\._-]+::[a-zA-Z0-9\._-]+\]/  #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
+#      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\(\)\._\-]+::[ \t\n]*/
+      when /\A\[([a-zA-Z0-9\(\)\._\-]+)::[ \t\n]*/
         @adl_type.push(:term_constraint)
-        yield :START_TERM_CODE_CONSTRAINT, $&
+        yield :START_TERM_CODE_CONSTRAINT, $1
       when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/   #V_LOCAL_TERM_CODE_REF
         yield :V_LOCAL_TERM_CODE_REF, $&
@@ -1618,5 +1637,5 @@
           yield @@cadl_reserved[word.downcase], @@cadl_reserved[word.downcase]
         else
-          @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}:#{@lineno}")
+          @@logger.debug("#{__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
@@ -1654,20 +1673,18 @@
       data = $' # variable $' receives the string after the match
     when :adl
-#      puts "Entering scan_adl"
       data = scan_adl(data) do |sym, val|
         yield sym, val
       end
     when :dadl
-#      puts "Entering scan_dadl"
       data = scan_dadl(data) do |sym, val|
         yield sym, val
       end
     when :regexp
-#      puts "Entering scan_regexp"
       data = scan_regexp(data) do |sym, val|
         yield sym, val
       end
     when :term_constraint
-#      puts "Entering scan_term_constraint"
+      @@logger.debug("#{__FILE__}:#{__LINE__}: scan_cadl: Entering scan_term_constraint at #{@filename}:#{@lineno}: data = #{data.inspect}")
+      
       data = scan_term_constraint(data) do |sym, val|
         yield sym, val
@@ -1680,8 +1697,8 @@
 
 def scan_dadl(data)
+  @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan_dadl at #{@filename}:#{@lineno}: data = #{data.inspect}")
   until data.nil?  do
     case @adl_type.last
     when :dadl
-#      puts "Entering scan_dadl"
       case scanned = @@dadl_scanner.parse(data)
       when Yaparc::Result::OK
@@ -1699,5 +1716,5 @@
       when /\A--.*\n/ # single line comment
         @lineno += 1
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_dadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
         ###----------/* symbols */ ------------------------------------------------- 
@@ -1730,5 +1747,4 @@
         elsif @in_c_domain_type == false
           adl_type = @adl_type.pop
-#          puts "Escaping #{adl_type}"
           assert_at(__FILE__,__LINE__){adl_type == :dadl}
           yield :SYM_END_DBLOCK, $&
@@ -1771,5 +1787,5 @@
         yield :Question_mark_code, :Question_mark_code
       when /\A\|/   # |
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_dadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
         if @in_interval
           @in_interval = false
@@ -1778,5 +1794,5 @@
           @in_interval = true
         end
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
+        @@logger.debug("#{__FILE__}:#{__LINE__}: scan_dadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
         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]
@@ -1827,10 +1843,8 @@
       data = $' # variable $' receives the string after the match
     when :adl
-#      puts "Entering scan_adl"
       data = scan_adl(data) do |sym, val|
         yield sym, val
       end
     when :cadl
-#      puts "Entering scan_cadl"
       data = scan_cadl(data) do |sym, val|
         yield sym, val
@@ -1842,5 +1856,6 @@
       end
     when :term_constraint
-#      puts "Entering scan_term_constraint"
+      @@logger.debug("#{__FILE__}:#{__LINE__}: scan_dadl: Entering scan_term_constraint at #{@filename}:#{@lineno}: data = #{data.inspect}")
+
       data = scan_term_constraint(data) do |sym, val|
         yield sym, val
@@ -1853,8 +1868,8 @@
 
 def scan_regexp(data)
+  @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan_regexp at #{@filename}:#{@lineno}: data = #{data.inspect}")
   until data.nil?  do
     case @adl_type.last
     when :regexp
-#      puts "Entering scan_regexp"
       case data
       when /\A\/\}/ #V_REGEXP
@@ -1880,20 +1895,17 @@
       data = $' # variable $' receives the string after the match
     when :adl
-#      puts "Entering scan_adl"
       data = scan_adl(data) do |sym, val|
         yield sym, val
       end
     when :dadl
-#      puts "Entering scan_dadl"
       data = scan_dadl(data) do |sym, val|
         yield sym, val
       end
     when :cadl
-#      puts "Entering scan_cadl"
       data = scan_cadl(data) do |sym, val|
         yield sym, val
       end
     when :term_constraint
-#      puts "Entering scan_term_constraint"
+      @@logger.debug("#{__FILE__}:#{__LINE__}: scan_regexp: Entering scan_term_constraint at #{@filename}:#{@lineno}")
       data = scan_term_constraint(data) do |sym, val|
         yield sym, val
@@ -1906,8 +1918,8 @@
 
 def scan_term_constraint(data)
+  @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan_term_constraint")
   until data.nil?  do
     case @adl_type.last
     when :term_constraint
-#      puts "Entering scan_term_constraint"
       case data
       when /\A\n/ # carriage return
@@ -1918,15 +1930,14 @@
       when /\A--.*$/ # single line comment
         @lineno += 1
-        @@log.info("#{__FILE__}:#{__LINE__}: scan_term_constraint: COMMENT = #{$&} at #{@filename}:#{@lineno}")
+        #@@logger.debug("#{__FILE__}:#{__LINE__}: scan_term_constraint: COMMENT = #{$&} at #{@filename}:#{@lineno}")
         ;
-      when /\A[a-zA-Z0-9\._\-]+[ \t]*,/ # match any line, with ',' termination
-        yield :TERM_CODE, $&
-      when /\A[a-zA-Z0-9\._\-]+[ \t]*;/ #match second last line with ';' termination (assumed value)
-        yield :TERM_CODE, $&
-#      when /\A[a-zA-Z0-9\._\-]+[ \t]*\]/ # match final line, terminating in ']'
-      when /\A[a-zA-Z0-9\._\-]*[ \t]*\]/ # match final line, terminating in ']'
+      when /\A([a-zA-Z0-9\._\-])+[ \t]*,/ # match any line, with ',' termination
+        yield :TERM_CODE, $1
+      when /\A([a-zA-Z0-9\._\-])+[ \t]*;/ # match second last line with ';' termination (assumed value)
+        yield :TERM_CODE, $1
+      when /\A([a-zA-Z0-9\._\-])*[ \t]*\]/ # match final line, terminating in ']'
         adl_type = @adl_type.pop
         assert_at(__FILE__,__LINE__){adl_type == :term_constraint}
-        yield :END_TERM_CODE_CONSTRAINT, $&
+        yield :END_TERM_CODE_CONSTRAINT, $1
       else
         raise "data = #{data}"
@@ -1934,15 +1945,12 @@
       data = $' # variable $' receives the string after the match
     when :adl
-#      puts "Entering scan_adl"
       data = scan_adl(data) do |sym, val|
         yield sym, val
       end
     when :dadl
-#      puts "Entering scan_dadl"
       data = scan_dadl(data) do |sym, val|
         yield sym, val
       end
     when :cadl
-#      puts "Entering scan_cadl"
       data = scan_cadl(data) do |sym, val|
         yield sym, val
