#################################################################################
#                                                                               #
#                       A d i e   S y n t a x   F i l e                         #
#                                                                               #
#################################################################################
# Copyright (C) 2004,2017 by Jeroen van der Zijp.   All Rights Reserved.        #
#################################################################################
# This program is free software; you can redistribute it and/or modify          #
# it under the terms of the GNU General Public License as published by          #
# the Free Software Foundation; either version 2 of the License, or             #
# (at your option) any later version.                                           #
#                                                                               #
# This program is distributed in the hope that it will be useful,               #
# but WITHOUT ANY WARRANTY; without even the implied warranty of                #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 #
# GNU General Public License for more details.                                  #
#                                                                               #
# You should have received a copy of the GNU General Public License             #
# along with this program; if not, write to the Free Software                   #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    #
#################################################################################

#
# Notes:
#
# - Please send addition changes or additions to this file to:
#
#       jeroen@fox-toolkit.com
#
# - Use bracketed patterns with sub-patterns instead of complex
#   regular expressions; complex regular expressions can recurse
#   deeply, which can be very expensive.
#
# - Rule name is used as registry key; should be unique if
#   different colors are desired!
#
# - A backslash "\" escapes only if followed by '"'; otherwise its
#   just a backslash.
#
# - Put this file in some directory in $PATH and Adie will find it.
#
# - If default rule (rule with no patterns at all) is used as parent
#   of all the other rules, then Adie will show colors different from
#   the default editor settings. Colors of a child rule are inherited
#   from its parent rule.
#
# - The "style" keyword can be used to give a syntactical element a color
#   when no color preference has been given yet by the user.
#   If the user sets colors for a syntactical element, those will take
#   precedence over the built-in ones.
#   Not all syntactical elements have been provided a color, on purpose;
#   some patterns are uncommon and not all users may want to colorize them.
#
# - The "group" keyword can be used to tie together families of programming
#   languages, in terms of their color schemes. For instance C++, C, C# and
#   Java have been given the same group name, allowing them to have similar
#   color schemes.
#   Languages not explicitly given a group name are colored by themselves.
#
# - The patterns selected to color source are determined by (1) matching file
#   extensions to wild-card match against the list of file extensions, or
#   (2) reading a fragment of the file and searching it for a regular expression.
#

#################################################################################

# Adie editor syntax-file syntax coloring (yup!)
language "Adie Syntax"
  filesmatch "*.stx"
  contextlines 1
  rule "Comment"
    openpattern     "#"
    closepattern    "$"
    style           "darkgreen"
  end
  rule "Keyword"
    pattern         "\<(language|filesmatch|contentsmatch|delimiters|contextlines|contextchars|rule|group|end|pattern|openpattern|closepattern|stoppattern|style|autoindent|wrapwidth|tabwidth|wordwrap|expandtabs)\>"
    style           "red"
  end
  rule "String"
    openpattern     "\""
    closepattern    "\""
    stoppattern     "$"
    style           "blue"
    rule "Escape"
      pattern       "\\\""
      style         "red"
    end
  end
end


# FOX Registry syntax coloring
language "Registry"
  filesmatch "*.ini,*.INI,*rc"
  contentsmatch  "^\s*?\[[^]]*?\]"
  contextlines 1
  rule "Comment"
    openpattern   "^\s*?[#;]"
    closepattern  "$"
    style         "darkgreen"
  end
  rule "RegistrySection"
    pattern   "^\s*?\[[^]]*?\]\s*?$"
    style     "orange"
  end
  rule "RegistryEntry"
    openpattern   "^\s*?[^[=#;\s][^=]*?(?==)"
    closepattern  "$"
    stoppattern   "$"
    style         "darkgreen"
    rule "RegistryEquals"
      openpattern   "\s*?=\s*?"
      closepattern  "$"
      stoppattern   "$"
      style         "red"
      rule "RegistryString"
        openpattern   "\""
        closepattern  "\""
        stoppattern   "$"
        style         "blue"
        rule "OctalEscape"
          pattern     "\\\d+"
          style       "carrot"
        end
        rule "HexEscape"
          pattern     "\\x\h+"
          style       "carrot"
        end
        rule "ControlEscape"
          pattern     "\\."
          style       "carrot"
        end
      end
      rule "RegistryValue"
        pattern   ".*?$"
        style     "blue"
      end
    end
  end
end


# C++ programming language
language "C++"

  # File patterns for this language mode
  filesmatch "*.C,*.cpp,*.cc,*.cxx,*.c++,*.cu,*.H,*.hpp,*.hh,*.hxx,*.h++,*.h,*.cuh"
  contentsmatch "[Cc]\+\+"

  contextlines 1

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"

  # All C-like languages use similar color schemes
  group "C-Like"

  # Merge
  rule "MergeMine"
    openpattern   "^<<<<<<<.*?\n"
    closepattern  "(?=^=======\n)"
  end
  rule "MergeDivision"
    pattern     "^=======\n"
  end
  rule "MergeYours"
    openpattern   "(?<=^=======\n)"
    closepattern  "^>>>>>>>.*?\n"
  end

  # C++ style comment
  rule "CPPDocComment"
    openpattern   "///(?!/)"
    closepattern  "$"
    style         "darkgreen"
  end

  # C++ style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # C style comment
  rule "CDocComment"
    openpattern   "/\*\*(?=\s)"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # C style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "carrot"
    end
    rule "Format"
      pattern     "%\*?(\d+\$)?['#0 +-]*(\*(\d+\$)?|\d*)(\.(\*(\d+\$)?|\d*))?(ll|l|hh|h|L|q|t|z)?([dDbiouxXeEfFgGaAcspn]|\[.*?\])"
      style       "fuchsia"
    end
  end

  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    stoppattern  "$"
    style       "blue"
    rule "OctalEscape"
      pattern "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern "\\."
      style       "carrot"
    end
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*(?=#)"
    closepattern "$"
    style        "blue"

    # PP blocked
    rule "PPBlocked"
      openpattern   "#if\s+0"
      closepattern  "#endif"
      style         "gray"
      rule "PPSubblock"
        openpattern   "/\*"
        closepattern  "\*/"
        style         "gray"
      end
      rule "PPSubblock"
        openpattern   "//"
        closepattern  "$"
        style         "gray"
      end
      rule "PPSubblock"
        openpattern   "#if"
        closepattern  "#endif"
        style         "gray"
        rule "PPSubblock"
          openpattern   "#if"
          closepattern  "#endif"
          style         "gray"
          rule "PPSubblock"
            openpattern   "#if"
            closepattern  "#endif"
            style         "gray"
          end
        end
      end
    end

    # Continuation
    rule "PreprocessorContinuation"
      pattern "\\\n"
      style   "blue"
    end

    # Comments
    rule "CComment"
      openpattern   "/\*"
      closepattern  "\*/"
      style         "darkgreen"
    end
    rule "CPPComment"
      openpattern   "//"
      closepattern  "$"
      style         "darkgreen"
    end
  end

  # Special macros
  rule "FOXMacro"
    pattern     "\<(FXAPI|FXDEFMAP|FXTRACE|FXMAPFUNCS|FXMAPFUNC|FXIMPLEMENT|FXIMPLEMENT_ABSTRACT|FXDECLARE|FXDECLARE_ABSTRACT|FXMAPTYPES|FXMAPTYPE|FXMETACLASS|FXRGBA|FXRGB|FXREDVAL|FXGREENVAL|FXBLUEVAL|FXALPHAVAL|FXASSERT|FXSELID|FXSELTYPE|FXSEL|FXMINMAX|FXMIN3|FXMIN4|FXMIN|FXMAX3|FXMAX4|FXMAX|FXSWAP|FXCLAMP|FXABS|FXSGNZ|FXSGN|FXSGNX|FXLERP|ARRAYNUMBER|STRUCTOFFSET|CONTAINER|__likely|__unlikely|__threadlocal|__noreturn|__prefetchw|__prefetch|__restrict|constructElms|destructElms|copyElms|moveElms|swapElms|equalElms|fillElms|clearElms|allocElms|callocElms|dupElms|resizeElms|freeElms|construct|destruct)\>"
  end

  rule "FOXType"
    pattern     "\<(FXuchar|FXschar|FXwchar|FXnchar|FXchar|FXbool|FXushort|FXshort|FXuint|FXint|FXhalf|FXfloat|FXdouble|FXulong|FXlong|FXival|FXuval|FXptr|FXColor|FXPixel|FXTime|FXString)\>"
  end

  rule "Keyword"
    pattern     "\<(alignas|alignof|and_eq|and|asm|auto|bitand|bitor|break|case|catch|class|compl|constexpr|const_cast|const|continue|decltype|default|delete|do|dynamic_cast|else|enum|explicit|export|extern|final|for|friend|goto|if|inline|mutable|namespace|new|noexcept|not_eq|not|nullptr|operator|or_eq|or|override|private|protected|public|register|reinterpret_cast|return|sizeof|static_assert|static_cast|static|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|using|virtual|volatile|while|xor_eq|xor|true|false|maybe)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<((\.\d+([eE][+-]?\d+)?|\d+\.\d*([eE][+-]?\d+)?|\d+[Ee][+-]?\d+|0[Xx]\.\h+[Pp][+-]?\d+|0[Xx]\h+\.\h*[Pp][+-]?\d+|0[Xx]\h+[Pp][+-]?\d+)[LlFfQq]?|(0[xX]\h+|0[0-7]*|[1-9]\d*)[Uu]?[Ll]{0,2})\>"
    style       "blue"
  end

  rule "Type"
    pattern     "\<(unsigned|signed|int|short|long|float|double|bool|void|char16_t|char32_t|char|wchar_t)\>"
    style       "blue"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|\+\+|\+=|\+|--|-=|->\*|->|-|==|=|&&|&=|&|\|\||\|=|\||\^=|\^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%|\?|:|\.\.\.|\.|;|,)"
    style       "red"
  end
end


# C programming language
language "C"

  # File patterns for this language mode
  filesmatch "*.c,*.h"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"

  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # Merge
  rule "MergeMine"
    openpattern   "^<<<<<<<.*?\n"
    closepattern  "(?=^=======\n)"
  end
  rule "MergeDivision"
    pattern     "^=======\n"
  end
  rule "MergeYours"
    openpattern   "(?<=^=======\n)"
    closepattern  "^>>>>>>>.*?\n"
  end

  # C style comment
  rule "CDocComment"
    openpattern   "/\*\*(?=\s)"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # C style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # C++ style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "carrot"
    end
    rule "Format"
      pattern     "%\*?(\d+\$)?['#0 +-]*(\*(\d+\$)?|\d*)(\.(\*(\d+\$)?|\d*))?(ll|l|hh|h|L|q|t|z)?([dDbiouxXeEfFgGaAcspn]|\[.*?\])"
      style       "fuchsia"
    end
  end

  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    stoppattern  "$"
    style        "blue"
    rule "OctalEscape"
      pattern "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern "\\."
      style       "carrot"
    end
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*(?=#)"
    closepattern "$"
    style        "blue"

    # PP blocked
    rule "PPBlocked"
      openpattern   "#if\s+0"
      closepattern  "#endif"
      style         "gray"
      rule "PPSubblock"
        openpattern   "/\*"
        closepattern  "\*/"
        style         "gray"
      end
      rule "PPSubblock"
        openpattern   "//"
        closepattern  "$"
        style         "gray"
      end
      rule "PPSubblock"
        openpattern   "#if"
        closepattern  "#endif"
        style         "gray"
        rule "PPSubblock"
          openpattern   "#if"
          closepattern  "#endif"
          style         "gray"
          rule "PPSubblock"
            openpattern   "#if"
            closepattern  "#endif"
            style         "gray"
          end
        end
      end
    end

    # Continuation
    rule "PreprocessorContinuation"
      pattern "\\\n"
      style   "blue"
    end

    # Comments
    rule "CComment"
      openpattern   "/\*"
      closepattern  "\*/"
      style         "darkgreen"
    end
    rule "CPPComment"
      openpattern   "//"
      closepattern  "$"
      style         "darkgreen"
    end
  end

  rule "Keyword"
    pattern     "\<(for|while|if|else|do|struct|enum|union|switch|case|default|return|break|continue|goto|static|volatile|const|auto|register|inline|extern)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<((\.\d+([eE][+-]?\d+)?|\d+\.\d*([eE][+-]?\d+)?|\d+[Ee][+-]?\d+|0[Xx]\.\h+[Pp][+-]?\d+|0[Xx]\h+\.\h*[Pp][+-]?\d+|0[Xx]\h+[Pp][+-]?\d+)[LlFfQq]?|(0[xX]\h+|0[0-7]*|[1-9]\d*)[Uu]?[Ll]{0,2})\>"
    style       "blue"
  end

  rule "Type"
    pattern     "\<(unsigned|signed|int|char|short|long|float|double|bool|complex|void|wchar_t)\>"
    style       "blue"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|\+\+|\+=|\+|--|-=|->\*|->|-|==|=|&&|&=|&|\|\||\|=|\||\^=|\^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%|\?|:|\.\.\.|\.|;|,)"
    style       "red"
  end
end


# Fortran Programming Language
language "Fortran"

  # File patterns for this language mode
  filesmatch "*.f,*.F,*.f90,*.F90,*.interface,*.INTERFACE"

  contextlines 1

  # Word delimiters
  delimiters "~.,/\`'!@$%^&*()-=+{}|[]\":;<>?"

  # Merge
  rule "MergeMine"
    openpattern   "^<<<<<<<.*?\n"
    closepattern  "(?=^=======\n)"
  end
  rule "MergeDivision"
    pattern     "^=======\n"
  end
  rule "MergeYours"
    openpattern   "(?<=^=======\n)"
    closepattern  "^>>>>>>>.*?\n"
  end

  # Comment
  rule "Comment"
    openpattern   "!|^C|^\*"
    closepattern  "$"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # Decimal number
  rule "Number"
    pattern     "(([bBoOzZ](('\h+')|(\"\h+\")))|(((\.\d+)|(\d+(\.\d*)?))([eEdD][-+]?\d+)?)|(?i\.true\.|\.false\.))(_\d)?"
    style       "blue"
  end

  # String
  rule "String"
    openpattern   "'"
    closepattern  "'"
    stoppattern   "$"
    style         "blue"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
  end

  # Types
  rule "Types"
    pattern     "\<(?iINTEGER|REAL|COMPLEX|DOUBLE *?PRECISION|CHARACTER|LOGICAL|TYPE|END *?TYPE)\>"
    style       "blue"
  end

  # Attribute
  rule "Attribute"
    pattern     "\<(?iPARAMETER|ALLOCATABLE|DIMENSION|EXTERNAL|INTENT *?(IN|OUT|INOUT)|INTRINSIC|OPTIONAL|POINTER|SAVE|TARGET|PRIVATE|PUBLIC|KIND|IMPLICIT( *?NONE)?|COMMON|NAMELIST|EQUIVALENCE|DATA|SEQUENCE)\>"
    style       "blue"
  end

  # Reserved keywords
  rule "Keyword"
    pattern     "\<(?iINCLUDE|IF|THEN|ELSE *?IF|ELSE|END *?IF|SELECT *?CASE|CASE|DEFAULT|END *?SELECT|DO *?WHILE|DO|END *?DO|CYCLE|CONTINUE|GO *?TO|MODULE|CONTAINS|USE|ONLY|END *?MODULE|SUBROUTINE|END *?SUBROUTINE|PROGRAM|END *?PROGRAM|INTERFACE|END *?INTERFACE|FUNCTION|END *?FUNCTION|EXIT|CALL|RETURN|RECURSIVE|WHERE|ELSE *?WHERE|END *?WHERE|FORALL|END *?FORALL|END)\>"
    style       "red"
  end

  # Operators
  rule "Operator"
    pattern     "(?i\.AND\.|\.OR\.|\.NOT\.|\.EQV\.|\.NEQV\.|\.EQ\.|\.NE\.|\.LT\.|\.LE\.|\.GT\.|\.GE\.|<=|<|>=|>|==|/=|%|\*\*|\*|\+|\-|/|=|\(|\)|:|,|//)"
    style       "red"
  end

  # Identifiers
  rule "Identifier"
    pattern     "\<(\l[\l\d_]*)\>"
  end
end


# Matlab language
language "Matlab"

  # File patterns for this language mode
  filesmatch "*.m"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # Line comment
  rule "LineComment"
    openpattern   "%"
    closepattern  "$"
    style         "darkgreen"
  end

  # Multiline comment
  rule "MultiLineComment"
    openpattern   "%\{"
    closepattern  "%\}"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\'"
    closepattern  "\'"
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "carrot"
    end
  end

  rule "Keyword"
    pattern     "\<(break|case|catch|continue|else|elseif|end|for|function|global|if|otherwise|persistent|return|switch|try|while)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<(((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)[ij]?\>"
    style       "blue"
  end

  rule "Operator"
    pattern     "(\+|-|\.\*|\.\/|\.\\|:|\.\^|\.'|\'|\*|\/|\\|\^|==|=|<=|<|>=|>|~=)"
    style       "red"
  end
end


# Java programming language
language "Java"

  # File patterns for this language mode
  filesmatch "*.java"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # Merge
  rule "MergeMine"
    openpattern   "^<<<<<<<.*?\n"
    closepattern  "(?=^=======\n)"
  end
  rule "MergeDivision"
    pattern     "^=======\n"
  end
  rule "MergeYours"
    openpattern   "(?<=^=======\n)"
    closepattern  "^>>>>>>>.*?\n"
  end

  # Line comment
  rule "LineComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
  end

  # Multiline comment
  rule "MultiLineComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "carrot"
    end
  end


  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    style        "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern "\\."
      style       "carrot"
    end
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*#"
    closepattern "$"
    style        "blue"
    rule "PreprocessorContinuation"
      pattern    "\\\n"
      style      "blue"
    end
  end

  rule "Keyword"
    pattern     "\<(abstract|default|if|private|this|do|implements|protected|throw|break|import|public|throws|else|instanceof|return|transient|case|extends|try|catch|final|interface|static|finally|strictfp|volatile|class|native|super|while|const|for|new|switch|continue|goto|package|synchronized|null)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|F|f|D|d)?\>"
  end

  rule "Type"
    pattern     "\<(boolean|double|int|short|void|char|float|long|byte)\>"
    style       "red"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|==|=|>>>=|>>>|>>=|>>|>=|>|<|<<=|<<|<=|!=|!|~|&&|\|\||\|=|\||\+\+|\+=|\+|--|-=|-|\*=|\*|/=|/|&=|&|\^=|\^|%=|%|\?|:)"
    style       "red"
  end
end


# C# programming language
language "C#"

  # File patterns for this language mode
  filesmatch "*.cs"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # Merge
  rule "MergeMine"
    openpattern   "^<<<<<<<.*?\n"
    closepattern  "(?=^=======\n)"
  end
  rule "MergeDivision"
    pattern     "^=======\n"
  end
  rule "MergeYours"
    openpattern   "(?<=^=======\n)"
    closepattern  "^>>>>>>>.*?\n"
  end

  # Line comment
  rule "LineComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
  end

  # Multiline comment
  rule "MultiLineComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "carrot"
    end
  end


  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "carrot"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "carrot"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "carrot"
    end
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*#"
    closepattern "$"
    style        "blue"
    rule "PreprocessorContinuation"
      pattern    "\\\n"
      style      "blue"
    end
  end

  rule "Keyword"
    pattern     "\<(abstract|base|break|case|catch|checked|class|const|continue|default|delegate|do|else|enum|event|explicit|extern|false|finally|fixed|for|foreach|goto|if|implicit|in|interface|internal|lock|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sealed|sizeof|stackalloc|static|struct|switch|this|throw|true|try|typeof|unchecked|unsafe|using|virtual|while|is|as)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu|F|f|D|d|M|m)?\>"
    style       "blue"
  end

  rule "Type"
    pattern     "\<(bool|byte|double|float|int|sbyte|short|void|ushort|long|uint|ulong|char|string|decimal)\>"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|\+\+|\+=|\+|--|-=|->\*|->|-|==|=|&&|&=|&|\|\||\|=|\||\^=|\^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%|\?|:)"
    style       "red"
  end
end


# GLSL shading language
language "GLSL"

  # File patterns for this language mode
  filesmatch "*.frag,*.vert,*.glsl"
  contentsmatch "\AGLSL"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # C++ style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
  end

  # C style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*#"
    closepattern "$"
    style        "blue"
    rule "PreprocessorContinuation"
      pattern    "\\\n"
      style      "blue"
    end
  end

  rule "Keyword"
    pattern     "\<(if|else|for|while|do|switch|case|default|discard|return|break|continue|struct)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
    style       "blue"
  end

  rule "Type"
    pattern     "\<(void|bool|int|uint|atomic_uint|float|double)\>"
  end

  rule "Vector"
    pattern     "\<(vec2|vec3|vec4|dvec2|dvec3|dvec4|bvec2|bvec3|bvec4|ivec2|ivec3|ivec4|uvec2|uvec3|uvec4)\>"
  end

  rule "Matrix"
    pattern     "\<(mat2|mat3|mat4|mat2x2|mat2x3|mat2x4|mat3x2|mat3x3|mat3x4|mat4x2|mat4x3|mat4x4|dmat2|dmat3|dmat4|dmat2x2|dmat2x3|dmat2x4|dmat3x2|dmat3x3|dmat3x4|dmat4x2|dmat4x3|dmat4x4)\>"
  end

  rule "Sampler"
    pattern     "\<(sampler1D|image1D|sampler2D|image2D|sampler3D|image3D|samplerCube|imageCube|sampler2DRect|image2DRect|sampler1DArray|image1DArray|sampler2DArray|image2DArray|samplerBuffer|imageBuffer|sampler2DMS|image2DMS|sampler2DMSArray|image2DMSArray|samplerCubeArray|imageCubeArray|sampler1DShadow|sampler2DShadow|sampler2DRectShadow|sampler2DArrayShadow|sampler1DArrayShadow|sampler2DArrayShadow|samplerCubeShadow|samplerCubeArrayShadow|isampler1D|iimage1D|isampler2D|iimage2D|isampler3D|iimage3D|isamplerCube|iimageCube|isampler2DRect|iimage2DRect|isampler1DArray|iimage1DArray|isampler2DArray|iimage2DArray|isamplerBuffer|iimageBuffer|isampler2DMS|iimage2DMS|isampler2DMSArray|iimage2DMSArray|isamplerCubeArray|iimageCubeArray|usampler1D|uimage1D|usampler2D|uimage2D|usampler3D|uimage3D|usamplerCube|uimageCube|usampler2DRect|uimage2DRect|usampler1DArray|uimage1DArray|usampler2DArray|uimage2DArray|usamplerBuffer|uimageBuffer|usampler2DMS|uimage2DMS|usampler2DMSArray|uimage2DMSArray|usamplerCubeArray|uimageCubeArray)\>"
  end

  rule "Qualifier"
    pattern     "\<(const|in|out|inout|attribute|uniform|varying|invariant|coherent|volatile|restrict|readonly|writeonly|centroid|sample|flat|noperspective|smooth|patch|layout)\>"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|\+\+|\+=|\+|--|-=|-|==|=|&&|\|\||\^=|\^|<=|<|>=|>|!=|!|\*=|\*|/=|/)"
    style       "red"
  end

  rule "Predefined"
    pattern     "\<(gl_Position|gl_PointSize|gl_ClipVertex|gl_Color|gl_Normal|gl_Vertex|gl_MultiTexCoord0|gl_MultiTexCoord1|gl_MultiTexCoord2|gl_MultiTexCoord3|gl_MultiTexCoord4|gl_MultiTexCoord5|gl_MultiTexCoord6|gl_MultiTexCoord7|gl_FogCoord|gl_FrontColor|gl_BackColor|gl_FrontSecondaryColor|gl_BackSecondaryColor|gl_TexCoord|gl_FogFragCoord|gl_SecondaryColor|gl_FragCoord|gl_FrontFacing|gl_FragColor|gl_FragDepth|gl_MaxLights|gl_MaxClipPlanes|gl_MaxTextureUnits|gl_MaxTextureCoordsARB|gl_MaxVertexAttributesGL2|gl_MaxVertexUniformFloatsGL2|gl_MaxVaryingFloatsGL2|gl_MaxVertexTextureUnitsGL2|gl_MaxFragmentTextureUnitsGL2|gl_MaxFragmentUniformFloatsGL2|gl_ModelViewMatrix|gl_ProjectionMatrix|gl_ModelViewProjectionMatrix|gl_NormalMatrix|gl_TextureMatrix|gl_MaxTextureCoordsARB|gl_NormalScale|gl_DepthRange|gl_ClipPlane|gl_MaxClipPlanes|gl_Point|gl_FrontMaterial|gl_BackMaterial|gl_LightSource|gl_MaxLights|gl_LightModel|gl_FrontLightModel|gl_BackLightModel|gl_FrontLightProduct|gl_BackLightProduct|gl_TextureEnvColor|gl_EyePlaneS|gl_EyePlaneT|gl_EyePlaneR|gl_EyePlaneQ|gl_ObjectPlaneS|gl_ObjectPlaneT|gl_ObjectPlaneR|gl_ObjectPlaneQ|gl_Fog)\>"
  end

  rule "Functions"
    pattern     "\<(radians|degress|sin|cos|tan|asin|acos|atan|atan|pow|exp2|log2|sqrt|inversesqrt|abs|sign|floor|ceil|fract|mod|min|max|clamp|mix|step|smoothstep|length|distance|dot|cross|normalize|ftransform|faceforward|reflect|matrixCompMult|lessThan|lessThanEqual|greaterThan|greaterThanEqual|equal|notEqual|any|all|not|texture1D|texture1DProj|texture1DLod|texture1DProjLod|texture2D|texture2DProj|texture2DLod|texture2DProjLod|texture3D|texture3DProj|texture3DLod|texture3DProjLod|textureCube|textureCubeLod|shadow1D|shadow2D|shadow1DProj|shadow2DProj|shadow1DLod|shadow2DLod|shadow1DProjLod|shadow2DProjLod|dFdx|dFdy|fwidth|noise1|noise2|noise3|noise4)\>"
  end
end


# JavaScript
language "JavaScript"

  # File patterns for this language mode
  filesmatch "*.js,*.json"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # Merge
  rule "MergeMine"
    openpattern   "^<<<<<<<.*?\n"
    closepattern  "(?=^=======\n)"
  end
  rule "MergeDivision"
    pattern     "^=======\n"
  end
  rule "MergeYours"
    openpattern   "(?<=^=======\n)"
    closepattern  "^>>>>>>>.*?\n"
  end

  # C style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # C++ style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "UnicodeEscape"
      pattern     "\\u\h\h\h\h"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\[0'\"\\nrvtbf]"
      style       "fuchsia"
    end
  end

  # String
  rule "String"
    openpattern   "\'"
    closepattern  "\'"
    stoppattern   "$"
    style         "blue"
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "UnicodeEscape"
      pattern     "\\u\h\h\h\h"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\[0'\"\\nrvtbf]"
      style       "fuchsia"
    end
  end

  # Keywords
  rule "Keyword"
    pattern     "\<(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with|class|const|enum|export|extends|import|super|implements|interface|let|package|private|protected|public|static|yield)\>"
    style       "red"
  end

  rule "Number"
    pattern     "\<(((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)[ij]?\>"
    style       "blue"
  end
  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|\.|;|,|<<=|<<|<=|<|>>>=|>>>|>>=|>>|>=|>|===|==|=|!==|!=|!|\+\+|\+=|\+|--|-=|-|%=|%|\*=|\*|\^=|\^|~=|~|&&|&=|&|\|\||\|=|\||:|/=|/|\?)"
    style       "red"
  end
end


# Pascal
language "Pascal"
  filesmatch "*.pas,*.p"
  contextlines 1
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
    style       "blue"
  end
  rule "String"
    pattern    "\'[^']*?\'"
    style       "blue"
  end
  rule "Type"
    pattern    "\<(?iInteger|Shortint|SmallInt|Longint|Int64|Byte|Word|Cardinal|QWord|Boolean|ByteBool|LongBool|Char)\>"
  end
  rule "Comment"
    pattern    "\(\*.*?\*\)|\{.*?\}"
    style      "darkgreen"
  end
  rule "Operator"
    pattern     "(:=|:|@|\\+=|\\+|-=|-|=|\\^|<=|<|>=|>|\\*=|\\*|/=|/|\\.)"
    style       "red"
  end
  rule "Keyword"
    pattern     "\<(?iabsolute|and|array|asm|begin|break|case|const|constructor|continue|destructor|div|do|downto|else|end|file|for|function|goto|if|implementation|in|inherited|inline|interface|label|mod|nil|not|object|of|on|operator|or|packed|procedure|program|record|repeat|self|set|shl|shr|string|then|to|type|unit|until|uses|var|while|with|xor)\>"
    style       "red"
  end
end


# Ada Programming Language
language "Ada"

  # File patterns for this language mode
  filesmatch "*.ada,*.ad,*.ads,*.adb,*.a,*.ADA,*.AD,*.ADS,*.ADB,*.A"

  contextlines 1

  # Word delimiters
  delimiters "~.,/\`'!@$%^&*()-=+{}|[]\":;<>?"

  # Comment
  rule "Comment"
    openpattern   "--"
    closepattern  "$"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
  end

  # Char constant
  rule "Char"
    pattern     "'([^\\]|\\.)'"
    style       "blue"
  end

  # Pragma
  rule "Pragma"
    pattern     "(?n(?ipragma)\s+\l[\l\d]*(?:_\l[\l\d]*)*\s*\([^)]*\)\s*;)"
  end

  rule "Attribute"
    pattern     "(?i'size\s+(use)>)|'\l[\l\d]*(?:_[\l\d]+)*"
  end

  # Statement label
  rule "Label"
    pattern     "<<\l[\l\d]*(_[\l\d]+)*>>"
  end

  # Based number
  rule "BasedNumber"
    pattern     "(\d+(_\d+)*#\h+(_\h+)*(\.\h+(_\h+)*)?#([eE][-+]?\d+(_\d+)*)?)"
  end

  # Decimal number
  rule "Number"
    pattern     "(\d+(_\d+)*(\.\d+(_\d+)*)?([eE][-+]?\d+(_\d+)*)?)"
  end

  # Reserved keywords
  rule "Keyword"
    pattern     "\<(?iabort|abstract|abs|accept|access|aliased|all|and|array|at|begin|body|case|constant|declare|delay|delta|digits|do|else|elsif|end|entry|exception|exit|for|function|generic|goto|if|interface|in|is|limited|loop|mod|new|nor|not|null|of|or|others|out|overriding|package|pragma|private|procedure|protected|raise|range|record|rem|renames|requeue|return|reverse|select|separate|some|subtype|synchronized|tagged|task|terminate|then|type|until|use|when|while|with|xor)\>"
    style       "red"
  end

  # Operators
  rule "Operator"
    pattern     "(=|/=|<=|<|>=|>|\+|-|&|\*\*|\*|/|:=|:)"
  end

  # Types
  rule "Types"
    pattern     "\<(boolean|character|count|duration|float|integer|long_float|long_integer|priority|short_float|short_integer|string)\>"
  end

  # Identifiers
  rule "Identifier"
    pattern     "\<(\l[\l\d]*(_[\l\d]+)*)\>"
  end
end


# Python
language "Python"
  filesmatch "*.py"
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # Numbers
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
    style       "blue"
  end

  # Quoted string (')
  rule "String"
    openpattern    "'(?!'')"
    closepattern   "'(?!'')"
    style          "blue"
    rule "ControlEscape"
      pattern     "\\(\\|'|\"|a|b|f|n|r|t|v)"
      style       "fuchsia"
    end
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "(\\u\h{4}|\\U\h{8})"
      style       "fuchsia"
    end
  end

  # Quoted string (")
  rule "String"
    openpattern    "\"(?!\"\")"
    closepattern   "\"(?!\"\")"
    style          "blue"
    rule "ControlEscape"
      pattern     "\\(\\|'|\"|a|b|f|n|r|t|v)"
      style       "fuchsia"
    end
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "(\\u\h{4}|\\U\h{8})"
      style       "fuchsia"
    end
  end

  # Triple quoted string (')
  rule "String"
    openpattern    "'''"
    closepattern   "'''"
    style          "blue"
    rule "ControlEscape"
      pattern     "\\(\\|'|\"|a|b|f|n|r|t|v)"
      style       "fuchsia"
    end
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "(\\u\h{4}|\\U\h{8})"
      style       "fuchsia"
    end
  end

  # Triple quoted string (")
  rule "String"
    openpattern    "\"\"\""
    closepattern   "\"\"\""
    style          "blue"
    rule "ControlEscape"
      pattern     "\\(\\|'|\"|a|b|f|n|r|t|v)"
      style       "fuchsia"
    end
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "(\\u\h{4}|\\U\h{8})"
      style       "fuchsia"
    end
  end

  rule "Comment"
    pattern    "#.*?$"
    style      "darkgreen"
  end

  rule "Operator"
    pattern    "\+\+|\+=|\+|--|-=|-|==|=|&&|&=|&|=|^=|^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!=|!|~=|~|\*=|\*|/=|/|%=|%|:"
    style      "red"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style      "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style      "red"
  end

  rule "Brackets"
    pattern     "(\[|\])"
    style      "red"
  end

  rule "Keyword"
    pattern    "\<(and|del|from|not|while|as|elif|global|or|with|assert|else|if|pass|yield|break|except|import|print|class|exec|in|raise|continue|finally|is|return|def|for|lambda|try)\>"
    style      "red"
  end
end


# Ruby
language "Ruby"
  filesmatch "*.rb"
  contextlines 1
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
    style       "blue"
  end
  rule "SingleString"
    openpattern   "'"
    closepattern  "'"
    style         "blue"
    rule "CharEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
  rule "DoubleString"
    openpattern   "\""
    closepattern  "\""
    style         "blue"
    rule "CharEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
  rule "Comment"
    pattern     "#.*?$"
    style       "darkgreen"
  end
  rule "Operator"
    pattern     "\+=|\+|-=|-|===|==|=|&&|&=|&|\|\||\|=|\||^=|^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%|"
  end
  rule "Keyword"
    pattern     "\<(alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\>"
    style       "red"
  end
end


# Perl
language "Perl"
  filesmatch "*.pl"
  contextlines 1
  rule "Comment"
    openpattern  "#"
    closepattern "$"
    style        "darkgreen"
  end
  rule "Statement"
    pattern "\<(if|until|while|elsif|else|unless|for(each)?|continue|last|goto|next|redo|do(?=\s*\{)|BEGIN|END)\>"
  end
  rule "Operator"
    pattern     "\<(lt|gt|le|ge|eq|ne|cmp|not|and|or|xor|sub|x)\>"
  end
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
  rule "String"
    openpattern   "'"
    closepattern  "'"
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
end


# TCL/TK
language "TCL/TK"
  filesmatch "*.tcl"
  contextlines 1
  rule "Comment"
    openpattern  "#"
    closepattern "$"
    style        "darkgreen"
  end
  rule "Operator"
    pattern     "(\*|/|%|\+|-|<<|<=|<|>>|>=|>|!=|==|&&|&|\|\||\||\^|\?|:)"
    style       "red"
  end
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|LL|l|ll|UL|ULL|ul|ull|u|U|F|f|Q|q)?\>"
    style       "blue"
  end
  rule "Keyword"
    pattern     "\<(if|elsif|else|switch|foreach|for|while|proc)\>"
  end
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
end


# Lua
language "Lua"

  # File patterns for this language mode
  filesmatch "*.lua"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # Short comment
  rule "SingleLineComment"
    openpattern   "--"
    closepattern  "$"
    style         "darkgreen"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end

  # String
  rule "String"
    openpattern   "\'"
    closepattern  "\'"
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end

  rule "Keyword"
    pattern     "\<(and|break|do|else|elseif|end|false|for|function|if|in|local|nil|not|or|repeat|return|then|true|until|while)\>"
    style       "red"
  end
  rule "Number"
    pattern     "\<(((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)[ij]?\>"
    style       "blue"
  end
  rule "Operator"
    pattern     "(\+|-|\*|/|%|\^|#|==|~=|<=|>=|<|>|=|\(|\)|\{|\}|\[|\]|;|:|,|\.\.\.|\.\.|\.)"
    style       "red"
  end
end


# Assembly language
language "AS"

  # File patterns for this language mode
  filesmatch "*.s,*.S"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"

  contextlines 1

  # Block comment
  rule "BlockComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
  end

  # Line comment
  rule "LineComment"
    pattern ";.*?$"
    style         "darkgreen"
  end

  # Number
  rule "Number"
    pattern     "\<((0[xXbB][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)\>"
    style       "blue"
  end

  # Operator
  rule "Operator"
    pattern     "(\*|/|%|<<|>>|<>|<=|<|>=|>|\+|-|~|\|\||\||&&|&|\^|!=|!|==)"
    style       "red"
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end

  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    stoppattern  "$"
    style        "blue"
    rule "OctalEscape"
      pattern "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
end


# Go Programming language
language "Go"

  # File patterns for this language mode
  filesmatch "*.go"

  contextlines 1

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"

  # All C-like languages use similar color schemes
  group "C-Like"

  # C++ style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # C style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    stoppattern  "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\[0-7]{3}"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "\\u\h\h\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "\\U\h\h\h\h\h\h\h\h"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\[abfnrtv\\']"
      style       "fuchsia"
    end
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\[0-7]{3}"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "\\u\h\h\h\h"
      style       "fuchsia"
    end
    rule "Unicode"
      pattern     "\\U\h\h\h\h\h\h\h\h"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\[abfnrtv\\\"]"
      style       "fuchsia"
    end
  end

  # String
  rule "RawString"
    openpattern   "\`"
    closepattern  "\`"
  end

  rule "Keyword"
    pattern     "\<(break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\>"
    style       "red"
  end

  rule "Operator"
    pattern     "(\+\+|\+=|\+|--|-=|-|\*=|\*|/=|/|%=|%|&&|&^=|&=|&^|&|\^=|\^|<<=|<<|<=|<-|<|>>=|>>|>=|>|\|\||\|=|\||==|=|!=|!|:=|:|\.\.\.|\.|\(|\[|\{|,|\)|\]|\}|;)"
    style       "red"
  end

  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?i?)\>"
    style       "blue"
  end

  rule "Type"
    pattern     "\<(uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|float64|complex64|complex128|byte|rune|uint|int|uintptr)\>"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end
end


# IDL interface definition language
language "IDL"

  # File patterns for this language mode
  filesmatch "*.idl"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # // style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # /* */ style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
    rule "Format"
      pattern     "%[\*hlLq#0 +-]?\d*(\.(\*|\d*))?l?[diouxXeEfFgGaAcsp]"
      style       "fuchsia"
    end
  end


  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*#"
    closepattern "$"
    style        "blue"
    rule "PreprocessorContinuation"
      pattern    "\\\n"
      style      "blue"
    end
  end

  rule "Keyword"
    pattern     "\<(attribute|component|comsumes|context|custom|exception|emits|eventtype|factory|finder|fixed|getraises|home|import|interface|local|module|multiple|native|oneway|primarykey|private|provides|public|publishes|raises|readonly|setraises|supports|truncatable|typedef|typeid|typeprefix|uses|ValueBase|valuetype)\>"
  end

  rule "Direction"
    pattern     "\<(in|inout|out)\>"
  end

  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
    style       "blue"
  end

  rule "Type"
    pattern     "\<(unsigned|signed|int|char|octet|any|wchar|short|long|hyper|float|double|boolean|complex|void|struct|union|enum|switch|case|default|sequence|string|wstring|Object)\>"
  end

  rule "Braces"
    pattern     "(\{|\})"
    style       "red"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
    style       "red"
  end

  rule "Operator"
    pattern     "(\[|\]|\+\+|\+=|\+|--|-=|->\*|->|-|==|=|&&|&=|&|\|\||\|=|\||\^=|\^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%)"
    style       "red"
  end
end


# Shell scripts
language "Shell"
  contentsmatch "\A#!\s*(/bin/)?(ba)?sh"
  contextlines 1
  rule "Comment"
    pattern    "#.*?$"
    style      "darkgreen"
  end
  rule "Keyword"
    pattern    "\<(for|in|do|done|if|then|else|elif|fi|switch|case|esac|while|function|select|until|time)\>"
    style      "blue"
  end
  rule "Operator"
    pattern    "(=|;;|;|!|\{|\}|\[\[|\]\])"
    style      "red"
  end
end


# Makefiles
language "Make"
  filesmatch "Makefile*,makefile*"
  contextlines 10
  expandtabs   no
  rule "Comment"
    openpattern  "#"
    closepattern "$"
    style         "darkgreen"
    rule "CommentContinuation"
      pattern  "\\\n"
      style    "darkgreen"
    end
  end
  rule "Assignment"
    openpattern "^( *| [ \t]*)[A-Za-z0-9_+$()][^ \t\n]*[ \t]*(\+=|:=|=)"
    closepattern "$"
    rule "AssignmentContinuation"
      pattern "\\\n"
    end
    rule "AssignmentComment"
      openpattern "#"
      closepattern "$"
    end
  end
  rule "DependencyLine"
    openpattern "^( *| [ \t]*)(.DEFAULT|.DELETE_ON_ERROR|.EXPORT_ALL_VARIABLES.IGNORE|.INTERMEDIATE|.PHONY|.POSIX|.PRECIOUS|.SECONDARY|.SILENT|.SUFFIXES)*(([A-Za-z0-9./$(){} _@^<*?%+-]+?(\\\n))*?[A-Za-z0-9./$(){} _@^<*?%+-]+)::?"
    closepattern "$|;"
    rule "DependencyContinuation"
      pattern "\\\n"
    end
  end
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
  rule "String"
    openpattern   "'"
    closepattern  "'"
    stoppattern   "$"
    style         "blue"
    rule "OctalEscape"
      pattern     "\\\d+"
      style       "fuchsia"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
      style       "fuchsia"
    end
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
end


# Makefiles
language "CMake"
  filesmatch "*.cmake,*.cmake.in,*.ctest,*.ctest.in,CMakeLists.txt"
  contextlines 1
  rule "BracketComment"
    openpattern  "#\[\["
    closepattern "\]\]"
    style         "darkgreen"
  end
  rule "Comment"
    openpattern  "#"
    closepattern "$"
    style         "darkgreen"
  end
  rule "Command"
    openpattern  "\s*?[A-Za-z_][A-Za-z0-9_]*?\s*?\("
    closepattern "\)"
    style        "blue"
    rule "QuotedArgument"
      openpattern   "\""
      closepattern  "\""
      stoppattern   "$"
      style         "blue"
      rule "Escape"
        pattern     "\\[()#\" \\$@^;trn]"
        style       "fuchsia"
      end
    end
    rule "Argument"
      pattern     "[^\s()#\"\']+?"
      style       "red"
    end
  end
end


# GNU configure scripts
language "Configure"
  filesmatch "configure.in,configure.ac"
  contextlines 1
  rule "Comment"
    pattern    "\<dnl\>.*?$"
    style         "darkgreen"
  end
  rule "Comment"
    pattern    "#.*?$"
    style      "darkgreen"
  end
  rule "String"
    openpattern  "'"
    closepattern "'"
    style        "blue"
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
  rule "String"
    openpattern  "\""
    closepattern "\""
    style        "blue"
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
  rule "Macro"
    pattern    "\<A[CM]\w*\>"
    style      "blue"
  end
  rule "ShellResult"
    openpattern  "`"
    closepattern "`"
    style        "red"
    rule "ControlEscape"
      pattern     "\\."
      style       "fuchsia"
    end
  end
end


# HTML and XML
language "XML/HTML"
  filesmatch "*.xml,*.htm,*.html,*.svg,*.ui"
  contextlines 1

  rule "Comment"
    openpattern   "<!--"
    closepattern  "-->"
    style         "darkgreen"
  end

  rule "CDATA"
    openpattern   "<!\[CDATA\["
    closepattern  "\]\]>"
    style         "cyan"
  end

  rule "Declaration"
    openpattern   "<!"
    closepattern  ">"
    style         "blue"
  end

  rule "EntityRef"
    pattern       "\&\l\w*;"
    style         "yellow"
  end

  rule "CharRef"
    pattern       "\&#(\d+|x\h+);"
    style         "yellow"
  end

  rule "Instruction"
    openpattern   "<\?"
    closepattern  "\?>"
    style         "red"
    rule "String"
      openpattern   "\""
      closepattern  "\""
      style         "blue"
    end
    rule "String"
      openpattern   "\'"
      closepattern  "\'"
      style         "blue"
    end
  end

  rule "Element"
    openpattern   "</?"
    closepattern  "/?>"
    style         "red"
    rule "Name"
      pattern     "[:_\l][\w.-]+"
      style       "yellow"
    end
    rule "Equals"
      pattern     "="
      style       "red"
    end
    rule "String"
      openpattern   "\""
      closepattern  "\""
      style         "blue"
    end
    rule "String"
      openpattern   "'"
      closepattern  "'"
      style         "blue"
    end
  end
end


# LaTeX text formatting language
language "LaTeX"
  filesmatch "*.tex"
  delimiters "~.,/\`'!@#$%^&*()_-=+{}|[]\":;<>?"
  contextlines 1
  rule "Math"
    openpattern "\$|\\\[|\\\(|\\begin(?=(\{(equation|align)\*?\}))"
    closepattern "\$|\\\]|\\\)|\\end(?=(\{(equation|align)\*?\}))"

    rule "Comment"
      openpattern   "%"
      closepattern  "$"
      stoppattern   "$"
      style         "darkgreen"
    end
    rule "CurlyBrace"
      pattern "\{|\}"
    end
    rule "MathCommand"
      openpattern  "\\(?!([^a-zA-Z]|end\{(equation|align)\*?\}))"
      closepattern "(?=[^a-zA-Z])|$"
      stoppattern  "(?=\$)|\\((?=\])|(?=\))|(?=end\{(equation|align)\}))"
      rule "Comment"
        openpattern   "%"
        closepattern  "$"
        stoppattern   "$"
        style         "darkgreen"
      end
      rule "MathGreek"
        pattern "\<([aA]lpha|[bB]eta|[gG]amma|[eE]psilon|[dD]elta|[eE]ta|[iI]ota|[kK]appa|[lL]ambda|[mM]u|[nN]u|[pP]i|[rR]ho|[sS]igma|[tT]au|[pP]hi|[pP]si|[xX]i|[uU]psilon|[zZ]eta|[tT]heta|[oO]mega)(\>|(?=_))"
      end
    end
  end

  rule "Command"
    openpattern  "\\{1}(?!\\)"
    closepattern "(?=[^a-zA-Z])|$"
    stoppattern  "\{|\}| |$"
    rule "TextFormating"
      pattern "\<(textbf|texttt|textsl|textit|emph)\>"
    end
    rule "Sectioning"
      pattern "\<(section|subsection|subsubsection|paragraph|chapter)\>"
    end
    rule "Reference"
      pattern "\<(cite|ref|label)\>"
    end
    rule "Includes"
      pattern "\<(usepackage|include|input|includegraphics)\>"
    end
    rule "Footnote"
      pattern "\<(footnote)\>"
    end

    rule "Comment"
      openpattern   "%"
      closepattern  "$"
      stoppattern   "$"
      style         "darkgreen"
    end

    rule "Breaks"
      pattern "\<(clearpage|newpage)\>"
    end
  end

  rule "CurlyBrace"
       pattern "\{|\}"
  end

  rule "Comment"
    openpattern   "%"
    closepattern  "$"
    stoppattern   "$"
    style         "darkgreen"
  end

  rule "Breaks"
    pattern "\\{2}"
  end
end


# HTLM/PHP Markup patterns
# Contributed by: Andy Preston <mail@andy-preston.co.uk>
language "Markup"
  filesmatch "*.html,*.xhtml,*.xml,*.sgml,*.php"
  contextlines 1
  rule "PHP"
    openpattern "<\?php"
    closepattern "\?>"
    rule "String"
      openpattern   "\""
      closepattern  "\""
      rule "ControlEscape"
         pattern     "\\."
      end
      rule "Variable"
        pattern "\$[A-Za-z_][0-9A-Za-z_]*"
      end
    end
    rule "SString"
      openpattern   "'"
      closepattern  "'"
      rule "SQuote"
         pattern     "''"
      end
    end
    rule "Number"
      pattern "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)\>"
    end
    rule "Variable"
      pattern "\$\$?[A-Za-z_][0-9A-Za-z_]*"
    end
    rule "Comment"
      pattern    "#.*?$"
      style      "darkgreen"
    end
    rule "CPPComment"
      openpattern   "//"
      closepattern  "$"
      style      "darkgreen"
    end
    rule "CComment"
      openpattern   "/\*"
      closepattern  "\*/"
      style      "darkgreen"
    end
    rule "Keyword"
      pattern "\<(and|break|case|class|do|echo|else|elseif|endfor|endwhile|for|function|global|if|include|new|or|print|return|static|switch|while|xor)\>"
      style   "red"
    end
    rule "Operator"
      # there's a bit of a kludge here, for the "?" operator, a "?" matches against the "?>" at the end of a block of PHP
      # so I've had to make it \?[^>] which means the character following the "?" is treated as part of the operator
      # If you write this: "$x = $y ? 1 : 2" it looks fine, but if you write "$x=$y?1:2" the "1" is shown as part of the operator
      pattern "(,|=|\+=|-=|\*=|/=|\.=|%=|&=|\|=|\^=|~=|<<=|>>=|:|\?[^>]|\|\||&&|\||\^|&|==|!=|===|!==|<|<=|>|>=|<<|>>|\+|-|\.|\*|/|%|!|~|\+\+|--|\(int\)|\(double\)|\(string\)|\(array\)|\(object\)|@|\[|\])"
    end
  end
  rule "Comment"
    openpattern "<!--"
    closepattern "-->"
  end
  rule "Tag"
    openpattern "<"
    closepattern ">"
    rule "Attribute"
      pattern " [A-Za-z_][A-Za-z0-9_-]+"
    end
    rule "Value"
      pattern "=?\"[^\"]*\""
      rule "HexTriplet"
        pattern "#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
      end
    end
  end
  rule "Special"
    openpattern "&"
    closepattern ";"
  end
end


# TENA definition language
language "TDL"

  # File patterns for this language mode
  filesmatch "*.tdl"

  # Word delimiters
  delimiters "~.,/\`'!@#$%^&*()-=+{}|[]\":;<>?"
  contextlines 1

  # All C-like languages use similar color schemes
  group "C-Like"

  # // style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # /* */ style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    style         "darkgreen"
    rule "FIXME"
      pattern     "FIXME"
      style       "fuchsia"
    end
  end

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    rule "OctalEscape"
      pattern     "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern     "\\."
    end
    rule "Format"
      pattern "%[\*hlLq#0 +-]?\d*(\.(\*|\d*))?l?[diouxXeEfFgGaAcsp]"
    end
  end


  # Char constant
  rule "Char"
    openpattern  "'"
    closepattern "'"
    rule "OctalEscape"
      pattern "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern "\\."
    end
  end

  # Preprocessor
  rule "Preprocessor"
    openpattern  "^\s*#"
    closepattern "$"
    rule "PreprocessorContinuation"
      pattern "\\\n"
    end
  end

  rule "Keyword"
    pattern     "\<(abstract|and_eq|and|any|asm|attribute|auto|bitand|bitor|break|case|catch|compl|component|const_cast|consumes|context|continue|custom|default|delete|do|dynamic_cast|else|emits|eventtype|exception|explicit|export|extends|extern|factory|FALSE|false|finder|fixed|for|friend|getraises|goto|home|if|implements|import|inline|interface|local|message|module|multiple|mutable|namespace|native|new|not_eq|not|oneway|operator|optional|or_eq|or|package|primarykey|private|protected|provides|public|publishes|raises|readonly|reinterpret_cast|return|sequence|setraises|sizeof|static_cast|supports|switch|template|this|throw|TRUE|true|truncatable|try|typedef|typeid|typename|typeprefix|uses|using|ValueBase|valuetype|vector|while|xor_eq|xor)\>"
    style       "red"
  end

  rule "Direction"
    pattern     "\<(inout|in|out)\>"
  end

  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
  end

  rule "Type"
    pattern     "\<(boolean|bool|char|class|const|double|enum|float32|float64|float|long|int16|int32|int64|int8|int|object|octet|register|short|signed|static|string|struct|uint16|uint32|uint64|uint8|union|unsigned|void|virtual|volatile|wchar_t|wchar|wstring)\>"
  end

  rule "Braces"
    pattern     "(\{|\})"
  end

  rule "Parentheses"
    pattern     "(\(|\))"
  end

  rule "Operator"
    pattern     "(\[|\]|\+\+|\+=|\+|--|-=|->\*|->|-|==|=|&&|&=|&|\|\||\|=|\||\^=|\^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%)"
  end
end
