pony.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.pony
  4. ~~~~~~~~~~~~~~~~~~~~
  5. Lexers for Pony and related languages.
  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__ = ['PonyLexer']
  13. class PonyLexer(RegexLexer):
  14. """
  15. For Pony source code.
  16. .. versionadded:: 2.4
  17. """
  18. name = 'Pony'
  19. aliases = ['pony']
  20. filenames = ['*.pony']
  21. _caps = r'(iso|trn|ref|val|box|tag)'
  22. tokens = {
  23. 'root': [
  24. (r'\n', Text),
  25. (r'[^\S\n]+', Text),
  26. (r'//.*\n', Comment.Single),
  27. (r'/\*', Comment.Multiline, 'nested_comment'),
  28. (r'"""(?:.|\n)*?"""', String.Doc),
  29. (r'"', String, 'string'),
  30. (r'\'.*\'', String.Char),
  31. (r'=>|[]{}:().~;,|&!^?[]', Punctuation),
  32. (words((
  33. 'addressof', 'and', 'as', 'consume', 'digestof', 'is', 'isnt',
  34. 'not', 'or'),
  35. suffix=r'\b'),
  36. Operator.Word),
  37. (r'!=|==|<<|>>|[-+/*%=<>]', Operator),
  38. (words((
  39. 'box', 'break', 'compile_error', 'compile_intrinsic',
  40. 'continue', 'do', 'else', 'elseif', 'embed', 'end', 'error',
  41. 'for', 'if', 'ifdef', 'in', 'iso', 'lambda', 'let', 'match',
  42. 'object', 'recover', 'ref', 'repeat', 'return', 'tag', 'then',
  43. 'this', 'trn', 'try', 'until', 'use', 'var', 'val', 'where',
  44. 'while', 'with', '#any', '#read', '#send', '#share'),
  45. suffix=r'\b'),
  46. Keyword),
  47. (r'(actor|class|struct|primitive|interface|trait|type)((?:\s)+)',
  48. bygroups(Keyword, Text), 'typename'),
  49. (r'(new|fun|be)((?:\s)+)', bygroups(Keyword, Text), 'methodname'),
  50. (words((
  51. 'I8', 'U8', 'I16', 'U16', 'I32', 'U32', 'I64', 'U64', 'I128',
  52. 'U128', 'ILong', 'ULong', 'ISize', 'USize', 'F32', 'F64',
  53. 'Bool', 'Pointer', 'None', 'Any', 'Array', 'String',
  54. 'Iterator'),
  55. suffix=r'\b'),
  56. Name.Builtin.Type),
  57. (r'_?[A-Z]\w*', Name.Type),
  58. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
  59. (r'0x[0-9a-fA-F]+', Number.Hex),
  60. (r'\d+', Number.Integer),
  61. (r'(true|false)\b', Name.Builtin),
  62. (r'_\d*', Name),
  63. (r'_?[a-z][\w\'_]*', Name)
  64. ],
  65. 'typename': [
  66. (_caps + r'?((?:\s)*)(_?[A-Z]\w*)',
  67. bygroups(Keyword, Text, Name.Class), '#pop')
  68. ],
  69. 'methodname': [
  70. (_caps + r'?((?:\s)*)(_?[a-z]\w*)',
  71. bygroups(Keyword, Text, Name.Function), '#pop')
  72. ],
  73. 'nested_comment': [
  74. (r'[^*/]+', Comment.Multiline),
  75. (r'/\*', Comment.Multiline, '#push'),
  76. (r'\*/', Comment.Multiline, '#pop'),
  77. (r'[*/]', Comment.Multiline)
  78. ],
  79. 'string': [
  80. (r'"', String, '#pop'),
  81. (r'\\"', String),
  82. (r'[^\\"]+', String)
  83. ]
  84. }