nit.py 2.7 KB

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