Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/bqn.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1""" 

2 pygments.lexers.bqn 

3 ~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for BQN. 

6 

7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer 

12from pygments.token import Comment, Operator, Keyword, Name, String, \ 

13 Number, Punctuation, Whitespace 

14 

15__all__ = ['BQNLexer'] 

16 

17 

18class BQNLexer(RegexLexer): 

19 """ 

20 A simple BQN lexer. 

21 """ 

22 name = 'BQN' 

23 url = 'https://mlochbaum.github.io/BQN/index.html' 

24 aliases = ['bqn'] 

25 filenames = ['*.bqn'] 

26 mimetypes = [] 

27 version_added = '2.16' 

28 

29 # An inter_word_char. Necessary because \w matches all alphanumeric 

30 # Unicode characters, including ones (e.g., 𝕊) that BQN treats special. 

31 _iwc = r'((?=[^𝕎𝕏𝔽𝔾𝕊𝕨𝕩𝕗𝕘𝕤𝕣])\w)' 

32 

33 tokens = { 

34 'root': [ 

35 # Whitespace 

36 # ========== 

37 (r'\s+', Whitespace), 

38 # 

39 # Comment 

40 # ======= 

41 # '#' is a comment that continues to the end of the line 

42 (r'#.*$', Comment.Single), 

43 # 

44 # Strings 

45 # ======= 

46 (r'\'((\'\')|[^\'])*\'', String.Single), 

47 (r'"(("")|[^"])*"', String.Double), 

48 # 

49 # Null Character 

50 # ============== 

51 # Literal representation of the null character 

52 (r'@', String.Symbol), 

53 # 

54 # Punctuation 

55 # =========== 

56 # This token type is used for diamond, commas 

57 # and array and list brackets and strand syntax 

58 (r'[\.⋄,\[\]⟨⟩‿]', Punctuation), 

59 # 

60 # Expression Grouping 

61 # =================== 

62 # Since this token type is important in BQN, it is not included in 

63 # the punctuation token type but rather in the following one 

64 (r'[\(\)]', String.Regex), 

65 # 

66 # Numbers 

67 # ======= 

68 # Includes the numeric literals and the Nothing character 

69 (r'¯?[0-9](([0-9]|_)*\.?([0-9]|_)+|([0-9]|_)*)([Ee][¯]?([0-9]|_)+)?|¯|∞|π|·', Number), 

70 # 

71 # Variables 

72 # ========= 

73 (r'[a-z]' + _iwc + r'*', Name.Variable), 

74 # 

75 # 2-Modifiers 

76 # =========== 

77 # Needs to come before the 1-modifiers due to _𝕣 and _𝕣_ 

78 (r'[∘○⊸⟜⌾⊘◶⎉⚇⍟⎊]', Name.Property), 

79 (r'_(𝕣|[a-zA-Z0-9]+)_', Name.Property), 

80 # 

81 # 1-Modifiers 

82 # =========== 

83 (r'[˙˜˘¨⌜⁼´˝`𝕣]', Name.Attribute), 

84 (r'_(𝕣|[a-zA-Z0-9]+)', Name.Attribute), 

85 # 

86 # Functions 

87 # ========= 

88 # The monadic or dyadic function primitives and function 

89 # operands and arguments, along with function self-reference 

90 (r'[+\-×÷\⋆√⌊⌈∧∨¬|≤<>≥=≠≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!𝕎𝕏𝔽𝔾𝕊]', 

91 Operator), 

92 (r'[A-Z]' + _iwc + r'*|•' + _iwc + r'+', Operator), 

93 # 

94 # Constant 

95 # ======== 

96 (r'˙', Name.Constant), 

97 # 

98 # Define/Export/Change 

99 # ==================== 

100 (r'[←↩⇐]', Keyword.Declaration), 

101 # 

102 # Blocks 

103 # ====== 

104 (r'[{}]', Keyword.Type), 

105 # 

106 # Extra characters 

107 # ================ 

108 (r'[;:?𝕨𝕩𝕗𝕘𝕤]', Name.Entity), 

109 # 

110 

111 ], 

112 }