#################################################################################
#                                                                               #
#                       A d i e   S y n t a x   F i l e                         #
#                                                                               #
#################################################################################
# Copyright (C) 2004,2006 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.    #
#################################################################################
# $Id: Adie.stx,v 1.37.2.4 2006/07/25 01:35:35 fox Exp $                            #
#################################################################################

#
# Notes:
#
# - Please send addition changes or additions to this file to:
#
#       jeroen@fox-toolkit.org
#
# - 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.


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

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

  rule "Math"
    openpattern "\$|\\\[|\\\(|\\begin(?=(\{(equation|align)\*?\}))"
    closepattern "\$|\\\]|\\\)|\\end(?=(\{(equation|align)\*?\}))"

    rule "Comment"
      openpattern   "%"
      closepattern  "$"
      stoppattern   "$"
    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   "$"
      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 "Referance"
      pattern "\<(cite|ref|label)\>"
    end
    rule "Includes"
      pattern "\<(usepackage|include|input|includegraphics)\>"
    end
    rule "Footnote"
      pattern "\<(footnote)\>"
    end

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

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

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

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

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


# A Syntax coloring pattern for syntax coloring patterns ;-)
language "Adie Syntax"
  filesmatch "*.stx"
  rule "Comment"
    openpattern   "#"
    closepattern  "$"
  end
  rule "Keyword"
    pattern     "\<(language|filesmatch|contentsmatch|delimiters|contextlines|contextchars|rule|foreground|end)\>"
  end
  rule "Expression"
    openpattern    "pattern|openpattern|closepattern|stoppattern"
    closepattern   "$"
    rule "Pattern"
      openpattern   "\""
      closepattern  "\""
      stoppattern   "$"
      rule "Escape"
        pattern     "\\\""
      end
    end
  end
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    rule "Escape"
      pattern     "\\\""
    end
  end
end


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

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

  contextlines 100

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

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

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

  # C style comment
  rule "CDocComment"
    openpattern   "/\*\*[ \n]"
    closepattern  "\*/"
  end

  # C style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    rule "FIXME"
      pattern     "FIXME"
    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 "%[\*ahlLq#0 +-]?\d*(\.(\*|\d*))?l?([dDiouxXeEfFgGaAcsp]|\[.*?\])"
    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 "$"

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

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

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

  # Special macros
  rule "FOXMacro"
    pattern     "\<(FXAPI|FXDEFMAP|FXMALLOC|FXFREE|FXCALLOC|FXRESIZE|FXMEMDUP|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|FXLERP|ARRAYNUMBER|STRUCTOFFSET|CONTAINER|allocElms|callocElms|dupElms|resizeElms|freeElms)\>"
  end

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

  rule "Keyword"
    pattern     "\<(friend|typename|explicit|typeid|for|while|if|else|try|catch|new|delete|do|namespace|class|struct|enum|union|public|private|protected|template|switch|case|default|this|return|throw|using|break|continue|goto|static|volatile|const|virtual|mutable|operator|auto|register|overload|inline|extern|and|or|xor|not|compl|and_eq|xor_eq|const_cast|dynamic_cast|true|false|not_eq|sizeof|bitor|bitand|reinterpret_cast|static_cast)\>"
  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)?\>"
  end

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

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

end

# C programming language
language "C"

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

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

  contextlines 100

  # C style comment
  rule "CDocComment"
    openpattern   "/\*\*[ \n]"
    closepattern  "\*/"
  end

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

  # C++ style comment
  rule "CPPComment"
    openpattern   "//"
    closepattern  "$"
  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 "%[\*ahlLq#0 +-]?\d*(\.(\*|\d*))?l?([dDiouxXeEfFgGaAcsp]|\[.*?\])"
    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 "$"

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

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

    # Comments
    rule "CComment"
      openpattern   "/\*"
      closepattern  "\*/"
    end
    rule "CPPComment"
      openpattern   "//"
      closepattern  "$"
    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)\>"
  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)?\>"
  end

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

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

end

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

language "Pascal"
  filesmatch "*.pas,*.p"
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
  end
  rule "String"
    pattern    "\'[^']*?\'"
  end
  rule "Type"
    pattern    "\<(?iInteger|Shortint|SmallInt|Longint|Int64|Byte|Word|Cardinal|QWord|Boolean|ByteBool|LongBool|Char)\>"
  end
  rule "Comment"
    pattern    "\(\*.*?\*\)|\{.*?\}"
  end
  rule "Operator"
    pattern     "(:=|:|@|\\+=|\\+|-=|-|=|\\^|<=|<|>=|>|\\*=|\\*|/=|/|\\.)"
  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)\>"
  end
end


language "Configure"
  filesmatch "configure.in,configure.ac"
  rule "Comment"
    pattern    "\<dnl\>.*?$"
  end
  rule "Comment"
    pattern    "#.*?$"
  end
  rule "String"
    openpattern  "'"
    closepattern "'"
    rule "ControlEscape"
      pattern     "\\."
    end
  end
  rule "String"
    openpattern  "\""
    closepattern "\""
    rule "ControlEscape"
      pattern     "\\."
    end
  end
  rule "Macro"
    pattern    "\<A[CM]\w*\>"
  end
  rule "ShellResult"
    openpattern  "`"
    closepattern "`"
    rule "ControlEscape"
      pattern     "\\."
    end
  end
end


language "Python"
  filesmatch "*.py"
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
  end
  rule "String"
    openpattern    "([^\"{2}]\"[^\"{2}])|([^'{2}]'[^\"{2}])"
    closepattern   "([^\"{2}]\"[^\"{2}])|([^\"{2}]'[^\"{2}])"
    rule "CharEscape"
      pattern     "\\."
    end
  end
  rule "TripleString"
    openpattern    "(\"{3})|('{3})"
    closepattern   "(\"{3})|('{3})"
    rule "CharEscape"
      pattern     "\\."
    end
  end
  rule "Comment"
    pattern    "#.*?$"
  end
  rule "Operator"
    pattern     "\+\+|\+=|\+|--|-=|-|==|=|&&|&=|&|=|^=|^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!=|!|~=|~|\*=|\*|/=|/|%=|%"
  end
  rule "Keyword"
    pattern     "\<(def|import|for|in|while|if|elif|else|try|class|return|break|continue|raise|and|or|not|print|pass|access|global|from|except|exec|is|finally|lambda)\>"
  end
end

language "Ruby"
  filesmatch "*.rb"
  rule "Number"
    pattern     "\<((0[xX][0-9a-fA-F]+)|((\d+\.?\d*)|(\.\d+))([eE](\+|-)?\d+)?)(L|l|UL|ul|u|U|F|f)?\>"
  end
  rule "SingleString"
    openpattern   "'"
    closepattern  "'"
    rule "CharEscape"
      pattern     "\\."
    end
  end
  rule "DoubleString"
    openpattern   "\""
    closepattern  "\""
    rule "CharEscape"
      pattern     "\\."
    end
  end
  rule "Comment"
    pattern    "#.*?$"
  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)\>"
  end
end

language "Xml/Html"
  filesmatch "*.xml,*.htm,*.html,*.ui"
  rule "Comment"
    openpattern   "<!--"
    closepattern  "-->"
  end

  rule "Entity"
    openpattern   "\&"
    closepattern  ";"
  end

  rule "Instruction"
    openpattern   "<\?"
    closepattern  "\?>"
    rule "String"
      openpattern   "\""
      closepattern  "\""
      rule "Entity"
        openpattern   "\&"
        closepattern  ";"
        stoppattern   "(?=\")"
      end
    end
    rule "String"
      openpattern   "\'"
      closepattern  "\'"
      rule "Entity"
        openpattern   "\&"
        closepattern  ";"
        stoppattern   "(?=\")"
      end
    end
  end

  rule "Node"
    openpattern   "<"
    closepattern  ">"
    rule "String"
      openpattern   "\""
      closepattern  "\""
      rule "Entity"
        openpattern   "\&"
        closepattern  ";"
        stoppattern   "(?=\")"
      end
    end
    rule "String"
      openpattern   "\'"
      closepattern  "\'"
      rule "Entity"
        openpattern   "\&"
        closepattern  ";"
        stoppattern   "(?=\")"
      end
    end
  end
end

# IDL interface definition language
language "IDL"

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

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

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

  # /* */ style comment
  rule "CComment"
    openpattern   "/\*"
    closepattern  "\*/"
    rule "FIXME"
      pattern     "FIXME"
    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     "\<(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)?\>"
  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 "Operator"
    pattern     "(\{|\}|\+\+|\+=|\+|--|-=|->\*|->|-|==|=|&&|&=|&|\|\||\|=|\||\^=|\^|<<=|<<|<=|<|>>=|>>|>=|>|!=|!|~=|~|\*=|\*|/=|/|%=|%)"
  end
end

# C# programming language
language "C#"

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

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

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

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

  # String
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    rule "OctalEscape"
      pattern     "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern     "\\."
    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|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)\>"
  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)?\>"
  end

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

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

end


# HTLM/PHP Markup patterns
# Contributed by: Andy Preston <mail@andy-preston.co.uk>
language "Markup"
  filesmatch "*.html,*.xhtml,*.xml,*.sgml,*.php"
  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    "#.*?$"
     end
     rule "CPPComment"
        openpattern   "//"
        closepattern  "$"
     end
     rule "CComment"
        openpattern   "/\*"
        closepattern  "\*/"
     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)\>"
     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


# Makefiles
language "Make"
  filesmatch "*Makefile*"
  rule "Comment"
    openpattern  "#"
    closepattern "$"
    rule "CommentContinuation"
      pattern "\\\n"
    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)){,8}[A-Za-z0-9./$(){} _@^<*?%+-]*)::?"
    closepattern "$|;"
    rule "DependencyContinuation"
      pattern "\\\n"
    end
  end
  rule "String"
    openpattern   "\""
    closepattern  "\""
    stoppattern   "$"
    rule "OctalEscape"
      pattern     "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern     "\\."
    end
  end
  rule "String"
    openpattern   "'"
    closepattern  "'"
    stoppattern   "$"
    rule "OctalEscape"
      pattern     "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern     "\\."
    end
  end
end

# Perl
language "Perl"
  filesmatch "*.pl"
  rule "Comment"
    openpattern  "#"
    closepattern "$"
  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   "$"
    rule "OctalEscape"
      pattern     "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern     "\\."
    end
  end
  rule "String"
    openpattern   "'"
    closepattern  "'"
    stoppattern   "$"
    rule "OctalEscape"
      pattern     "\\\d+"
    end
    rule "HexEscape"
      pattern     "\\x\h+"
    end
    rule "ControlEscape"
      pattern     "\\."
    end
  end
end

# GLSL shading language
language "GLSL"

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

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

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

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

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

  rule "Keyword"
    pattern     "\<(if|else|for|while|do|discard|return|break|continue|struct)\>"
  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     "\<(void|bool|int|float|vec2|vec3|vec4|bvec2|bvec3|bvec4|ivec2|ivec3|ivec4|mat2|mat3|mat4|sampler1D|sampler2D|sampler3D|samplerCube|sampler1DShadow|sampler2DShadow)\>"
  end

  rule "Qualifier"
    pattern     "\<(varying|attribute|uniform|in|out|inout|const)\>"
  end

  rule "Operator"
    pattern     "(\+\+|\+=|\+|--|-=|-|==|=|&&|\|\||\^=|\^|<=|<|>=|>|!=|!|\*=|\*|/=|/)"
  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


# A Syntax coloring pattern for FOX registry
language "Registry"
  contentsmatch  "\A\[[^]]*?\]"
  contextlines 100
  rule "Comment"
    openpattern   "#"
    closepattern  "$"
  end
  rule "RegistrySection"
    pattern   "^\s*?\[[^]]*?\]\s*?$"
  end
  rule "RegistryEntry"
    openpattern   "^\s*?[^=]*?\s*?(?==)"
    closepattern  "$"
    stoppattern   "$"
    rule "RegistryEquals"
      openpattern   "\s*?=\s*?"
      closepattern  "$"
      stoppattern   "$"
      rule "RegistryString"
        openpattern   "\""
        closepattern  "\""
        stoppattern   "$"
        rule "OctalEscape"
          pattern     "\\\d+"
        end
        rule "HexEscape"
          pattern     "\\x\h+"
        end
        rule "ControlEscape"
          pattern     "\\."
        end
      end
      rule "RegistryValue"
        pattern ".*?$"
      end
    end
  end
end
