pony.py 3.2 KB

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