<?xml version="1.0"?>

<!DOCTYPE MODE SYSTEM "xmode.dtd">

<!--

Author: Jaco de Groot
Version: 2.2 20070213

Comma Separated Values specification used for this mode:

A file containing table data where the fields are sperated by commas. Fields
containing commas (,) or newlines must be quoted (surrounded by quotes (")).
Quotes in quoted fields must be escaped with two quotes.

Highlighted are:
- Even columns
- Commas seperating values
- Quotes surrounding values
- Escaped quotes are highlighted.

It is also possible that semicolons are used instead of commas. Therefor the
first rules check if the first separator found is a comma or a semicolon and
then switch to the comma or semicolon rules.

-->

<MODE>

  <!-- Switch rules -->

  <RULES>
    <SEQ TYPE="MARKUP" DELEGATE="ODD_QUOTED" AT_LINE_START="TRUE">"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN_QUOTED">,"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN_QUOTED">;"</SEQ>
    <EOL_SPAN_REGEXP TYPE="MARKUP" HASH_CHAR="," DELEGATE="COMMA_LAST_COLUMN">,(?=[^,]*$)</EOL_SPAN_REGEXP>
    <EOL_SPAN_REGEXP TYPE="MARKUP" HASH_CHAR=";" DELEGATE="SEMICOLON_LAST_COLUMN">;(?=[^;]*$)</EOL_SPAN_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN">,</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN">;</SEQ>
  </RULES>

  <RULES SET="ODD_QUOTED">
    <SEQ TYPE="MARKUP" DELEGATE="ODD_QUOTED">""</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="COMMA_MAIN">"(?=,[^"][^,]*$)</SEQ_REGEXP>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="SEMICOLON_MAIN">"(?=;[^"][^;]*$)</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN_QUOTED">","</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN_QUOTED">";"</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;," DELEGATE="COMMA_MAIN">",$</SEQ_REGEXP>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;;" DELEGATE="SEMICOLON_MAIN">";$</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN">",</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN">";</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="MAIN">"$</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="EVEN">"</SEQ>
  </RULES>

  <RULES DEFAULT="COMMENT1" SET="EVEN">
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_ODD_QUOTED">,"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_ODD_QUOTED">;"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_MAIN">,</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_MAIN">;</SEQ>
  </RULES>

  <RULES DEFAULT="COMMENT1" SET="EVEN_QUOTED">
    <SEQ TYPE="MARKUP" DELEGATE="EVEN_QUOTED">""</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_ODD_QUOTED">","</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_ODD_QUOTED">";"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_MAIN">",</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_MAIN">";</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="MAIN">"</SEQ>
  </RULES>

  <!-- Comma rules -->

  <RULES SET="COMMA_MAIN">
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_ODD_QUOTED" AT_LINE_START="TRUE">"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN_QUOTED">,"</SEQ>
    <EOL_SPAN_REGEXP TYPE="MARKUP" HASH_CHAR="," DELEGATE="COMMA_LAST_COLUMN">,(?=[^,]*$)</EOL_SPAN_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN">,</SEQ>
  </RULES>

  <RULES SET="COMMA_ODD_QUOTED">
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_ODD_QUOTED">""</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="COMMA_MAIN">"(?=,[^"][^,]*$)</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN_QUOTED">","</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;," DELEGATE="COMMA_MAIN">",$</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN">",</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="COMMA_MAIN">"$</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN">"</SEQ>
  </RULES>

  <RULES SET="COMMA_EVEN" DEFAULT="COMMENT1">
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_ODD_QUOTED">,"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_MAIN">,</SEQ>
  </RULES>

  <RULES SET="COMMA_EVEN_QUOTED" DEFAULT="COMMENT1">
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_EVEN_QUOTED">""</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_ODD_QUOTED">","</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_MAIN">",</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="COMMA_MAIN">"</SEQ>
  </RULES>

  <RULES SET="COMMA_LAST_COLUMN" DEFAULT="COMMENT1">
  </RULES>

  <!-- Semicolon rules -->

  <RULES SET="SEMICOLON_MAIN">
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_ODD_QUOTED" AT_LINE_START="TRUE">"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN_QUOTED">;"</SEQ>
    <EOL_SPAN_REGEXP TYPE="MARKUP" HASH_CHAR=";" DELEGATE="SEMICOLON_LAST_COLUMN">;(?=[^;]*$)</EOL_SPAN_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN">;</SEQ>
  </RULES>

  <RULES SET="SEMICOLON_ODD_QUOTED">
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_ODD_QUOTED">""</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="SEMICOLON_MAIN">"(?=;[^"][^;]*$)</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN_QUOTED">";"</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;;" DELEGATE="SEMICOLON_MAIN">";$</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN">";</SEQ>
    <SEQ_REGEXP TYPE="MARKUP" HASH_CHAR="&quot;" DELEGATE="SEMICOLON_MAIN">"$</SEQ_REGEXP>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN">"</SEQ>
  </RULES>

  <RULES SET="SEMICOLON_EVEN" DEFAULT="COMMENT1">
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_ODD_QUOTED">;"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_MAIN">;</SEQ>
  </RULES>

  <RULES SET="SEMICOLON_EVEN_QUOTED" DEFAULT="COMMENT1">
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_EVEN_QUOTED">""</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_ODD_QUOTED">";"</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_MAIN">";</SEQ>
    <SEQ TYPE="MARKUP" DELEGATE="SEMICOLON_MAIN">"</SEQ>
  </RULES>

  <RULES SET="SEMICOLON_LAST_COLUMN" DEFAULT="COMMENT1">
  </RULES>

</MODE>
