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