#!/usr/bin/env icarus
# DSMZ Plasmid Catalogue - Syntax file
# 
# Version 2004.12.17.01
# Last Updated December 17, 2004
# Author: Domenico Marra & Francesca Piersigilli & Paolo Romano
# (c) CABRI 1999-2023

$fn={
  Collection_number:coll_no
  Name:name
  Other_culture_collection_numbers:oth_cul_col_no
  Type:type
  Class:class
  Constructed_from:construct
  Literature:literature
  History_of_deposit:history
  Restricted_distribution:rest_dist
  Host_for_distribution:host_for_dist
  Medium:medium
  Selectable_phenotype:sel_phen
  Replicon:replicon
  Incompatibility_group:inc_group
  Transfer_ability:tran_abil
  Host_range:host_range
  Properties_and_applications:prop_and_applic
  Helper:helper
  Copy_number:copy_number
  Molecular_weight:mol_weight
  Cloned_gene:cloned_gene
  Transposable_element:trans_el
  Promoter:promoter
  Ribosome_binding_site:ribo_bind_site
  Start_codon:start_codon
  Terminator:term
  Further_information:further_inf
  Restriction_sites:rest_sites
  Sequence_detail:seq_detail
}

$rules={
  entry:	~ {$In:[file:text] $Out pre $Skip:0}
		  ('Collection_number' {$Not} ln)*
		  ('Collection_number' {$entryFip=$Fip $Wrt} ln {$App}
		  ('Collection_number' {$Not} ln {$App})*)?
		~

# fields
  fields:	~ {$In:entry $Out $Skip:1}
                  (/\/[^\n]+\n/ {$Wrt} |
                  tag {$Wrt:$fn.$Ct} 
                  (/[\/A-Z]/ {$Not} ln {$App})+)+ ~
 
#indexing
  coll_no:	~ {$In:[fields c:coll_no] $Out}
		  tag ' ' (word2{$Wrt} |punct2)* ~

  name:		~ {$In:[fields c:name] $Out}
		  tag (word{$Wrt:[s:$StrRep:[s:$Ct r:"[\/|\.|-]" to:""]]}
                       | punct)* ~

  oth_cul_col_no: ~ {$In:[fields c:oth_cul_col_no] $Out}
                  tag ( ' -' | ' ' code {$Wrt} (code {$Rep:" $Ct" $App})?
                        ( ';' code {$Wrt} (code {$Rep:" $Ct" $App})? )* ) ~

  strX:		~ {$In:[fields c:{name type host_for_dist medium rest_dist
				  class construct inc_group tran_abil
                                  prop_and_applic helper copy_number 
      				  mol_weight cloned_gene trans_el 
 				  promoter ribo_bind_site start_codon 
				  term further_inf rest_sites seq_detail
				  literature history sel_phen replicon 
				  host_range}] $Out}
		  tag (str{$Uniq:$Itc}| /./ |punct)* ~ 

#HTML stuff...
  h_top:      ~ {$In:[fields c:coll_no t:html] pre if:$ParInt:isTable $Fail}
                tag {$Rep:
                     |</TR><TR VALIGN=TOP>
                     |<TD colspan=2 bgcolor=\"#ffffff\">
		     |<font color=\"#000066\">
 		     |<B>CABRI:($entry.libName)</B></TD></TR>
		     |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
		     |<font color=\"#000066\"><b><i>$Ct</i></b>
		     |</font></TD><TD bgcolor=\"#ffffff\">
		 } 
		  /.*/ {$Rep:"$Ct</TD></TR>"}  ~

  h_medium: ~ {$In:[fields c:medium t:html] pre if:$ParInt:isTable $Fail}
              'Medium' {if:$isTable==0
              $Rep:
                |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
                |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                |<TD bgcolor=\"#ffffff\">
               }
              ' '* str {$Rep:$Hlink:[dsmz_mediaR p:$Ct]} ~

  h_literature: ~ {$In:[fields c:literature t:html] pre if:$ParInt:isTable $Fai
}
              'Literature' {if:$isTable==0
                $Rep:
                  |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
                  |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                  |<TD bgcolor=\"#ffffff\">
                 }
                ' '* ('-'| 'DSM ref.no. '
                          number {$Rep:$Hlink:[dsmz_litR p:$Ct]}
                ('; DSM ref.no. '
                          number {$Rep:$Hlink:[dsmz_litR p:$Ct]})*) ~

 h_fields:      ~ {$In:[fields xc:{medium literature} t:html]
                               pre if:$ParInt:isTable $Fail}
                   tag {if:$isTable==0
                   $Rep:
                     |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
                     |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                     |<TD bgcolor=\"#ffffff\">
                    } /.*/ {$Rep:"$Ct</TD></TR>"}  ~

 t_fields:     ~ {$In:[fields] $Out} tag /.*/ {$Wrt:$Itc} ~

# definitions
  tag:          ~ /[A-Z][a-z_]+/ ~
  ln:           ~ /[^\n]*\n/ ~
  code:         ~ /[A-Z0-9][A-Z0-9-]+/ ~ 
  word:		~/[0-9a-zA-Z_\/]+/ ~
  word2:	~/[ 0-9a-zA-Z_\\(\\)\/]+/ ~
  number:       ~/[0-9]+/ ~ 
  str:		~/[a-zA-Z0-9&.'=\/\\%_-]+/ ~
  punct:	~ /[ \t,;:\\.\\(\\)\\+\\*]+/ ~  
  punct2:	~ /[\t,;:\/\\+]+/ ~
}