3 pygments.lexers.apl |
3 pygments.lexers.apl |
4 ~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for APL. |
6 Lexers for APL. |
7 |
7 |
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from pygments.lexer import RegexLexer |
12 from pygments.lexer import RegexLexer |
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
33 (r'\s+', Text), |
33 (r'\s+', Text), |
34 # |
34 # |
35 # Comment |
35 # Comment |
36 # ======= |
36 # ======= |
37 # '⍝' is traditional; '#' is supported by GNU APL and NGN (but not Dyalog) |
37 # '⍝' is traditional; '#' is supported by GNU APL and NGN (but not Dyalog) |
38 (u'[⍝#].*$', Comment.Single), |
38 (r'[⍝#].*$', Comment.Single), |
39 # |
39 # |
40 # Strings |
40 # Strings |
41 # ======= |
41 # ======= |
42 (r'\'((\'\')|[^\'])*\'', String.Single), |
42 (r'\'((\'\')|[^\'])*\'', String.Single), |
43 (r'"(("")|[^"])*"', String.Double), # supported by NGN APL |
43 (r'"(("")|[^"])*"', String.Double), # supported by NGN APL |
44 # |
44 # |
45 # Punctuation |
45 # Punctuation |
46 # =========== |
46 # =========== |
47 # This token type is used for diamond and parenthesis |
47 # This token type is used for diamond and parenthesis |
48 # but not for bracket and ; (see below) |
48 # but not for bracket and ; (see below) |
49 (u'[⋄◇()]', Punctuation), |
49 (r'[⋄◇()]', Punctuation), |
50 # |
50 # |
51 # Array indexing |
51 # Array indexing |
52 # ============== |
52 # ============== |
53 # Since this token type is very important in APL, it is not included in |
53 # Since this token type is very important in APL, it is not included in |
54 # the punctuation token type but rather in the following one |
54 # the punctuation token type but rather in the following one |
55 (r'[\[\];]', String.Regex), |
55 (r'[\[\];]', String.Regex), |
56 # |
56 # |
57 # Distinguished names |
57 # Distinguished names |
58 # =================== |
58 # =================== |
59 # following IBM APL2 standard |
59 # following IBM APL2 standard |
60 (u'⎕[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Function), |
60 (r'⎕[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Function), |
61 # |
61 # |
62 # Labels |
62 # Labels |
63 # ====== |
63 # ====== |
64 # following IBM APL2 standard |
64 # following IBM APL2 standard |
65 # (u'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*:', Name.Label), |
65 # (r'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*:', Name.Label), |
66 # |
66 # |
67 # Variables |
67 # Variables |
68 # ========= |
68 # ========= |
69 # following IBM APL2 standard |
69 # following IBM APL2 standard |
70 (u'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Variable), |
70 (r'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Variable), |
71 # |
71 # |
72 # Numbers |
72 # Numbers |
73 # ======= |
73 # ======= |
74 (u'¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞)' |
74 (r'¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞)' |
75 u'([Jj]¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞))?', |
75 r'([Jj]¯?(0[Xx][0-9A-Fa-f]+|[0-9]*\.?[0-9]+([Ee][+¯]?[0-9]+)?|¯|∞))?', |
76 Number), |
76 Number), |
77 # |
77 # |
78 # Operators |
78 # Operators |
79 # ========== |
79 # ========== |
80 (u'[\\.\\\\\\/⌿⍀¨⍣⍨⍠⍤∘]', Name.Attribute), # closest token type |
80 (r'[\.\\\/⌿⍀¨⍣⍨⍠⍤∘⌸&⌶@⌺⍥⍛⍢]', Name.Attribute), # closest token type |
81 (u'[+\\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗]', |
81 (r'[+\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗⊆⊇⍸√⌾…⍮]', |
82 Operator), |
82 Operator), |
83 # |
83 # |
84 # Constant |
84 # Constant |
85 # ======== |
85 # ======== |
86 (u'⍬', Name.Constant), |
86 (r'⍬', Name.Constant), |
87 # |
87 # |
88 # Quad symbol |
88 # Quad symbol |
89 # =========== |
89 # =========== |
90 (u'[⎕⍞]', Name.Variable.Global), |
90 (r'[⎕⍞]', Name.Variable.Global), |
91 # |
91 # |
92 # Arrows left/right |
92 # Arrows left/right |
93 # ================= |
93 # ================= |
94 (u'[←→]', Keyword.Declaration), |
94 (r'[←→]', Keyword.Declaration), |
95 # |
95 # |
96 # D-Fn |
96 # D-Fn |
97 # ==== |
97 # ==== |
98 (u'[⍺⍵⍶⍹∇:]', Name.Builtin.Pseudo), |
98 (r'[⍺⍵⍶⍹∇:]', Name.Builtin.Pseudo), |
99 (r'[{}]', Keyword.Type), |
99 (r'[{}]', Keyword.Type), |
100 ], |
100 ], |
101 } |
101 } |