codekingpro/portable-devtools
114k
1"""2 pygments.lexers.apl3 ~~~~~~~~~~~~~~~~~~~4 5 Lexers for APL.6 7 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.8 :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer12from pygments.token import Comment, Operator, Keyword, Name, String, \13 Number, Punctuation, Whitespace14 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 # Whitespace34 # ==========35 (r'\s+', Whitespace),36 #37 # Comment38 # =======39 # '⍝' is traditional; '#' is supported by GNU APL and NGN (but not Dyalog)40 (r'[⍝#].*$', Comment.Single),41 #42 # Strings43 # =======44 (r'\'((\'\')|[^\'])*\'', String.Single),45 (r'"(("")|[^"])*"', String.Double), # supported by NGN APL46 #47 # Punctuation48 # ===========49 # This token type is used for diamond and parenthesis50 # but not for bracket and ; (see below)51 (r'[⋄◇()]', Punctuation),52 #53 # Array indexing54 # ==============55 # Since this token type is very important in APL, it is not included in56 # the punctuation token type but rather in the following one57 (r'[\[\];]', String.Regex),58 #59 # Distinguished names60 # ===================61 # following IBM APL2 standard62 (r'⎕[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*', Name.Function),63 #64 # Labels65 # ======66 # following IBM APL2 standard67 # (r'[A-Za-zΔ∆⍙][A-Za-zΔ∆⍙_¯0-9]*:', Name.Label),68 #69 # Variables70 # =========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 # Numbers75 # =======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 # Operators81 # ==========82 (r'[\.\\\/⌿⍀¨⍣⍨⍠⍤∘⌸&⌶@⌺⍥⍛⍢]', Name.Attribute), # closest token type83 (r'[+\-×÷⌈⌊∣|⍳?*⍟○!⌹<≤=>≥≠≡≢∊⍷∪∩~∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢⍁⍂≈⌸⍯↗⊆⊇⍸√⌾…⍮]',84 Operator),85 #86 # Constant87 # ========88 (r'⍬', Name.Constant),89 #90 # Quad symbol91 # ===========92 (r'[⎕⍞]', Name.Variable.Global),93 #94 # Arrows left/right95 # =================96 (r'[←→]', Keyword.Declaration),97 #98 # D-Fn99 # ====100 (r'[⍺⍵⍶⍹∇:]', Name.Builtin.Pseudo),101 (r'[{}]', Keyword.Type),102 ],103 }104 