bqn.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. """
  2. pygments.lexers.bqn
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for BQN.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer
  9. from pygments.token import Comment, Operator, Keyword, Name, String, \
  10. Number, Punctuation, Whitespace
  11. __all__ = ['BQNLexer']
  12. class BQNLexer(RegexLexer):
  13. """
  14. A simple BQN lexer.
  15. """
  16. name = 'BQN'
  17. url = 'https://mlochbaum.github.io/BQN/index.html'
  18. aliases = ['bqn']
  19. filenames = ['*.bqn']
  20. mimetypes = []
  21. version_added = '2.16'
  22. tokens = {
  23. 'root': [
  24. # Whitespace
  25. # ==========
  26. (r'\s+', Whitespace),
  27. #
  28. # Comment
  29. # =======
  30. # '#' is a comment that continues to the end of the line
  31. (r'#.*$', Comment.Single),
  32. #
  33. # Strings
  34. # =======
  35. (r'\'((\'\')|[^\'])*\'', String.Single),
  36. (r'"(("")|[^"])*"', String.Double),
  37. #
  38. # Null Character
  39. # ==============
  40. # Literal representation of the null character
  41. (r'@', String.Symbol),
  42. #
  43. # Punctuation
  44. # ===========
  45. # This token type is used for diamond, commas
  46. # and array and list brackets and strand syntax
  47. (r'[\.⋄,\[\]⟨⟩‿]', Punctuation),
  48. #
  49. # Expression Grouping
  50. # ===================
  51. # Since this token type is important in BQN, it is not included in
  52. # the punctuation token type but rather in the following one
  53. (r'[\(\)]', String.Regex),
  54. #
  55. # Numbers
  56. # =======
  57. # Includes the numeric literals and the Nothing character
  58. (r'¯?([0-9]+\.?[0-9]+|[0-9]+)([Ee][¯]?[0-9]+)?|¯|∞|π|·', Number),
  59. #
  60. # Variables
  61. # =========
  62. (r'\b[a-z]\w*\b', Name.Variable),
  63. #
  64. # 1-Modifiers
  65. # ===========
  66. (r'[˙˜˘¨⌜⁼´˝`𝕣]', Name.Attribute),
  67. (r'\b_[a-zA-Z0-9]+\b', Name.Attribute),
  68. #
  69. # 2-Modifiers
  70. # ===========
  71. (r'[∘○⊸⟜⌾⊘◶⎉⚇⍟⎊]', Name.Property),
  72. (r'\b_[a-zA-Z0-9]+_\b', Name.Property),
  73. #
  74. # Functions
  75. # =========
  76. # The monadic or dyadic function primitives and function
  77. # operands and arguments, along with function self-reference
  78. (r'[+\-×÷\*√⌊⌈∧∨¬|≤<>≥=≠≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!𝕎𝕏𝔽𝔾𝕊]',
  79. Operator),
  80. (r'[A-Z]\w*|•\w+\b', Operator),
  81. #
  82. # Constant
  83. # ========
  84. (r'˙', Name.Constant),
  85. #
  86. # Define/Export/Change
  87. # ====================
  88. (r'[←↩⇐]', Keyword.Declaration),
  89. #
  90. # Blocks
  91. # ======
  92. (r'[{}]', Keyword.Type),
  93. #
  94. # Extra characters
  95. # ================
  96. (r'[;:?𝕨𝕩𝕗𝕘𝕤]', Name.Entity),
  97. #
  98. ],
  99. }