#!/usr/bin/env icarus
# BCCM//MUCL - (Agro)Industrial Fungi & Yeasts Collection - Syntax file
#
# 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
  Restrictions:restrictions
  Organism_type:org_type
  Name:name
  Status:status
  Misapplied_names:mis
  History:history
  Conditions_for_growth:cond
  Form_of_supply:supply
  Substrate:substrate
  Geographic_origin:origin
  Mutant:mutant
  Sexual_state:sex
  Literature:literature
  Enzyme_production:enzyme
  Applications:applications
  Metabolite_production:metabolites
  }

$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 space (word2{$Wrt} |punct2)* ~

  strX:		~ {$In:[fields c:{applications name mis org_type restrictions
                                  status history 
				  enzyme substrate origin sex literature supply
                                  mutant metabolites}] $Out}
		  word (str{$Uniq:$Itc}| /./ |punct)* ~ 

  concat2:      ~ {$In:[fields c:name] $Out}
                  /[^\n]+/ {$Wrt} '\n' (/[^\n]+/ {$App} '\n')* ~

  name:         ~ {$In:concat2 $Out}
                  'Name '
                  (word1 {$Wrt:[s:$StrRep:[s:$Ct r:"[\"|\.]" to:""]]}
                   | punct | number*) ~

  cond:	        ~ {$In:[fields c:cond] $Out}
		  word / /? (/, / | word3{$Uniq} | /./ | punct2)* ~

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

#HTML stuff...
 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></TD>
                     |</TR>
		     |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
                     |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                     |<TD bgcolor=\"#ffffff\">
		    } 
		    ':'? {$Rep:""} /.*/ {$Rep:"$Ct</TD></TR>"}  ~

  h_cond: ~ {$In:[fields c:cond 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\">
                }
	        ' '? word3 {$Ct.rep:['%' to:'_PC_']
                        $Ct.rep:['+' to:'_PL_']
                        $Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[bccm_muclR p:$Ct]}
		(', ' ( temp
                       | word3 {$Ct.rep:['%' to:'_PC_']
                        $Ct.rep:['+' to:'_PL_']
                        $Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[bccm_muclR p:$Ct]}))*  ~


   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\">
                      }
                     / */ (word1 {$r=$Ct.rep:['.' to: '']
                                  $p=$r.rep:[' ' to:'%20']
                                  $Rep:$Hlink:[bccm_mucl_namR p:{$p $Ct}]}
                           | word2 |punct) ~

 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:		~ /[0-9a-zA-Z_\/]+/ ~
  word1:        ~ /[A-Z][a-z]+[ ]*[a-zA-Z]*/ ~
  word2:	~ /[ 0-9a-zA-Z_:\\.\\(\\)\/-]+/ ~
  word3:        ~ /[ 0-9a-zA-Z_\/\\.\\+\\%-]+/ ~
  str:		~ /[a-zA-Z0-9&.'=\/\\%_-]+/ ~
  punct:	~ /[ \t,;:\\.\\(\\)\\+\\*-]+/ ~  
  punct2:	~ /[\t,;:\/\\+]+/ ~
  temp:         ~ (number /[ \/]/?)+ /[Cc]/ '.'? ~
  number:       ~ /[0-9]+/ ~
  space:        ~ /[\t ]/ ~
}