fift.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. pygments.lexers.fift
  3. ~~~~~~~~~~~~~~~~~~~~
  4. Lexers for fift.
  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, include
  9. from pygments.token import Literal, Comment, Name, String, Number, Whitespace
  10. __all__ = ['FiftLexer']
  11. class FiftLexer(RegexLexer):
  12. """
  13. For Fift source code.
  14. """
  15. name = 'Fift'
  16. aliases = ['fift', 'fif']
  17. filenames = ['*.fif']
  18. url = 'https://ton-blockchain.github.io/docs/fiftbase.pdf'
  19. tokens = {
  20. 'root': [
  21. (r'\s+', Whitespace),
  22. include('comments'),
  23. (r'[\.+]?\"', String, 'string'),
  24. # numbers
  25. (r'0x[0-9a-fA-F]+', Number.Hex),
  26. (r'0b[01]+', Number.Bin),
  27. (r'-?[0-9]+("/"-?[0-9]+)?', Number.Decimal),
  28. # slices
  29. (r'b\{[01]+\}', Literal),
  30. (r'x\{[0-9a-fA-F_]+\}', Literal),
  31. # byte literal
  32. (r'B\{[0-9a-fA-F_]+\}', Literal),
  33. # treat anything as word
  34. (r'\S+', Name)
  35. ],
  36. 'string': [
  37. (r'\\.', String.Escape),
  38. (r'\"', String, '#pop'),
  39. (r'[^\"\r\n\\]+', String)
  40. ],
  41. 'comments': [
  42. (r'//.*', Comment.Singleline),
  43. (r'/\*', Comment.Multiline, 'comment'),
  44. ],
  45. 'comment': [
  46. (r'[^/*]+', Comment.Multiline),
  47. (r'/\*', Comment.Multiline, '#push'),
  48. (r'\*/', Comment.Multiline, '#pop'),
  49. (r'[*/]', Comment.Multiline),
  50. ],
  51. }