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

9 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-18 06:13 +0000

1""" 

2 pygments.lexers.apl 

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

4 

5 Lexers for APL. 

6 

7 :copyright: Copyright 2006-2023 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 .. versionadded:: 2.0 

23 """ 

24 name = 'APL' 

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

26 aliases = ['apl'] 

27 filenames = [ 

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

29 '*.aplc', '*.apli', '*.dyalog', 

30 ] 

31 

32 tokens = { 

33 'root': [ 

34 # Whitespace 

35 # ========== 

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

37 # 

38 # Comment 

39 # ======= 

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

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

42 # 

43 # Strings 

44 # ======= 

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

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

47 # 

48 # Punctuation 

49 # =========== 

50 # This token type is used for diamond and parenthesis 

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

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

53 # 

54 # Array indexing 

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

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

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

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

59 # 

60 # Distinguished names 

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

62 # following IBM APL2 standard 

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

64 # 

65 # Labels 

66 # ====== 

67 # following IBM APL2 standard 

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

69 # 

70 # Variables 

71 # ========= 

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

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

74 # 

75 # Numbers 

76 # ======= 

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

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

79 Number), 

80 # 

81 # Operators 

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

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

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

85 Operator), 

86 # 

87 # Constant 

88 # ======== 

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

90 # 

91 # Quad symbol 

92 # =========== 

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

94 # 

95 # Arrows left/right 

96 # ================= 

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

98 # 

99 # D-Fn 

100 # ==== 

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

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

103 ], 

104 }