#!/usr/bin/env icarus
# CRBIP_CIP Bacteria Catalogue - Syntax file
# Version 2009.07.23.01
# Last Updated July 23, 2009
# change: renamed from CIP_BACT to CRBIP_CIP_BACT
# Author: Paolo Romano
# (c) CABRI 1999-2023

$fn={
  Strain_number:strain_no
  Other_collection_numbers:other_nos
  Name:name
  Organism_type:org_type
  Restrictions:restrictions
  Infrasubspecific_names:inf_name
  Status:status
  History:history
  Isolated_from:isol_from
  Geographic_origin:geo_origin
  Literature:lit
  Conditions_for_growth:cond
  Form_of_supply:supply
  Serovar:serovar
}

$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:0}
                  (/\/[^\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)* ~

  name:		~ {$In:[fields c:name] $Out}
                  word / /* word2{$Wrt $Ct.rep:['.' to:'']}
                  (',' (word{$Wrt}|punct3)*)*  ~

  strX:		~ {$In:[fields c:{restrictions org_type name status 
				  history cond supply isol_from geo_origin 
				  inf_name serovar}] $Out}
		  word (str{$Uniq:$Itc}| /./ |punct)* ~ 

  lit:          ~ {$In:[fields c:lit] $Out $Skip:0}
                  word (parola {$Uniq:$Itc}
                       |numero {$Uniq:$Itc})* ~

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

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

  oth_names:	~ {$In:concat2 $Out}
		  word / /?
                  (/;/? / /? word3 {$Wrt:[s:$StrRep:[s:$Ct r:"[\"|\.]" to:""]]}
                   | /,/ /[^;]/+)* ~

  namesort:     ~ {$In:[fields c:{name}] $Out}
                  'Name' /[^(\n]+/ {$Wrt} ~

#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\">
                }
               parola ' '?
               (numero {$Rest=$Ct.rep:[' ' to:'%20']
                        $Rep:$Hlink:[crbip_cip_bact_mediaR p:{$Rest $Ct}]})* ~

 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
  parola:       ~/[^0-9]+/ ~
  numero:       ~/[0-9]+/ ~
  tag:          ~ word ':'?~
  ln:		~/[^\n]*\n/ ~
  word:		~/[0-9a-zA-Z_\/]+/ ~
  word2:        ~/[ 0-9a-zA-Z_\/\\.-]+/ ~
  letters:      ~/[ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü§øÀÃÕÿY:ÂÊÁËÈÍÎÏÓÔÒÚÛÙa-zA-Z0-9&=\/\\%_]+/ ~  
  str:          ~letters ~
  punct:	~ /[ \t,;:\\.\\(\\)\\+\\*]+/ ~  
  punct2:	~ /[\t,;:\/\\+]+/ ~
  punct3:       ~ /[^a-zA-Z0-9]+/ ~ 
  word3:	~/[ 0-9a-zA-Z_\\"\\.\\(\\)\/\\*-]+/ ~
}