#!/usr/bin/env icarus
# IBRD Database - Syntax file
# Version 2023.02.22.01
# Last Updated February 22, 2023
# Author: Domenico Marra & Francesca Piersigilli & Paolo Romano
# (c) CABRI 1999-2023

$fn={
  Identification:identification                 
  Name:name            
}

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

# fields
  fields:	~ {$In:entry $Out $Skip:1}
                  (/\/[^\n]+\n/ {$Wrt} |
                  word {$Wrt:$fn.$Ct} 
                  (/[\/A-Z]/ {$Not} ln {$App})+)+ ~

#indexing
 identification: ~ {$In:[fields c:identification] $Out}
                  'Identification ' cat_name ' ' cat_code {$Wrt} ~
  
 name: ~ {$In:[fields c:name] $Out}
		  word ' ' (word {$Uniq:$Itc} | /./ | punct)* ~

#HTML stuff
 h_identif: ~ {$In:[fields c:identification t:html] pre if:$ParInt:isTable $Fail}
            'Identification' {if:$isTable==0 $Rep:
                |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\"><font color=\"#000066\">
                |<b><i>$Ct</i></b></font></TD>
                |<TD bgcolor=\"#ffffff\">
                } / */
             ('BCCM_IHEM ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[bccm_ihem_ibrd p:{$rest $Ct}]}|
              'DSMZ_MUTZ ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                       $Rep:$Hlink:[dsmz_mutz_ibrd p:{$rest $Ct}]} |
              'ECACC_CELL ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[ecacc_cell_ibrd p:{$rest $Ct}]} |
              'ICLC ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[iclc_ibrd p:{$rest $Ct}]} |
              'ECACC_HLA ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[ecacc_hla_ibrd p:{$rest $Ct}]} |
              'ECACC_HYBRID ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[ecacc_hybrid_ibrd p:{$rest $Ct}]}| 
              'BCCM_LMG ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[bccm_lmg_ibrd p:{$rest $Ct}]} |
              'CABI_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cabi_bact_ibrd p:{$rest $Ct}]} |
              'CRBIP_CIP_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[crbip_cip_bact_ibrd p:{$rest $Ct}]} |
              'CRBIP_COSIB_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[crbip_cosib_bact_ibrd p:{$rest $Ct}]} |
              'PCC_CYANO ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[crbip_pcc_cyano_ibrd p:{$rest $Ct}]} |
              'CBS_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cbs_bact_ibrd p:{$rest $Ct}]} |
              'DSMZ_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[dsmz_bact_ibrd p:{$rest $Ct}]} |
              'NCIMB_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                       $Rep:$Hlink:[ncimb_bact_ibrd p:{$rest $Ct}]} |
              'NCCB_BACT ' word2 {$rest=$Ct.rep:[' ' to:'%20']
  	        $Rep:$Hlink:[nccb_bact_ibrd p:{$rest $Ct}]} |
              'BCCM_MUCL ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[bccm_mucl_ibrd p:{$rest $Ct}]} |
              'CBS_FIL ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cbs_fil_ibrd p:{$rest $Ct}]} |
              'CBS_YEAST ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cbs_yeast_ibrd p:{$rest $Ct}]}| 
              'CABI_FIL ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cabi_fil_ibrd p:{$rest $Ct}]} |
              'CABI_YEAST ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cabi_yeast_ibrd p:{$rest $Ct}]}| 
              'DSMZ_FUNGI ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[dsmz_fungi_ibrd p:{$rest $Ct}]} |
              'CRBIP_UMIP_FIL ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[crbip_umip_fil_ibrd p:{$rest $Ct}]} |
              'CRBIP_UMIP_YEAST ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[crbip_umip_yeast_ibrd p:{$rest $Ct}]} |
              'BCCM_GENECORNER ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[bccm_genecorner_ibrd p:{$rest $Ct}]} |
              'DSMZ_PLASMID ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[dsmz_plasmid_ibrd p:{$rest $Ct}]}| 
              'NCCB_PLASMID ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[nccb_plasmid_ibrd p:{$rest $Ct}]} |
              'DSMZ_PHAGES ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[dsmz_phages_ibrd p:{$rest $Ct}]} |
              'NCCB_PHAGES ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[nccb_phages_ibrd p:{$rest $Ct}]} |
              'NCIMB_PHAGES ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[ncimb_phages_ibrd p:{$rest $Ct}]} |
              'DSMZ_PLANT_CELL ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[dsmz_plant_cell_ibrd p:{$rest $Ct}]}| 
              'DSMZ_PLANT_VIRUSES ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[dsmz_plant_viruses_ibrd p:{$rest $Ct}]}| 
              'ECACC_DNA_PROBES ' word2 {$rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[ecacc_dna_probes_ibrd p:{$rest $Ct}]})~ 

  h_top:      ~ {$In:[fields c:identification t:html] pre if:$ParInt:isTable $Fail}
               word {$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_fields:    ~ {$In:[fields xc:{biblio_ref further_biblio} t:html]
                        pre if:$ParInt:isTable $Fail}
                word {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} word /.*/ {$Wrt:$Itc} ~

# definitions
  number:       ~ /[0-9]+/ ~
  ln:		~ /[^\n]*\n/ ~
  word:		~ /[0-9a-zA-Z_\\.\\?\/-]+/ ~
  word2:	~ /[ 0-9a-zA-Z_\\.\\?\/-]+/ ~
  word3:        ~ /[ A-Z0-9a-z.()-]+/ ~
  cat_name:	~ /[A-Z_]+/ ~
  cat_code:	~ /[A-Za-z0-9.\\(\\) \/_-]+/ ~
  punct:	~ /[ \t,;:\\(\\)\\.\\+\\*]+/ ~    
  punct4:	~ /[\t,;:\/\\+]+/ ~
}