nit.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. pygments.lexers.nit
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for the Nit 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, words
  9. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  10. Number, Punctuation
  11. __all__ = ['NitLexer']
  12. class NitLexer(RegexLexer):
  13. """
  14. For `nit <http://nitlanguage.org>`_ source.
  15. .. versionadded:: 2.0
  16. """
  17. name = 'Nit'
  18. aliases = ['nit']
  19. filenames = ['*.nit']
  20. tokens = {
  21. 'root': [
  22. (r'#.*?$', Comment.Single),
  23. (words((
  24. 'package', 'module', 'import', 'class', 'abstract', 'interface',
  25. 'universal', 'enum', 'end', 'fun', 'type', 'init', 'redef',
  26. 'isa', 'do', 'readable', 'writable', 'var', 'intern', 'extern',
  27. 'public', 'protected', 'private', 'intrude', 'if', 'then',
  28. 'else', 'while', 'loop', 'for', 'in', 'and', 'or', 'not',
  29. 'implies', 'return', 'continue', 'break', 'abort', 'assert',
  30. 'new', 'is', 'once', 'super', 'self', 'true', 'false', 'nullable',
  31. 'null', 'as', 'isset', 'label', '__debug__'), suffix=r'(?=[\r\n\t( ])'),
  32. Keyword),
  33. (r'[A-Z]\w*', Name.Class),
  34. (r'"""(([^\'\\]|\\.)|\\r|\\n)*((\{\{?)?(""?\{\{?)*""""*)', String), # Simple long string
  35. (r'\'\'\'(((\\.|[^\'\\])|\\r|\\n)|\'((\\.|[^\'\\])|\\r|\\n)|'
  36. r'\'\'((\\.|[^\'\\])|\\r|\\n))*\'\'\'', String), # Simple long string alt
  37. (r'"""(([^\'\\]|\\.)|\\r|\\n)*((""?)?(\{\{?""?)*\{\{\{\{*)', String), # Start long string
  38. (r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(""?)?(\{\{?""?)*\{\{\{\{*', String), # Mid long string
  39. (r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(\{\{?)?(""?\{\{?)*""""*', String), # End long string
  40. (r'"(\\.|([^"}{\\]))*"', String), # Simple String
  41. (r'"(\\.|([^"}{\\]))*\{', String), # Start string
  42. (r'\}(\\.|([^"}{\\]))*\{', String), # Mid String
  43. (r'\}(\\.|([^"}{\\]))*"', String), # End String
  44. (r'(\'[^\'\\]\')|(\'\\.\')', String.Char),
  45. (r'[0-9]+', Number.Integer),
  46. (r'[0-9]*.[0-9]+', Number.Float),
  47. (r'0(x|X)[0-9A-Fa-f]+', Number.Hex),
  48. (r'[a-z]\w*', Name),
  49. (r'_\w+', Name.Variable.Instance),
  50. (r'==|!=|<==>|>=|>>|>|<=|<<|<|\+|-|=|/|\*|%|\+=|-=|!|@', Operator),
  51. (r'\(|\)|\[|\]|,|\.\.\.|\.\.|\.|::|:', Punctuation),
  52. (r'`\{[^`]*`\}', Text), # Extern blocks won't be Lexed by Nit
  53. (r'[\r\n\t ]+', Text),
  54. ],
  55. }