ooc.py 2.9 KB

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