ooc.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.ooc
  4. ~~~~~~~~~~~~~~~~~~~
  5. Lexers for the Ooc language.
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer, bygroups, words
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation
  12. __all__ = ['OocLexer']
  13. class OocLexer(RegexLexer):
  14. """
  15. For `Ooc <http://ooc-lang.org/>`_ source code
  16. .. versionadded:: 1.2
  17. """
  18. name = 'Ooc'
  19. aliases = ['ooc']
  20. filenames = ['*.ooc']
  21. mimetypes = ['text/x-ooc']
  22. tokens = {
  23. 'root': [
  24. (words((
  25. 'class', 'interface', 'implement', 'abstract', 'extends', 'from',
  26. 'this', 'super', 'new', 'const', 'final', 'static', 'import',
  27. 'use', 'extern', 'inline', 'proto', 'break', 'continue',
  28. 'fallthrough', 'operator', 'if', 'else', 'for', 'while', 'do',
  29. 'switch', 'case', 'as', 'in', 'version', 'return', 'true',
  30. 'false', 'null'), prefix=r'\b', suffix=r'\b'),
  31. Keyword),
  32. (r'include\b', Keyword, 'include'),
  33. (r'(cover)([ \t]+)(from)([ \t]+)(\w+[*@]?)',
  34. bygroups(Keyword, Text, Keyword, Text, Name.Class)),
  35. (r'(func)((?:[ \t]|\\\n)+)(~[a-z_]\w*)',
  36. bygroups(Keyword, Text, Name.Function)),
  37. (r'\bfunc\b', Keyword),
  38. # Note: %= and ^= not listed on http://ooc-lang.org/syntax
  39. (r'//.*', Comment),
  40. (r'(?s)/\*.*?\*/', Comment.Multiline),
  41. (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|'
  42. r'&&?|\|\|?|\^=?)', Operator),
  43. (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text,
  44. Name.Function)),
  45. (r'[A-Z][A-Z0-9_]+', Name.Constant),
  46. (r'[A-Z]\w*([@*]|\[[ \t]*\])?', Name.Class),
  47. (r'([a-z]\w*(?:~[a-z]\w*)?)((?:[ \t]|\\\n)*)(?=\()',
  48. bygroups(Name.Function, Text)),
  49. (r'[a-z]\w*', Name.Variable),
  50. # : introduces types
  51. (r'[:(){}\[\];,]', Punctuation),
  52. (r'0x[0-9a-fA-F]+', Number.Hex),
  53. (r'0c[0-9]+', Number.Oct),
  54. (r'0b[01]+', Number.Bin),
  55. (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float),
  56. (r'[0-9_]+', Number.Decimal),
  57. (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\"])*"',
  58. String.Double),
  59. (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
  60. String.Char),
  61. (r'@', Punctuation), # pointer dereference
  62. (r'\.', Punctuation), # imports or chain operator
  63. (r'\\[ \t\n]', Text),
  64. (r'[ \t]+', Text),
  65. ],
  66. 'include': [
  67. (r'[\w/]+', Name),
  68. (r',', Punctuation),
  69. (r'[ \t]', Text),
  70. (r'[;\n]', Text, '#pop'),
  71. ],
  72. }