eric6/ThirdParty/Pygments/pygments/lexers/j.py

changeset 6942
2602857055c5
parent 6651
e8f3b5568b21
child 7547
21b0534faebc
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.j
4 ~~~~~~~~~~~~~~~~~
5
6 Lexer for the J programming language.
7
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 from pygments.lexer import RegexLexer, words, include
13 from pygments.token import Comment, Keyword, Name, Number, Operator, Punctuation, \
14 String, Text
15
16 __all__ = ['JLexer']
17
18
19 class JLexer(RegexLexer):
20 """
21 For `J <http://jsoftware.com/>`_ source code.
22
23 .. versionadded:: 2.1
24 """
25
26 name = 'J'
27 aliases = ['j']
28 filenames = ['*.ijs']
29 mimetypes = ['text/x-j']
30
31 validName = r'\b[a-zA-Z]\w*'
32
33 tokens = {
34 'root': [
35 # Shebang script
36 (r'#!.*$', Comment.Preproc),
37
38 # Comments
39 (r'NB\..*', Comment.Single),
40 (r'\n+\s*Note', Comment.Multiline, 'comment'),
41 (r'\s*Note.*', Comment.Single),
42
43 # Whitespace
44 (r'\s+', Text),
45
46 # Strings
47 (r"'", String, 'singlequote'),
48
49 # Definitions
50 (r'0\s+:\s*0|noun\s+define\s*$', Name.Entity, 'nounDefinition'),
51 (r'(([1-4]|13)\s+:\s*0|(adverb|conjunction|dyad|monad|verb)\s+define)\b',
52 Name.Function, 'explicitDefinition'),
53
54 # Flow Control
55 (words(('for_', 'goto_', 'label_'), suffix=validName+r'\.'), Name.Label),
56 (words((
57 'assert', 'break', 'case', 'catch', 'catchd',
58 'catcht', 'continue', 'do', 'else', 'elseif',
59 'end', 'fcase', 'for', 'if', 'return',
60 'select', 'throw', 'try', 'while', 'whilst',
61 ), suffix=r'\.'), Name.Label),
62
63 # Variable Names
64 (validName, Name.Variable),
65
66 # Standard Library
67 (words((
68 'ARGV', 'CR', 'CRLF', 'DEL', 'Debug',
69 'EAV', 'EMPTY', 'FF', 'JVERSION', 'LF',
70 'LF2', 'Note', 'TAB', 'alpha17', 'alpha27',
71 'apply', 'bind', 'boxopen', 'boxxopen', 'bx',
72 'clear', 'cutLF', 'cutopen', 'datatype', 'def',
73 'dfh', 'drop', 'each', 'echo', 'empty',
74 'erase', 'every', 'evtloop', 'exit', 'expand',
75 'fetch', 'file2url', 'fixdotdot', 'fliprgb', 'getargs',
76 'getenv', 'hfd', 'inv', 'inverse', 'iospath',
77 'isatty', 'isutf8', 'items', 'leaf', 'list',
78 'nameclass', 'namelist', 'names', 'nc',
79 'nl', 'on', 'pick', 'rows',
80 'script', 'scriptd', 'sign', 'sminfo', 'smoutput',
81 'sort', 'split', 'stderr', 'stdin', 'stdout',
82 'table', 'take', 'timespacex', 'timex', 'tmoutput',
83 'toCRLF', 'toHOST', 'toJ', 'tolower', 'toupper',
84 'type', 'ucp', 'ucpcount', 'usleep', 'utf8',
85 'uucp',
86 )), Name.Function),
87
88 # Copula
89 (r'=[.:]', Operator),
90
91 # Builtins
92 (r'[-=+*#$%@!~`^&";:.,<>{}\[\]\\|/]', Operator),
93
94 # Short Keywords
95 (r'[abCdDeEfHiIjLMoprtT]\.', Keyword.Reserved),
96 (r'[aDiLpqsStux]\:', Keyword.Reserved),
97 (r'(_[0-9])\:', Keyword.Constant),
98
99 # Parens
100 (r'\(', Punctuation, 'parentheses'),
101
102 # Numbers
103 include('numbers'),
104 ],
105
106 'comment': [
107 (r'[^)]', Comment.Multiline),
108 (r'^\)', Comment.Multiline, '#pop'),
109 (r'[)]', Comment.Multiline),
110 ],
111
112 'explicitDefinition': [
113 (r'\b[nmuvxy]\b', Name.Decorator),
114 include('root'),
115 (r'[^)]', Name),
116 (r'^\)', Name.Label, '#pop'),
117 (r'[)]', Name),
118 ],
119
120 'numbers': [
121 (r'\b_{1,2}\b', Number),
122 (r'_?\d+(\.\d+)?(\s*[ejr]\s*)_?\d+(\.?=\d+)?', Number),
123 (r'_?\d+\.(?=\d+)', Number.Float),
124 (r'_?\d+x', Number.Integer.Long),
125 (r'_?\d+', Number.Integer),
126 ],
127
128 'nounDefinition': [
129 (r'[^)]', String),
130 (r'^\)', Name.Label, '#pop'),
131 (r'[)]', String),
132 ],
133
134 'parentheses': [
135 (r'\)', Punctuation, '#pop'),
136 # include('nounDefinition'),
137 include('explicitDefinition'),
138 include('root'),
139 ],
140
141 'singlequote': [
142 (r"[^']", String),
143 (r"''", String),
144 (r"'", String, '#pop'),
145 ],
146 }

eric ide

mercurial