#!/usr/bin/env icarus
# CBS Filamentous Fungi 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={
  Strain_number:strain_no
  Name:name
  Race:race
  Organism_type:org_type
  Restrictions:restrictions
  Other_collection_numbers:other_nos
  Status:status
  Literature:literature
  Sexual_state:sex_state
  Mutant:mutant
  Substrate:substrate
  Geographic_origin:origin
  History:history
  Enzyme_production:enzymes
  Pathogenicity:pathogenicity
  Metabolite_production:metabolites
  Misapplied_names:misapplied
  Conditions_for_growth:cond
  Form_of_supply:supply
  Applications:applications
}

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

  wordX:	~ {$In:[fields c:{name org_type race status literature
                                  applications mutant substrate origin
                                  pathogenicity history enzymes metabolites supply}] $Out}
		  word (word{$Uniq:$Itc} |punct)*  ~

  concat: 	~ {$In:[fields c:{misapplied other_nos}] $Out}
                  /[^\n]+/ {$Uniq:$Itc} '\n' (/[^\n]+/ {$App} '\n')* ~

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

 sex_state:	~ {$In:[fields c:sex_state] $Out}
		  word (str{$Wrt} |punct)*  ~

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

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

  restrictions: ~  {$In:[fields c:restrictions] $Out}
                  word / / 
                   ('No' |'HO' {$Wrt}| 'M' {$Wrt}  | word5 {$Wrt} | word4) ~

  misapplied:	~ {$In:[concat c:misapplied] $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\">
                     |This entry contains an HTML link to the reference
                     | database for synonyms of this catalogue.
                     |If there is no synonym data available, these links
                     |will be empty.<br><br>
                     |<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:[cbs_fungi_mediaR p:$Ct]}
                (', ' ( temp
                       | word3 {$Ct.rep:['%' to:'_PC_']
                        $Ct.rep:['+' to:'_PL_']
                        $Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[cbs_fungi_mediaR p:$Ct]}))*  ~

  h_rest: ~ {$In:[fields c:restrictions t:html] pre if:$ParInt:isTable $Fail} 
              'Restrictions' {if:$isTable==0 
                $Rep:
                 |<TR VALIGN=TOP><TD bgcolor=\"#ffffff\">
                 |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                 |<TD bgcolor=\"#ffffff\">
                } / /+
                 ('No'
		  | 'M' {$Rep:$Hlink:[cbs_fungi_restrictionsR p:{$Ct $Ct}]}
                  
		  | word5 {$Rep:$Hlink:[cbs_fungi_restrictionsR p:{$Ct $Ct}]}
		  |'HO' {$Rep:$Hlink:[cbs_fungi_restrictionsR p:{$Ct $Ct}]}) ~

h_lit:        ~ {$In:[fields c:literature 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\">
                       }
                 /[^\\[]*/
                  ('[PMID: ' pmid {$Rep:$Hlink:[pubmedCabriR p:{$Ct $Ct}]} ']')?
                  x{$Rep:"</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:[cbs_fil_namR p:{$Rest $Ct}]}
                  | 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} ~

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

# definitions
  tag:          ~ word ~
  ln:		~ /[^\n]*\n/ ~
  word:		~ /[0-9a-zA-Z_\/-]+/ ~
  word2:        ~ /[ 0-9a-zA-Z_\/\\.-]+/ ~
  word3:	~ /[ 0-9a-zA-Z_\/\\.\\+\\%]+/ ~
  word4:	~ /[ 0-9a-zA-Z_\/\\.\\+\\%\\*]+/ ~
  word5:        ~ /[A-Z][A-Z]?[0-9]/  /a?/ ~
  word6:        ~ /[ 0-9a-zA-Z_\\.\\(\\)\/]+/ ~
  str:		~ /[a-zA-Z0-9&'=\\+\\%\\._-]+/ ~
  punct:	~ /[ \t,;:\\.\\(\\)\\+\\*]+/ ~  
  punct2:	~ /[\t,;:\\(\\)\\*]+/ ~  
  punct4:	~ /[\t,;:\/\\+]+/ ~
  number:	~ /[0-9.]+/ ~
  temp:         ~ (number /[ \/]/?)+ /[Cc]/ '.'? ~
  pmid:         ~ /[0-9]+/ ~
}