home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / syntax / python.vim < prev    next >
Encoding:
Text File  |  2003-02-11  |  6.4 KB  |  172 lines

  1. " Vim syntax file
  2. " Language:    Python
  3. " Maintainer:    Neil Schemenauer <nas@python.ca>
  4. " Updated:    2002-10-18
  5. "
  6. " Options to control Python syntax highlighting:
  7. "
  8. " For highlighted numbers:
  9. "
  10. "    let python_highlight_numbers = 1
  11. "
  12. " For highlighted builtin functions:
  13. "
  14. "    let python_highlight_builtins = 1
  15. "
  16. " For highlighted standard exceptions:
  17. "
  18. "    let python_highlight_exceptions = 1
  19. "
  20. " Highlight erroneous whitespace:
  21. "
  22. "    let python_highlight_space_errors = 1
  23. "
  24. " If you want all possible Python highlighting (the same as setting the
  25. " preceding options):
  26. "
  27. "    let python_highlight_all = 1
  28. "
  29.  
  30. " For version 5.x: Clear all syntax items
  31. " For version 6.x: Quit when a syntax file was already loaded
  32. if version < 600
  33.   syntax clear
  34. elseif exists("b:current_syntax")
  35.   finish
  36. endif
  37.  
  38.  
  39. syn keyword pythonStatement    break continue del
  40. syn keyword pythonStatement    except exec finally
  41. syn keyword pythonStatement    pass print raise
  42. syn keyword pythonStatement    return try
  43. syn keyword pythonStatement    global assert
  44. syn keyword pythonStatement    lambda yield
  45. syn keyword pythonStatement    def class nextgroup=pythonFunction skipwhite
  46. syn match   pythonFunction    "[a-zA-Z_][a-zA-Z0-9_]*" contained
  47. syn keyword pythonRepeat    for while
  48. syn keyword pythonConditional    if elif else
  49. syn keyword pythonOperator    and in is not or
  50. syn keyword pythonPreCondit    import from
  51. syn match   pythonComment    "#.*$" contains=pythonTodo
  52. syn keyword pythonTodo        TODO FIXME XXX contained
  53.  
  54. " strings
  55. syn region pythonString        matchgroup=Normal start=+[uU]\='+ end=+'+ skip=+\\\\\|\\'+ contains=pythonEscape
  56. syn region pythonString        matchgroup=Normal start=+[uU]\="+ end=+"+ skip=+\\\\\|\\"+ contains=pythonEscape
  57. syn region pythonString        matchgroup=Normal start=+[uU]\="""+ end=+"""+ contains=pythonEscape
  58. syn region pythonString        matchgroup=Normal start=+[uU]\='''+ end=+'''+ contains=pythonEscape
  59. syn region pythonRawString    matchgroup=Normal start=+[uU]\=[rR]'+ end=+'+ skip=+\\\\\|\\'+
  60. syn region pythonRawString    matchgroup=Normal start=+[uU]\=[rR]"+ end=+"+ skip=+\\\\\|\\"+
  61. syn region pythonRawString    matchgroup=Normal start=+[uU]\=[rR]"""+ end=+"""+
  62. syn region pythonRawString    matchgroup=Normal start=+[uU]\=[rR]'''+ end=+'''+
  63. syn match  pythonEscape        +\\[abfnrtv'"\\]+ contained
  64. syn match  pythonEscape        "\\\o\{1,3}" contained
  65. syn match  pythonEscape        "\\x\x\{2}" contained
  66. syn match  pythonEscape        "\(\\u\x\{4}\|\\U\x\{8}\)" contained
  67. syn match  pythonEscape        "\\$"
  68.  
  69. if exists("python_highlight_all")
  70.   let python_highlight_numbers = 1
  71.   let python_highlight_builtins = 1
  72.   let python_highlight_exceptions = 1
  73.   let python_highlight_space_errors = 1
  74. endif
  75.  
  76. if exists("python_highlight_numbers")
  77.   " numbers (including longs and complex)
  78.   syn match   pythonNumber    "\<0x\x\+[Ll]\=\>"
  79.   syn match   pythonNumber    "\<\d\+[LljJ]\=\>"
  80.   syn match   pythonNumber    "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>"
  81.   syn match   pythonNumber    "\<\d\+\.\([eE][+-]\=\d\+\)\=[jJ]\=\>"
  82.   syn match   pythonNumber    "\<\d\+\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>"
  83. endif
  84.  
  85. if exists("python_highlight_builtins")
  86.   " builtin functions, types and objects, not really part of the syntax
  87.   syn keyword pythonBuiltin    Ellipsis None NotImplemented __import__ abs
  88.   syn keyword pythonBuiltin    apply buffer callable chr classmethod cmp
  89.   syn keyword pythonBuiltin    coerce compile complex delattr dict dir divmod
  90.   syn keyword pythonBuiltin    eval execfile file filter float getattr globals
  91.   syn keyword pythonBuiltin    hasattr hash hex id input int intern isinstance
  92.   syn keyword pythonBuiltin    issubclass iter len list locals long map max
  93.   syn keyword pythonBuiltin    min object oct open ord pow property range
  94.   syn keyword pythonBuiltin    raw_input reduce reload repr round setattr
  95.   syn keyword pythonBuiltin    slice staticmethod str super tuple type unichr
  96.   syn keyword pythonBuiltin    unicode vars xrange zip
  97. endif
  98.  
  99. if exists("python_highlight_exceptions")
  100.   " builtin exceptions and warnings
  101.   syn keyword pythonException    ArithmeticError AssertionError AttributeError
  102.   syn keyword pythonException    DeprecationWarning EOFError EnvironmentError
  103.   syn keyword pythonException    Exception FloatingPointError IOError
  104.   syn keyword pythonException    ImportError IndentationError IndexError
  105.   syn keyword pythonException    KeyError KeyboardInterrupt LookupError
  106.   syn keyword pythonException    MemoryError NameError NotImplementedError
  107.   syn keyword pythonException    OSError OverflowError OverflowWarning
  108.   syn keyword pythonException    ReferenceError RuntimeError RuntimeWarning
  109.   syn keyword pythonException    StandardError StopIteration SyntaxError
  110.   syn keyword pythonException    SyntaxWarning SystemError SystemExit TabError
  111.   syn keyword pythonException    TypeError UnboundLocalError UnicodeError
  112.   syn keyword pythonException    UserWarning ValueError Warning WindowsError
  113.   syn keyword pythonException    ZeroDivisionError
  114. endif
  115.  
  116. if exists("python_highlight_space_errors")
  117.   " trailing whitespace
  118.   syn match   pythonSpaceError   display excludenl "\S\s\+$"ms=s+1
  119.   " mixed tabs and spaces
  120.   syn match   pythonSpaceError   display " \+\t"
  121.   syn match   pythonSpaceError   display "\t\+ "
  122. endif
  123.  
  124. " This is fast but code inside triple quoted strings screws it up. It
  125. " is impossible to fix because the only way to know if you are inside a
  126. " triple quoted string is to start from the beginning of the file. If
  127. " you have a fast machine you can try uncommenting the "sync minlines"
  128. " and commenting out the rest.
  129. syn sync match pythonSync grouphere NONE "):$"
  130. syn sync maxlines=200
  131. "syn sync minlines=2000
  132.  
  133. if version >= 508 || !exists("did_python_syn_inits")
  134.   if version <= 508
  135.     let did_python_syn_inits = 1
  136.     command -nargs=+ HiLink hi link <args>
  137.   else
  138.     command -nargs=+ HiLink hi def link <args>
  139.   endif
  140.  
  141.   " The default methods for highlighting.  Can be overridden later
  142.   HiLink pythonStatement    Statement
  143.   HiLink pythonFunction        Function
  144.   HiLink pythonConditional    Conditional
  145.   HiLink pythonRepeat        Repeat
  146.   HiLink pythonString        String
  147.   HiLink pythonRawString    String
  148.   HiLink pythonEscape        Special
  149.   HiLink pythonOperator        Operator
  150.   HiLink pythonPreCondit    PreCondit
  151.   HiLink pythonComment        Comment
  152.   HiLink pythonTodo        Todo
  153.   if exists("python_highlight_numbers")
  154.     HiLink pythonNumber    Number
  155.   endif
  156.   if exists("python_highlight_builtins")
  157.     HiLink pythonBuiltin    Function
  158.   endif
  159.   if exists("python_highlight_exceptions")
  160.     HiLink pythonException    Exception
  161.   endif
  162.   if exists("python_highlight_space_errors")
  163.     HiLink pythonSpaceError    Error
  164.   endif
  165.  
  166.   delcommand HiLink
  167. endif
  168.  
  169. let b:current_syntax = "python"
  170.  
  171. " vim: ts=8
  172.