pointless.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. pygments.lexers.pointless
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for Pointless.
  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 Comment, Error, Keyword, Name, Number, Operator, \
  10. Punctuation, String, Text
  11. __all__ = ['PointlessLexer']
  12. class PointlessLexer(RegexLexer):
  13. """
  14. For `Pointless <https://ptls.dev>`_ source code.
  15. .. versionadded:: 2.7
  16. """
  17. name = 'Pointless'
  18. aliases = ['pointless']
  19. filenames = ['*.ptls']
  20. ops = words([
  21. "+", "-", "*", "/", "**", "%", "+=", "-=", "*=",
  22. "/=", "**=", "%=", "|>", "=", "==", "!=", "<", ">",
  23. "<=", ">=", "=>", "$", "++",
  24. ])
  25. keywords = words([
  26. "if", "then", "else", "where", "with", "cond",
  27. "case", "and", "or", "not", "in", "as", "for",
  28. "requires", "throw", "try", "catch", "when",
  29. "yield", "upval",
  30. ], suffix=r'\b')
  31. tokens = {
  32. 'root': [
  33. (r'[ \n\r]+', Text),
  34. (r'--.*$', Comment.Single),
  35. (r'"""', String, 'multiString'),
  36. (r'"', String, 'string'),
  37. (r'[\[\](){}:;,.]', Punctuation),
  38. (ops, Operator),
  39. (keywords, Keyword),
  40. (r'\d+|\d*\.\d+', Number),
  41. (r'(true|false)\b', Name.Builtin),
  42. (r'[A-Z][a-zA-Z0-9]*\b', String.Symbol),
  43. (r'output\b', Name.Variable.Magic),
  44. (r'(export|import)\b', Keyword.Namespace),
  45. (r'[a-z][a-zA-Z0-9]*\b', Name.Variable)
  46. ],
  47. 'multiString': [
  48. (r'\\.', String.Escape),
  49. (r'"""', String, '#pop'),
  50. (r'"', String),
  51. (r'[^\\"]+', String),
  52. ],
  53. 'string': [
  54. (r'\\.', String.Escape),
  55. (r'"', String, '#pop'),
  56. (r'\n', Error),
  57. (r'[^\\"]+', String),
  58. ],
  59. }