Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/apl.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

11 statements  

1""" 

2 pygments.lexers.apl 

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

4 

5 Lexers for APL. 

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__ = ['APLLexer'] 

16 

17 

18class APLLexer(RegexLexer): 

19 """ 

20 A simple APL lexer. 

21 """ 

22 name = 'APL' 

23 url = 'https://en.m.wikipedia.org/wiki/APL_(programming_language)' 

24 aliases = ['apl'] 

25 filenames = [ 

26 '*.apl', '*.aplf', '*.aplo', '*.apln', 

27 '*.aplc', '*.apli', '*.dyalog', 

28 ] 

29 version_added = '2.0' 

30 

31 tokens = { 

32 'root': [ 

33 # Whitespace 

34 # ========== 

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

36 # 

37 # Comment 

38 # ======= 

39 # '⍝' is traditional; '#' is supported by GNU APL and NGN (but not Dyalog) 

40 (r'[⍝#].*$', Comment.Single), 

41 # 

42 # Strings 

43 # ======= 

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

45 (r'"(("")|[^"])*"', String.Double), # supported by NGN APL 

46 # 

47 # Punctuation 

48 # =========== 

49 # This token type is used for diamond and parenthesis 

50 # but not for bracket and ; (see below) 

51 (r'[⋄◇()]', Punctuation), 

52 # 

53 # Array indexing 

54 # ============== 

55 # Since this token type is very important in APL, it is not included in 

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

57 (r'[\[\];]', String.Regex), 

58 # 

59 # Distinguished names 

60 # =================== 

61 # following IBM APL2 standard 

62 (r'⎕[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Function), 

63 # 

64 # Labels 

65 # ====== 

66 # following IBM APL2 standard 

67 # (r'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*:', Name.Label), 

68 # 

69 # Variables 

70 # ========= 

71 # following IBM APL2 standard (with a leading _ ok for GNU APL and Dyalog) 

72 (r'[A-Za-zΔ∆⍙_][A-Za-zΔ∆⍙_¯0-9]*', Name.Variable), 

73 # 

74 # Numbers 

75 # ======= 

76 (r'¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞)' 

77 r'([Jj]¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞))?', 

78 Number), 

79 # 

80 # Operators 

81 # ========== 

82 (r'[\.\\\/⌿⍀¨⍣⍨⍠⍤∘⌸&⌶@⌺⍥⍛⍢]', Name.Attribute), # closest token type 

83 (r'[+\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗⊆⊇⍸√⌾…⍮]', 

84 Operator), 

85 # 

86 # Constant 

87 # ======== 

88 (r'⍬', Name.Constant), 

89 # 

90 # Quad symbol 

91 # =========== 

92 (r'[⎕⍞]', Name.Variable.Global), 

93 # 

94 # Arrows left/right 

95 # ================= 

96 (r'[←→]', Keyword.Declaration), 

97 # 

98 # D-Fn 

99 # ==== 

100 (r'[⍺⍵⍶⍹∇:]', Name.Builtin.Pseudo), 

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

102 ], 

103 }