#!/usr/bin/env icarus
# NCCB_PLASMID Plasmid - 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
  Type:type
  Literature:lit
  History_of_deposit:history
  Restricted_distribution:rest_distrib
  Host_for_distribution:host_for_dist
  Selectable_phenotype:sel_pheno
  Replicon:replicon
  Host_range:host_range
  Promoter:promoter
  Cloned_gene:cloned_gene
  Properties_and_applications:prop_and_appl
  Medium:medium
  Other_culture_collection_numbers:oth_cul_col_no
  Class:class
  Constructed_from:construct
  Incompatibility_group:inc_group
  Transfer_ability:tran_abil
  Helper:helper
  Copy_number:copy_number
  Molecular_weight:mol_weight
  Transposable_element:trans_el
  Ribosome_binding_site:ribo_bind_site
  Start_codon:start_codon
  Terminator:term
  Restriction_sites:rest_sites
  Further_information:further_inf
  Price_code:price_code
}

$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 ' '(word3{$Wrt} |punct4) ~

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

  medium:	~ {$In:[fields c:{medium}] $Out}
		  tag  / /* medi{$Uniq:$Itc} ~


  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})? )* ) ~

  lit:   ~ {$In:[fields c:lit] $Out}
                    bib_tag
		    (bib_word {$Uniq:$Itc} | bib_vol | bib_punct | ' ')*
		     ('[PMID: ' pmid {$Uniq:$Itc} ']')? ~

  strX:		~ {$In:[fields c:{type lit history sel_pheno replicon
                                  host_range promoter cloned_gene
                                  prop_and_appl rest_distrib
                                  host_for_dist class inc_group
                                  tran_abil helper copy_number mol_weight
                                  trans_el term
                                  ribo_bind_site start_codon rest_sites 
                                  further_inf price_code}] $Out}
		  tag (str{$Uniq:$Itc} | /./ |punct2)* ~

  strX1:	~ {$In:[fields c:{construct}] $Out}
		  tag (str1{$Uniq:$Itc} | /./ |punct2)* ~

#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\">
                }
        	/ /* medi {$rest=$Ct.rep:[' ' to:'%20']
			$Rep:$Hlink:[nccb_plasmidR p:{$rest $Ct}]}~   

  h_lit:  ~ {$In:[fields c:lit t:html]
                   pre if:$ParInt:isTable $Fail}
		   bib_tag {if:$isTable==0 $Rep:
		      |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
		      |<font color=\"#000066\">
		      |<b><i>$Ct</i></b></font></TD>
		      |<TD bgcolor=\"#ffffff\">
		  }
		  /[^\\[]*/
		 ('[PMID: ' pmid {$Rep:$Hlink:[pubmedCabriR p:{$Ct $Ct}]} ']')?
		  x{$Rep:"</TD></TR>"}  ~

  h_fields:      ~ {$In:[fields 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-]+/ ~
  number:	~/[0-9.]+/ ~
  word:		~/[0-9a-zA-Z_\/-]+/ ~
  word3:	~/[ 0-9a-zA-Z_\/\\(\\)-]+/ ~
  word4:        ~/[a-zA-Z0-9&\\%\\_-]+/ ~
  word5:        ~/[a-zA-Z0-9&\\%\\_-]+(\\.[a-zA-Z0-9&\\%\\_-]+)+/ ~
  str:		~ word5 | word4 ~
  str1:		~/[a-zA-Z0-9&\\%\\.+_-]+/ ~
  punct:	~ /[ \t,;:\\.\\(\\)\\+\\*]+/ ~  
  punct4:	~ /[\t,;:\\.\\(\\)\\+\\*]+/ ~  
  punct2:	~ /[ \t]+/ ~  
  bib_tag:        ~ ('Literature') ~
  bib_word:     ~ /[a-zA-Z]+/ ~
  bib_punct:    ~ /[;:.-]/ ~
  bib_vol:      ~ (number bib_punct?)+ ~
  pmid:         ~ /[0-9]+/ ~
  medi:		~ bib_word / /* number ~
}