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

changeset 6942
2602857055c5
parent 5713
6762afd9f963
child 7547
21b0534faebc
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.factor
4 ~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexers for the Factor language.
7
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 import re
13
14 from pygments.lexer import RegexLexer, bygroups, default, words
15 from pygments.token import Text, Comment, Keyword, Name, String, Number
16
17 __all__ = ['FactorLexer']
18
19
20 class FactorLexer(RegexLexer):
21 """
22 Lexer for the `Factor <http://factorcode.org>`_ language.
23
24 .. versionadded:: 1.4
25 """
26 name = 'Factor'
27 aliases = ['factor']
28 filenames = ['*.factor']
29 mimetypes = ['text/x-factor']
30
31 flags = re.MULTILINE | re.UNICODE
32
33 builtin_kernel = words((
34 '-rot', '2bi', '2bi@', '2bi*', '2curry', '2dip', '2drop', '2dup', '2keep', '2nip',
35 '2over', '2tri', '2tri@', '2tri*', '3bi', '3curry', '3dip', '3drop', '3dup', '3keep',
36 '3tri', '4dip', '4drop', '4dup', '4keep', '<wrapper>', '=', '>boolean', 'clone',
37 '?', '?execute', '?if', 'and', 'assert', 'assert=', 'assert?', 'bi', 'bi-curry',
38 'bi-curry@', 'bi-curry*', 'bi@', 'bi*', 'boa', 'boolean', 'boolean?', 'both?',
39 'build', 'call', 'callstack', 'callstack>array', 'callstack?', 'clear', '(clone)',
40 'compose', 'compose?', 'curry', 'curry?', 'datastack', 'die', 'dip', 'do', 'drop',
41 'dup', 'dupd', 'either?', 'eq?', 'equal?', 'execute', 'hashcode', 'hashcode*',
42 'identity-hashcode', 'identity-tuple', 'identity-tuple?', 'if', 'if*',
43 'keep', 'loop', 'most', 'new', 'nip', 'not', 'null', 'object', 'or', 'over',
44 'pick', 'prepose', 'retainstack', 'rot', 'same?', 'swap', 'swapd', 'throw',
45 'tri', 'tri-curry', 'tri-curry@', 'tri-curry*', 'tri@', 'tri*', 'tuple',
46 'tuple?', 'unless', 'unless*', 'until', 'when', 'when*', 'while', 'with',
47 'wrapper', 'wrapper?', 'xor'), suffix=r'\s')
48
49 builtin_assocs = words((
50 '2cache', '<enum>', '>alist', '?at', '?of', 'assoc', 'assoc-all?',
51 'assoc-any?', 'assoc-clone-like', 'assoc-combine', 'assoc-diff',
52 'assoc-diff!', 'assoc-differ', 'assoc-each', 'assoc-empty?',
53 'assoc-filter', 'assoc-filter!', 'assoc-filter-as', 'assoc-find',
54 'assoc-hashcode', 'assoc-intersect', 'assoc-like', 'assoc-map',
55 'assoc-map-as', 'assoc-partition', 'assoc-refine', 'assoc-size',
56 'assoc-stack', 'assoc-subset?', 'assoc-union', 'assoc-union!',
57 'assoc=', 'assoc>map', 'assoc?', 'at', 'at+', 'at*', 'cache', 'change-at',
58 'clear-assoc', 'delete-at', 'delete-at*', 'enum', 'enum?', 'extract-keys',
59 'inc-at', 'key?', 'keys', 'map>assoc', 'maybe-set-at', 'new-assoc', 'of',
60 'push-at', 'rename-at', 'set-at', 'sift-keys', 'sift-values', 'substitute',
61 'unzip', 'value-at', 'value-at*', 'value?', 'values', 'zip'), suffix=r'\s')
62
63 builtin_combinators = words((
64 '2cleave', '2cleave>quot', '3cleave', '3cleave>quot', '4cleave',
65 '4cleave>quot', 'alist>quot', 'call-effect', 'case', 'case-find',
66 'case>quot', 'cleave', 'cleave>quot', 'cond', 'cond>quot', 'deep-spread>quot',
67 'execute-effect', 'linear-case-quot', 'no-case', 'no-case?', 'no-cond',
68 'no-cond?', 'recursive-hashcode', 'shallow-spread>quot', 'spread',
69 'to-fixed-point', 'wrong-values', 'wrong-values?'), suffix=r'\s')
70
71 builtin_math = words((
72 '-', '/', '/f', '/i', '/mod', '2/', '2^', '<', '<=', '<fp-nan>', '>',
73 '>=', '>bignum', '>fixnum', '>float', '>integer', '(all-integers?)',
74 '(each-integer)', '(find-integer)', '*', '+', '?1+',
75 'abs', 'align', 'all-integers?', 'bignum', 'bignum?', 'bit?', 'bitand',
76 'bitnot', 'bitor', 'bits>double', 'bits>float', 'bitxor', 'complex',
77 'complex?', 'denominator', 'double>bits', 'each-integer', 'even?',
78 'find-integer', 'find-last-integer', 'fixnum', 'fixnum?', 'float',
79 'float>bits', 'float?', 'fp-bitwise=', 'fp-infinity?', 'fp-nan-payload',
80 'fp-nan?', 'fp-qnan?', 'fp-sign', 'fp-snan?', 'fp-special?',
81 'if-zero', 'imaginary-part', 'integer', 'integer>fixnum',
82 'integer>fixnum-strict', 'integer?', 'log2', 'log2-expects-positive',
83 'log2-expects-positive?', 'mod', 'neg', 'neg?', 'next-float',
84 'next-power-of-2', 'number', 'number=', 'number?', 'numerator', 'odd?',
85 'out-of-fixnum-range', 'out-of-fixnum-range?', 'power-of-2?',
86 'prev-float', 'ratio', 'ratio?', 'rational', 'rational?', 'real',
87 'real-part', 'real?', 'recip', 'rem', 'sgn', 'shift', 'sq', 'times',
88 'u<', 'u<=', 'u>', 'u>=', 'unless-zero', 'unordered?', 'when-zero',
89 'zero?'), suffix=r'\s')
90
91 builtin_sequences = words((
92 '1sequence', '2all?', '2each', '2map', '2map-as', '2map-reduce', '2reduce',
93 '2selector', '2sequence', '3append', '3append-as', '3each', '3map', '3map-as',
94 '3sequence', '4sequence', '<repetition>', '<reversed>', '<slice>', '?first',
95 '?last', '?nth', '?second', '?set-nth', 'accumulate', 'accumulate!',
96 'accumulate-as', 'all?', 'any?', 'append', 'append!', 'append-as',
97 'assert-sequence', 'assert-sequence=', 'assert-sequence?',
98 'binary-reduce', 'bounds-check', 'bounds-check?', 'bounds-error',
99 'bounds-error?', 'but-last', 'but-last-slice', 'cartesian-each',
100 'cartesian-map', 'cartesian-product', 'change-nth', 'check-slice',
101 'check-slice-error', 'clone-like', 'collapse-slice', 'collector',
102 'collector-for', 'concat', 'concat-as', 'copy', 'count', 'cut', 'cut-slice',
103 'cut*', 'delete-all', 'delete-slice', 'drop-prefix', 'each', 'each-from',
104 'each-index', 'empty?', 'exchange', 'filter', 'filter!', 'filter-as', 'find',
105 'find-from', 'find-index', 'find-index-from', 'find-last', 'find-last-from',
106 'first', 'first2', 'first3', 'first4', 'flip', 'follow', 'fourth', 'glue', 'halves',
107 'harvest', 'head', 'head-slice', 'head-slice*', 'head*', 'head?',
108 'if-empty', 'immutable', 'immutable-sequence', 'immutable-sequence?',
109 'immutable?', 'index', 'index-from', 'indices', 'infimum', 'infimum-by',
110 'insert-nth', 'interleave', 'iota', 'iota-tuple', 'iota-tuple?', 'join',
111 'join-as', 'last', 'last-index', 'last-index-from', 'length', 'lengthen',
112 'like', 'longer', 'longer?', 'longest', 'map', 'map!', 'map-as', 'map-find',
113 'map-find-last', 'map-index', 'map-integers', 'map-reduce', 'map-sum',
114 'max-length', 'member-eq?', 'member?', 'midpoint@', 'min-length',
115 'mismatch', 'move', 'new-like', 'new-resizable', 'new-sequence',
116 'non-negative-integer-expected', 'non-negative-integer-expected?',
117 'nth', 'nths', 'pad-head', 'pad-tail', 'padding', 'partition', 'pop', 'pop*',
118 'prefix', 'prepend', 'prepend-as', 'produce', 'produce-as', 'product', 'push',
119 'push-all', 'push-either', 'push-if', 'reduce', 'reduce-index', 'remove',
120 'remove!', 'remove-eq', 'remove-eq!', 'remove-nth', 'remove-nth!', 'repetition',
121 'repetition?', 'replace-slice', 'replicate', 'replicate-as', 'rest',
122 'rest-slice', 'reverse', 'reverse!', 'reversed', 'reversed?', 'second',
123 'selector', 'selector-for', 'sequence', 'sequence-hashcode', 'sequence=',
124 'sequence?', 'set-first', 'set-fourth', 'set-last', 'set-length', 'set-nth',
125 'set-second', 'set-third', 'short', 'shorten', 'shorter', 'shorter?',
126 'shortest', 'sift', 'slice', 'slice-error', 'slice-error?', 'slice?',
127 'snip', 'snip-slice', 'start', 'start*', 'subseq', 'subseq?', 'suffix',
128 'suffix!', 'sum', 'sum-lengths', 'supremum', 'supremum-by', 'surround', 'tail',
129 'tail-slice', 'tail-slice*', 'tail*', 'tail?', 'third', 'trim',
130 'trim-head', 'trim-head-slice', 'trim-slice', 'trim-tail', 'trim-tail-slice',
131 'unclip', 'unclip-last', 'unclip-last-slice', 'unclip-slice', 'unless-empty',
132 'virtual-exemplar', 'virtual-sequence', 'virtual-sequence?', 'virtual@',
133 'when-empty'), suffix=r'\s')
134
135 builtin_namespaces = words((
136 '+@', 'change', 'change-global', 'counter', 'dec', 'get', 'get-global',
137 'global', 'inc', 'init-namespaces', 'initialize', 'is-global', 'make-assoc',
138 'namespace', 'namestack', 'off', 'on', 'set', 'set-global', 'set-namestack',
139 'toggle', 'with-global', 'with-scope', 'with-variable', 'with-variables'),
140 suffix=r'\s')
141
142 builtin_arrays = words((
143 '1array', '2array', '3array', '4array', '<array>', '>array', 'array',
144 'array?', 'pair', 'pair?', 'resize-array'), suffix=r'\s')
145
146 builtin_io = words((
147 '(each-stream-block-slice)', '(each-stream-block)',
148 '(stream-contents-by-block)', '(stream-contents-by-element)',
149 '(stream-contents-by-length-or-block)',
150 '(stream-contents-by-length)', '+byte+', '+character+',
151 'bad-seek-type', 'bad-seek-type?', 'bl', 'contents', 'each-block',
152 'each-block-size', 'each-block-slice', 'each-line', 'each-morsel',
153 'each-stream-block', 'each-stream-block-slice', 'each-stream-line',
154 'error-stream', 'flush', 'input-stream', 'input-stream?',
155 'invalid-read-buffer', 'invalid-read-buffer?', 'lines', 'nl',
156 'output-stream', 'output-stream?', 'print', 'read', 'read-into',
157 'read-partial', 'read-partial-into', 'read-until', 'read1', 'readln',
158 'seek-absolute', 'seek-absolute?', 'seek-end', 'seek-end?',
159 'seek-input', 'seek-output', 'seek-relative', 'seek-relative?',
160 'stream-bl', 'stream-contents', 'stream-contents*', 'stream-copy',
161 'stream-copy*', 'stream-element-type', 'stream-flush',
162 'stream-length', 'stream-lines', 'stream-nl', 'stream-print',
163 'stream-read', 'stream-read-into', 'stream-read-partial',
164 'stream-read-partial-into', 'stream-read-partial-unsafe',
165 'stream-read-unsafe', 'stream-read-until', 'stream-read1',
166 'stream-readln', 'stream-seek', 'stream-seekable?', 'stream-tell',
167 'stream-write', 'stream-write1', 'tell-input', 'tell-output',
168 'with-error-stream', 'with-error-stream*', 'with-error>output',
169 'with-input-output+error-streams',
170 'with-input-output+error-streams*', 'with-input-stream',
171 'with-input-stream*', 'with-output-stream', 'with-output-stream*',
172 'with-output>error', 'with-output+error-stream',
173 'with-output+error-stream*', 'with-streams', 'with-streams*',
174 'write', 'write1'), suffix=r'\s')
175
176 builtin_strings = words((
177 '1string', '<string>', '>string', 'resize-string', 'string',
178 'string?'), suffix=r'\s')
179
180 builtin_vectors = words((
181 '1vector', '<vector>', '>vector', '?push', 'vector', 'vector?'),
182 suffix=r'\s')
183
184 builtin_continuations = words((
185 '<condition>', '<continuation>', '<restart>', 'attempt-all',
186 'attempt-all-error', 'attempt-all-error?', 'callback-error-hook',
187 'callcc0', 'callcc1', 'cleanup', 'compute-restarts', 'condition',
188 'condition?', 'continuation', 'continuation?', 'continue',
189 'continue-restart', 'continue-with', 'current-continuation',
190 'error', 'error-continuation', 'error-in-thread', 'error-thread',
191 'ifcc', 'ignore-errors', 'in-callback?', 'original-error', 'recover',
192 'restart', 'restart?', 'restarts', 'rethrow', 'rethrow-restarts',
193 'return', 'return-continuation', 'thread-error-hook', 'throw-continue',
194 'throw-restarts', 'with-datastack', 'with-return'), suffix=r'\s')
195
196 tokens = {
197 'root': [
198 # factor allows a file to start with a shebang
199 (r'#!.*$', Comment.Preproc),
200 default('base'),
201 ],
202 'base': [
203 (r'\s+', Text),
204
205 # defining words
206 (r'((?:MACRO|MEMO|TYPED)?:[:]?)(\s+)(\S+)',
207 bygroups(Keyword, Text, Name.Function)),
208 (r'(M:[:]?)(\s+)(\S+)(\s+)(\S+)',
209 bygroups(Keyword, Text, Name.Class, Text, Name.Function)),
210 (r'(C:)(\s+)(\S+)(\s+)(\S+)',
211 bygroups(Keyword, Text, Name.Function, Text, Name.Class)),
212 (r'(GENERIC:)(\s+)(\S+)',
213 bygroups(Keyword, Text, Name.Function)),
214 (r'(HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)',
215 bygroups(Keyword, Text, Name.Function, Text, Name.Function)),
216 (r'\(\s', Name.Function, 'stackeffect'),
217 (r';\s', Keyword),
218
219 # imports and namespaces
220 (r'(USING:)(\s+)',
221 bygroups(Keyword.Namespace, Text), 'vocabs'),
222 (r'(USE:|UNUSE:|IN:|QUALIFIED:)(\s+)(\S+)',
223 bygroups(Keyword.Namespace, Text, Name.Namespace)),
224 (r'(QUALIFIED-WITH:)(\s+)(\S+)(\s+)(\S+)',
225 bygroups(Keyword.Namespace, Text, Name.Namespace, Text, Name.Namespace)),
226 (r'(FROM:|EXCLUDE:)(\s+)(\S+)(\s+=>\s)',
227 bygroups(Keyword.Namespace, Text, Name.Namespace, Text), 'words'),
228 (r'(RENAME:)(\s+)(\S+)(\s+)(\S+)(\s+=>\s+)(\S+)',
229 bygroups(Keyword.Namespace, Text, Name.Function, Text, Name.Namespace, Text, Name.Function)),
230 (r'(ALIAS:|TYPEDEF:)(\s+)(\S+)(\s+)(\S+)',
231 bygroups(Keyword.Namespace, Text, Name.Function, Text, Name.Function)),
232 (r'(DEFER:|FORGET:|POSTPONE:)(\s+)(\S+)',
233 bygroups(Keyword.Namespace, Text, Name.Function)),
234
235 # tuples and classes
236 (r'(TUPLE:|ERROR:)(\s+)(\S+)(\s+<\s+)(\S+)',
237 bygroups(Keyword, Text, Name.Class, Text, Name.Class), 'slots'),
238 (r'(TUPLE:|ERROR:|BUILTIN:)(\s+)(\S+)',
239 bygroups(Keyword, Text, Name.Class), 'slots'),
240 (r'(MIXIN:|UNION:|INTERSECTION:)(\s+)(\S+)',
241 bygroups(Keyword, Text, Name.Class)),
242 (r'(PREDICATE:)(\s+)(\S+)(\s+<\s+)(\S+)',
243 bygroups(Keyword, Text, Name.Class, Text, Name.Class)),
244 (r'(C:)(\s+)(\S+)(\s+)(\S+)',
245 bygroups(Keyword, Text, Name.Function, Text, Name.Class)),
246 (r'(INSTANCE:)(\s+)(\S+)(\s+)(\S+)',
247 bygroups(Keyword, Text, Name.Class, Text, Name.Class)),
248 (r'(SLOT:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Function)),
249 (r'(SINGLETON:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class)),
250 (r'SINGLETONS:', Keyword, 'classes'),
251
252 # other syntax
253 (r'(CONSTANT:|SYMBOL:|MAIN:|HELP:)(\s+)(\S+)',
254 bygroups(Keyword, Text, Name.Function)),
255 (r'SYMBOLS:\s', Keyword, 'words'),
256 (r'SYNTAX:\s', Keyword),
257 (r'ALIEN:\s', Keyword),
258 (r'(STRUCT:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class)),
259 (r'(FUNCTION:)(\s+\S+\s+)(\S+)(\s+\(\s+[^)]+\)\s)',
260 bygroups(Keyword.Namespace, Text, Name.Function, Text)),
261 (r'(FUNCTION-ALIAS:)(\s+)(\S+)(\s+\S+\s+)(\S+)(\s+\(\s+[^)]+\)\s)',
262 bygroups(Keyword.Namespace, Text, Name.Function, Text, Name.Function, Text)),
263
264 # vocab.private
265 (r'(?:<PRIVATE|PRIVATE>)\s', Keyword.Namespace),
266
267 # strings
268 (r'"""\s+(?:.|\n)*?\s+"""', String),
269 (r'"(?:\\\\|\\"|[^"])*"', String),
270 (r'\S+"\s+(?:\\\\|\\"|[^"])*"', String),
271 (r'CHAR:\s+(?:\\[\\abfnrstv]|[^\\]\S*)\s', String.Char),
272
273 # comments
274 (r'!\s+.*$', Comment),
275 (r'#!\s+.*$', Comment),
276 (r'/\*\s+(?:.|\n)*?\s\*/\s', Comment),
277
278 # boolean constants
279 (r'[tf]\s', Name.Constant),
280
281 # symbols and literals
282 (r'[\\$]\s+\S+', Name.Constant),
283 (r'M\\\s+\S+\s+\S+', Name.Constant),
284
285 # numbers
286 (r'[+-]?(?:[\d,]*\d)?\.(?:\d([\d,]*\d)?)?(?:[eE][+-]?\d+)?\s', Number),
287 (r'[+-]?\d(?:[\d,]*\d)?(?:[eE][+-]?\d+)?\s', Number),
288 (r'0x[a-fA-F\d](?:[a-fA-F\d,]*[a-fA-F\d])?(?:p\d([\d,]*\d)?)?\s', Number),
289 (r'NAN:\s+[a-fA-F\d](?:[a-fA-F\d,]*[a-fA-F\d])?(?:p\d([\d,]*\d)?)?\s', Number),
290 (r'0b[01]+\s', Number.Bin),
291 (r'0o[0-7]+\s', Number.Oct),
292 (r'(?:\d([\d,]*\d)?)?\+\d(?:[\d,]*\d)?/\d(?:[\d,]*\d)?\s', Number),
293 (r'(?:\-\d([\d,]*\d)?)?\-\d(?:[\d,]*\d)?/\d(?:[\d,]*\d)?\s', Number),
294
295 # keywords
296 (r'(?:deprecated|final|foldable|flushable|inline|recursive)\s',
297 Keyword),
298
299 # builtins
300 (builtin_kernel, Name.Builtin),
301 (builtin_assocs, Name.Builtin),
302 (builtin_combinators, Name.Builtin),
303 (builtin_math, Name.Builtin),
304 (builtin_sequences, Name.Builtin),
305 (builtin_namespaces, Name.Builtin),
306 (builtin_arrays, Name.Builtin),
307 (builtin_io, Name.Builtin),
308 (builtin_strings, Name.Builtin),
309 (builtin_vectors, Name.Builtin),
310 (builtin_continuations, Name.Builtin),
311
312 # everything else is text
313 (r'\S+', Text),
314 ],
315 'stackeffect': [
316 (r'\s+', Text),
317 (r'\(\s+', Name.Function, 'stackeffect'),
318 (r'\)\s', Name.Function, '#pop'),
319 (r'--\s', Name.Function),
320 (r'\S+', Name.Variable),
321 ],
322 'slots': [
323 (r'\s+', Text),
324 (r';\s', Keyword, '#pop'),
325 (r'(\{\s+)(\S+)(\s+[^}]+\s+\}\s)',
326 bygroups(Text, Name.Variable, Text)),
327 (r'\S+', Name.Variable),
328 ],
329 'vocabs': [
330 (r'\s+', Text),
331 (r';\s', Keyword, '#pop'),
332 (r'\S+', Name.Namespace),
333 ],
334 'classes': [
335 (r'\s+', Text),
336 (r';\s', Keyword, '#pop'),
337 (r'\S+', Name.Class),
338 ],
339 'words': [
340 (r'\s+', Text),
341 (r';\s', Keyword, '#pop'),
342 (r'\S+', Name.Function),
343 ],
344 }

eric ide

mercurial