#!/usr/bin/env icarus
# DSMZ Fungi Synonyms 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={
  Name:name
  Synonyms:syn
  Alternative_state:alt_state
}

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

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

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

  concat2: 	~ {$In:[fields c:alt_state] $Out}
                  /[^\n]+/ {$Wrt} '\n' (/[^\n]+/ {$App} '\n')* ~
  
  syn:		~ {$In:concat $Out}
		  word / /?
                  (/ /? word2{$Wrt:[s:$StrRep:[s:$Ct r:"[\/|\.|-]" to:""]]}
                   | /;/?  /,/?  /[^;]/+)* ~

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

#HTML stuff...
 h_top:      ~ {$In:[fields c:name 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_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_\/]+/ ~ 
  word2:	~/[ 0-9a-zA-Z_:\\.\\(\\)\/-]+/ ~
  punct:	~ /[ \t]+/ ~
}