# Syntax highlighting

Syntax highlighting is set up in the file kon.syn. Defining syntax highlighting for a filetype is mainly done by specifying for which file extensions the scheme should be activated, listing groups of keywords and the color each group should have, and perhaps certain other primitives such as how comments are defined, and which character are used to delimit words.

Kon can also define syntax highlighting using regular expressions.

In the definition for each filetype, you can also specify how code sections should be identified using regular expressions. The identified code sections will be shown in a drop-down list for fast navigation.

The layout of kon.syn is as follows:

    // Color definitions, set color and font attributes statements may appear
    // before any syntax definitions

    define color Blue = 0,0,255
    define color Cyan = 0,128,128
    define color LightGray = 128,128,128

    // ------------------
    // K syntax highlight

    name = "K"  // The name of this syntax highlighting scheme

    extensions = .k  // The extension(s) for which this scheme should be used

    sections = "^([:m]+)\\(", 1  // Regular expressions defining code sections in the file

    set caseinsensitive = no  // yes if all keywords are case insensitive

    literal = \  // Escape character

    set foreground = Blue  // All keywords defined after this should have it's
                           // foreground set to blue (RGB 0,0,255 above)

    delimitors = ",;:\"'[](){}-+="  // Delimitors separating words (apart from
                                    // white-spaces)

    // Blue keywords
    keyword = break, case, continue, default, do, else, for, if,
              return, switch, while

    set foreground = Cyan  // All keywords defined after this should have it's
                           // foreground set to cyan (RGB 0,128,128 above)

    eolword = #include     // A word where the color settings will extend to the
                           // end of the line

    set foreground = LightGray  // All keywords defined after this should have it's
                                // foreground set to LightGray
                                // (RGB 128,128,128 above)

    set fontattribute = italic  // All keywords defined after this should have
                                // an italic font

    eolcomment = "//"           // A comment to the end of line

    set fontattribute = normal  // Set the font back to normal

    pair = "'":"'", '"':'"'     // Strings declaration

    grep = (0x[0-9abcdef]+)     // A regular expression which in this case defines
                                // what is a hexadecimal value. Note that parts
                                // which should be highlighted must be defined
                                // as groups: (Enclosing in '('..')').

    // --------------
    // .syn highlight

    // Repeat as above for a different scheme
    .
    .
    .

## The following commands can be used in kon.syn:

- Define a color (Can appear anywhere)

          define color <COLORNAME> = <RED>, <GREEN>, <BLUE>

- Start a new syntax defintion

          name = "Scheme name"

- Define extensions using the syntax definition

          extensions = .ext1,.ext2, ..

- Define code sections

          sections = "regular expression 1", groupToUse 1,
                     "regular expression 2", groupToUse 2, . . .

  Each regular expression defines a code section to define. Following the regular expressions is a numeric value specifying which group in the regular expression is to be shown in the pull-down list.

  For an explanation of grouping in regular expression, see regular expressions.

  // Identify a K-function. The first group contains the function name sections = "^([:m]+)\\(", 1

- Set case sensitivity

          set caseinsensitive = yes/no

- Define the literal character.

          literal = <char>

- Set the foreground for the following keywords/syntax elements

          set foreground = <RGB color>/<Color definition>

- Set the background for the following keywords/syntax elements

          set background = <RGB color>/<Color definition>

- Set the font attribute for the following keywords/syntax elements

          set fontattribute = italic/bold/underscore/normal

- Declare a range of keywords

          keyword = word1, word2, ... wordn

- Define character sequence for comment to end of line

          eolcomment = "characters"

- Define a pair which encloses a range of characters in the code. Cannot extend to multiple lines.

          pair = "startcharacters", "endcharacters"

- Define a pair which encloses a range of characters in the code which can extend to multiple lines

          multilinepair = "startcharacters", "endcharacters"

- Define a comment pair which can extend to multiple lines

          multilinecomment = "startcharacters", "endcharacters"

- Define a set of word delimitors

          delimitors = "characters"

- Defines the literal character

          literal = character

- Defines a word which causes higlighting to extend to end of line

          eolword = word

- Defines a regular expressions definition for syntax highlighting.

          grep = "expression"

  Kon doesn't highlight the full expression found but only the parts that has been defined as a group (subexpression).

  Grep definitions in syntax highlighting does not extend over line breaks.

  // Highlight an XML tag including '<' and '>' but not its attributes. grep = "(<[:a]+):s[^>]*(>)"

- Set the following keywords to require a delimitor in front

          set requiresdelimfront = yes/no

- Set the following keywords to require a delimitor at end of word

          set requiresdelimend = yes/no

- Set the following keywords to require a delimitor at both ends

          set requiresdelim = yes/no