#!/usr/bin/env icarus
# BCCM/IHEM Fungi and Yeasts Catalogue - Syntax file [full catalogue]
#
# Version 2004.12.17.01
# Last Updated December 17, 2004
# Author: Domenico Marra & Francesca Piersigilli & Paolo Romano
# (c) CABRI 1999-2023

$fn={
Strain_number:strain_no
Other_collection_numbers:other_nos
Organism_type:org_type
Name:name
Conditions_for_growth:cond_for_growth
Race:race
Status:status
History:history
Form_of_supply:form
Sexual_state:sex_state
Serotype:serotype
Pathogenicity:patho
Isolated_by:isol_by
Applications:applications
Literature:literature
Restrictions:restrictions
Substrate:substrate
Determined_by:determined
Geographic_origin:geographic
}


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

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

 
#indexing
  strain_no:	~ {$In:[fields c:strain_no] $Out}
		  word ' ' (word2{$Wrt} |punct2)* ~

  strX:		~ {$In:[fields c:{org_type cond_for_growth race status history
                                  form sex_state serotype substrate patho 
			          isol_by determined applications literature
                                  restrictions geographic}] $Out}
		  word (str{$Uniq:$Itc} | /./ |punct)* ~

  name:      ~ {$In:[fields c:name] $Out}
                  word / / (word2{$Wrt} | punct2) ~

  other_nos:	~ {$In:[fields c:other_nos] $Out}
		  word / /? ( '-' | (word2{$Uniq} | / ?= /)* ) ~

# Prettifying the output

 h_top:      ~ {$In:[fields c:strain_no 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>
                     |</font></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_name:     ~ {$In:[fields c:name t:html] pre if:$ParInt:isTable $Fail}
               'Name' {if:$isTable==0 $Rep:
               |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\"><font color=\"#000066\">
               |<b><i> $Ct</i></b></font></TD>
               |<TD bgcolor=\"#ffffff\">
              } / */
             word2 {$rest=$Ct.rep:[' ' to:'%20']
            $Rep:$Hlink:[bccm_ihem_namR p:{$rest $Ct}]} ~
																			
  h_cond: ~ {$In:[fields c:cond_for_growth t:html] pre if:$ParInt:isTable $Fail}
          'Conditions_for_growth' {if:$isTable==0
	  $Rep:
              |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
	      |<font color=\"#000066\"><b><i>$Ct</i></b>
	      |</font></TD><TD bgcolor=\"#ffffff\">
	   }
           / ?/ word
           / ?/ word {$Rep:$Hlink:[bccm_ihemR p:{$Ct $Ct}]}
           (',' (word)*)*
           (';' / ?/ word
                / ?/ word {$Rep:$Hlink:[bccm_ihemR p:{$Ct $Ct}]}
                (',' (word)*)*)* ~

  h_fields: ~ {$In:[fields 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:""} /.*/ {$Rep:"$Ct</TD></TR>"}  ~

  t_fields: ~ {$In:[fields] $Out} tag /.*/ {$Wrt:$Itc} ~
 
# definitions
  tag:          ~ word ~
  ln:		~/[^\n]*\n/ ~
  word:		~/[a-zA-Z_0-9\/]+/ ~
  word2:	~/[ 0-9a-zA-Z_\\.\\(\\)\/-]+/ ~
  punct:	~/[ \t,;:\\.\\(\\)\\+\\*]+/ ~ 
  str:          ~/[a-zA-Z0-9&.;'=\/\\?\\(\\)\\+\\%_-]+/ ~
  punct2:	~ /[\t,;:\/\\+]+/ ~
}