#!/usr/bin/env icarus
# BCCM/LMG Bacteria 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
Infrasubspecific_names:inf_name
Organism_type:org_type
Other_collection_numbers:other_nos
Status:status
History:history
Isolated_from:isol_from
Geographic_origin:geo_origin
Conditions_for_growth:cond
Form_of_supply:supply
Serovar:serovar
Mutant:mutant
Genotype:genotype
Remarks:remarks
Applications:apps
Restrictions:rest
Other_names:other_names
}

$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)* ~

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

  name:		~ {$In:concat2 $Out}
		  word / /? (word2{$Wrt:[s:$StrRep:[s:$Ct r:"[\"|\.]" to:""]]}
                   | punct)*  ~

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

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

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

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

  other_names:	~ {$In:concat $Out}
		  word / /?
                  (/;/? / /? word2{$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\">
                      |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:"$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_lmg_namR p:{$rest $Ct}]} ~

  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\">
	     }/ */
	      (simpleword / ?/ number {$rest=$Ct.rep:[' ' to:'%20']
	                               $Rep:$Hlink:[bccm_lmgR p:{$rest $Ct}]}
	     ','? /[^;]/* ';'?)*~ 

  h_rest:    ~ {$In:[fields c:rest 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\">
	        }/ */ 
		(simpleword+  number? {$rest=$Ct.rep:[' ' to:'%20']
		  $Rep:$Hlink:[bccm_lmg_restR 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:"$Ct</TD></TR>"} ~

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

# definitions
  tag:          ~ word ':'?~
  ln:		~ /[^\n]*\n/ ~
  word:		~ /[0-9a-zA-Z_]+/ ('/' /[a-zA-Z0-9_]*/)* ~
  word2:        ~ /[ 0-9a-zA-Z_\/\\.\\+\\%\\*\\(\\)-]+/ ~
  punct:	~ /[ \t,;:\.\(\)\+\*-]+/ ~  
  punct2:	~ /[\t,;:\/\\+]+/ ~
  simpleword:	~ /[ a-zA-Z]+/ ~
  number:	~ /[0-9]+/ ~
}