pointless.py 1.9 KB

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