ThirdParty/Pygments/pygments/lexers/agile.py

changeset 808
8f85926125ef
parent 684
2f29a0b6e1c7
child 1705
b0fbc9300f2b
equal deleted inserted replaced
805:83ca4d1ff648 808:8f85926125ef
20 20
21 21
22 __all__ = ['PythonLexer', 'PythonConsoleLexer', 'PythonTracebackLexer', 22 __all__ = ['PythonLexer', 'PythonConsoleLexer', 'PythonTracebackLexer',
23 'RubyLexer', 'RubyConsoleLexer', 'PerlLexer', 'LuaLexer', 23 'RubyLexer', 'RubyConsoleLexer', 'PerlLexer', 'LuaLexer',
24 'MiniDLexer', 'IoLexer', 'TclLexer', 'ClojureLexer', 24 'MiniDLexer', 'IoLexer', 'TclLexer', 'ClojureLexer',
25 'Python3Lexer', 'Python3TracebackLexer'] 25 'Python3Lexer', 'Python3TracebackLexer', 'FactorLexer', 'IokeLexer']
26 26
27 # b/w compatibility 27 # b/w compatibility
28 from pygments.lexers.functional import SchemeLexer 28 from pygments.lexers.functional import SchemeLexer
29 29
30 line_re = re.compile('.*?\n') 30 line_re = re.compile('.*?\n')
41 mimetypes = ['text/x-python', 'application/x-python'] 41 mimetypes = ['text/x-python', 'application/x-python']
42 42
43 tokens = { 43 tokens = {
44 'root': [ 44 'root': [
45 (r'\n', Text), 45 (r'\n', Text),
46 (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Text, String.Doc)), 46 (r'^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")', bygroups(Text, String.Doc)),
47 (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Text, String.Doc)), 47 (r"^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')", bygroups(Text, String.Doc)),
48 (r'[^\S\n]+', Text), 48 (r'[^\S\n]+', Text),
49 (r'#.*$', Comment), 49 (r'#.*$', Comment),
50 (r'[]{}:(),;[]', Punctuation), 50 (r'[]{}:(),;[]', Punctuation),
51 (r'\\\n', Text), 51 (r'\\\n', Text),
52 (r'\\', Text), 52 (r'\\', Text),
102 r'WindowsError|ZeroDivisionError)\b', Name.Exception), 102 r'WindowsError|ZeroDivisionError)\b', Name.Exception),
103 ], 103 ],
104 'numbers': [ 104 'numbers': [
105 (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), 105 (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
106 (r'\d+[eE][+-]?[0-9]+', Number.Float), 106 (r'\d+[eE][+-]?[0-9]+', Number.Float),
107 (r'0\d+', Number.Oct), 107 (r'0[0-7]+', Number.Oct),
108 (r'0[xX][a-fA-F0-9]+', Number.Hex), 108 (r'0[xX][a-fA-F0-9]+', Number.Hex),
109 (r'\d+L', Number.Integer.Long), 109 (r'\d+L', Number.Integer.Long),
110 (r'\d+', Number.Integer) 110 (r'\d+', Number.Integer)
111 ], 111 ],
112 'backtick': [ 112 'backtick': [
369 (r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'), 369 (r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
370 (r'^.*\n', Other), 370 (r'^.*\n', Other),
371 ], 371 ],
372 'intb': [ 372 'intb': [
373 (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)', 373 (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
374 bygroups(Text, Name.Builtin, Text, Number, Text, Name.Identifier, Text)), 374 bygroups(Text, Name.Builtin, Text, Number, Text, Name, Text)),
375 (r'^( File )("[^"]+")(, line )(\d+)(\n)', 375 (r'^( File )("[^"]+")(, line )(\d+)(\n)',
376 bygroups(Text, Name.Builtin, Text, Number, Text)), 376 bygroups(Text, Name.Builtin, Text, Number, Text)),
377 (r'^( )(.+)(\n)', 377 (r'^( )(.+)(\n)',
378 bygroups(Text, using(PythonLexer), Text)), 378 bygroups(Text, using(PythonLexer), Text)),
379 (r'^([ \t]*)(...)(\n)', 379 (r'^([ \t]*)(...)(\n)',
380 bygroups(Text, Comment, Text)), # for doctests... 380 bygroups(Text, Comment, Text)), # for doctests...
381 (r'^(.+)(: )(.+)(\n)', 381 (r'^(.+)(: )(.+)(\n)',
382 bygroups(Name.Class, Text, Name.Identifier, Text), '#pop'), 382 bygroups(Generic.Error, Text, Name, Text), '#pop'),
383 (r'^([a-zA-Z_][a-zA-Z0-9_]*)(:?\n)', 383 (r'^([a-zA-Z_][a-zA-Z0-9_]*)(:?\n)',
384 bygroups(Name.Class, Text), '#pop') 384 bygroups(Generic.Error, Text), '#pop')
385 ], 385 ],
386 } 386 }
387 387
388 388
389 class Python3TracebackLexer(RegexLexer): 389 class Python3TracebackLexer(RegexLexer):
407 (r'^The above exception was the direct cause of the ' 407 (r'^The above exception was the direct cause of the '
408 r'following exception:\n\n', Generic.Traceback), 408 r'following exception:\n\n', Generic.Traceback),
409 ], 409 ],
410 'intb': [ 410 'intb': [
411 (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)', 411 (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
412 bygroups(Text, Name.Builtin, Text, Number, Text, Name.Identifier, Text)), 412 bygroups(Text, Name.Builtin, Text, Number, Text, Name, Text)),
413 (r'^( )(.+)(\n)', 413 (r'^( )(.+)(\n)',
414 bygroups(Text, using(Python3Lexer), Text)), 414 bygroups(Text, using(Python3Lexer), Text)),
415 (r'^([ \t]*)(...)(\n)', 415 (r'^([ \t]*)(...)(\n)',
416 bygroups(Text, Comment, Text)), # for doctests... 416 bygroups(Text, Comment, Text)), # for doctests...
417 (r'^(.+)(: )(.+)(\n)', 417 (r'^(.+)(: )(.+)(\n)',
418 bygroups(Name.Class, Text, Name.Identifier, Text), '#pop'), 418 bygroups(Generic.Error, Text, Name, Text), '#pop'),
419 (r'^([a-zA-Z_][a-zA-Z0-9_]*)(:?\n)', 419 (r'^([a-zA-Z_][a-zA-Z0-9_]*)(:?\n)',
420 bygroups(Name.Class, Text), '#pop') 420 bygroups(Generic.Error, Text), '#pop')
421 ], 421 ],
422 } 422 }
423 423
424 424
425 class RubyLexer(ExtendedRegexLexer): 425 class RubyLexer(ExtendedRegexLexer):
426 """ 426 """
427 For `Ruby <http://www.ruby-lang.org>`_ source code. 427 For `Ruby <http://www.ruby-lang.org>`_ source code.
428 """ 428 """
429 429
430 name = 'Ruby' 430 name = 'Ruby'
431 aliases = ['rb', 'ruby'] 431 aliases = ['rb', 'ruby', 'duby']
432 filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx'] 432 filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec',
433 '*.rbx', '*.duby']
433 mimetypes = ['text/x-ruby', 'application/x-ruby'] 434 mimetypes = ['text/x-ruby', 'application/x-ruby']
434 435
435 flags = re.DOTALL | re.MULTILINE 436 flags = re.DOTALL | re.MULTILINE
436 437
437 def heredoc_callback(self, match, ctx): 438 def heredoc_callback(self, match, ctx):
621 r'protected_methods|public_class_method|' 622 r'protected_methods|public_class_method|'
622 r'public_instance_methods|public_methods|' 623 r'public_instance_methods|public_methods|'
623 r'putc|puts|raise|rand|readline|readlines|require|' 624 r'putc|puts|raise|rand|readline|readlines|require|'
624 r'scan|select|self|send|set_trace_func|singleton_methods|sleep|' 625 r'scan|select|self|send|set_trace_func|singleton_methods|sleep|'
625 r'split|sprintf|srand|sub|syscall|system|taint|' 626 r'split|sprintf|srand|sub|syscall|system|taint|'
626 r'test|throw|to_a|to_s|trace_var|trap|type|untaint|untrace_var|' 627 r'test|throw|to_a|to_s|trace_var|trap|untaint|untrace_var|'
627 r'warn)\b', Name.Builtin), 628 r'warn)\b', Name.Builtin),
628 (r'__(FILE|LINE)__\b', Name.Builtin.Pseudo), 629 (r'__(FILE|LINE)__\b', Name.Builtin.Pseudo),
629 # normal heredocs 630 # normal heredocs
630 (r'(?<!\w)(<<-?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)', heredoc_callback), 631 (r'(?<!\w)(<<-?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)', heredoc_callback),
631 # empty string heredocs 632 # empty string heredocs
835 'root': [ 836 'root': [
836 (r'\#.*?$', Comment.Single), 837 (r'\#.*?$', Comment.Single),
837 (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline), 838 (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline),
838 (r'(case|continue|do|else|elsif|for|foreach|if|last|my|' 839 (r'(case|continue|do|else|elsif|for|foreach|if|last|my|'
839 r'next|our|redo|reset|then|unless|until|while|use|' 840 r'next|our|redo|reset|then|unless|until|while|use|'
840 r'print|new|BEGIN|END|return)\b', Keyword), 841 r'print|new|BEGIN|CHECK|INIT|END|return)\b', Keyword),
841 (r'(format)(\s+)([a-zA-Z0-9_]+)(\s*)(=)(\s*\n)', 842 (r'(format)(\s+)([a-zA-Z0-9_]+)(\s*)(=)(\s*\n)',
842 bygroups(Keyword, Text, Name, Text, Punctuation, Text), 'format'), 843 bygroups(Keyword, Text, Name, Text, Punctuation, Text), 'format'),
843 (r'(eq|lt|gt|le|ge|ne|not|and|or|cmp)\b', Operator.Word), 844 (r'(eq|lt|gt|le|ge|ne|not|and|or|cmp)\b', Operator.Word),
844 # common delimiters 845 # common delimiters
845 (r's/(\\\\|\\/|[^/])*/(\\\\|\\/|[^/])*/[egimosx]*', String.Regex), 846 (r's/(\\\\|\\/|[^/])*/(\\\\|\\/|[^/])*/[egimosx]*', String.Regex),
891 (r"\$[\\\"\[\]'&`+*.,;=%~?@$!<>(^|/-](?!\w)", Name.Variable.Global), 892 (r"\$[\\\"\[\]'&`+*.,;=%~?@$!<>(^|/-](?!\w)", Name.Variable.Global),
892 (r'[$@%#]+', Name.Variable, 'varname'), 893 (r'[$@%#]+', Name.Variable, 'varname'),
893 (r'0_?[0-7]+(_[0-7]+)*', Number.Oct), 894 (r'0_?[0-7]+(_[0-7]+)*', Number.Oct),
894 (r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex), 895 (r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex),
895 (r'0b[01]+(_[01]+)*', Number.Bin), 896 (r'0b[01]+(_[01]+)*', Number.Bin),
896 (r'\d+', Number.Integer), 897 (r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?',
898 Number.Float),
899 (r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float),
900 (r'\d+(_\d+)*', Number.Integer),
897 (r"'(\\\\|\\'|[^'])*'", String), 901 (r"'(\\\\|\\'|[^'])*'", String),
898 (r'"(\\\\|\\"|[^"])*"', String), 902 (r'"(\\\\|\\"|[^"])*"', String),
899 (r'`(\\\\|\\`|[^`])*`', String.Backtick), 903 (r'`(\\\\|\\`|[^`])*`', String.Backtick),
900 (r'<([^\s>]+)>', String.Regexp), 904 (r'<([^\s>]+)>', String.Regex),
901 (r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'), 905 (r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'),
902 (r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'), 906 (r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'),
903 (r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'), 907 (r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'),
904 (r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'), 908 (r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'),
905 (r'(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2', String.Other), 909 (r'(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2', String.Other),
972 (r'.+', Comment.Preproc, '#pop') 976 (r'.+', Comment.Preproc, '#pop')
973 ] 977 ]
974 } 978 }
975 979
976 def analyse_text(text): 980 def analyse_text(text):
977 if shebang_matches(text, r'perl(\d\.\d\.\d)?'): 981 if shebang_matches(text, r'perl'):
978 return True 982 return True
979 if 'my $' in text: 983 if 'my $' in text:
980 return 0.9 984 return 0.9
981 return 0.1 # who knows, might still be perl! 985 return 0.1 # who knows, might still be perl!
982 986
1004 ['string', 'coroutine', 'modules', 'io', 'basic', ...] 1008 ['string', 'coroutine', 'modules', 'io', 'basic', ...]
1005 """ 1009 """
1006 1010
1007 name = 'Lua' 1011 name = 'Lua'
1008 aliases = ['lua'] 1012 aliases = ['lua']
1009 filenames = ['*.lua'] 1013 filenames = ['*.lua', '*.wlua']
1010 mimetypes = ['text/x-lua', 'application/x-lua'] 1014 mimetypes = ['text/x-lua', 'application/x-lua']
1011 1015
1012 tokens = { 1016 tokens = {
1013 'root': [ 1017 'root': [
1014 # lua allows a file to start with a shebang 1018 # lua allows a file to start with a shebang
1024 ('(?i)0x[0-9a-f]*', Number.Hex), 1028 ('(?i)0x[0-9a-f]*', Number.Hex),
1025 (r'\d+', Number.Integer), 1029 (r'\d+', Number.Integer),
1026 1030
1027 (r'\n', Text), 1031 (r'\n', Text),
1028 (r'[^\S\n]', Text), 1032 (r'[^\S\n]', Text),
1029 (r'(?s)\[(=*)\[.*?\]\1\]', String.Multiline), 1033 # multiline strings
1034 (r'(?s)\[(=*)\[.*?\]\1\]', String),
1035
1036 (r'(==|~=|<=|>=|\.\.|\.\.\.|[=+\-*/%^<>#])', Operator),
1030 (r'[\[\]\{\}\(\)\.,:;]', Punctuation), 1037 (r'[\[\]\{\}\(\)\.,:;]', Punctuation),
1031
1032 (r'(==|~=|<=|>=|\.\.|\.\.\.|[=+\-*/%^<>#])', Operator),
1033 (r'(and|or|not)\b', Operator.Word), 1038 (r'(and|or|not)\b', Operator.Word),
1034 1039
1035 ('(break|do|else|elseif|end|for|if|in|repeat|return|then|until|' 1040 ('(break|do|else|elseif|end|for|if|in|repeat|return|then|until|'
1036 r'while)\b', Keyword), 1041 r'while)\b', Keyword),
1037 (r'(local)\b', Keyword.Declaration), 1042 (r'(local)\b', Keyword.Declaration),
1040 (r'(function)(\s+)', bygroups(Keyword, Text), 'funcname'), 1045 (r'(function)(\s+)', bygroups(Keyword, Text), 'funcname'),
1041 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), 1046 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
1042 1047
1043 (r'[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?', Name), 1048 (r'[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?', Name),
1044 1049
1045 # multiline strings
1046 (r'(?s)\[(=*)\[(.*?)\]\1\]', String),
1047 ("'", String.Single, combined('stringescape', 'sqs')), 1050 ("'", String.Single, combined('stringescape', 'sqs')),
1048 ('"', String.Double, combined('stringescape', 'dqs')) 1051 ('"', String.Double, combined('stringescape', 'dqs'))
1049 ], 1052 ],
1050 1053
1051 'funcname': [ 1054 'funcname': [
1052 ('[A-Za-z_][A-Za-z0-9_]*', Name.Function, '#pop'), 1055 ('(?:([A-Za-z_][A-Za-z0-9_]*)(\.))?([A-Za-z_][A-Za-z0-9_]*)',
1056 bygroups(Name.Class, Punctuation, Name.Function), '#pop'),
1053 # inline function 1057 # inline function
1054 ('\(', Punctuation, '#pop'), 1058 ('\(', Punctuation, '#pop'),
1055 ], 1059 ],
1056 1060
1057 'classname': [ 1061 'classname': [
1481 1485
1482 # the famous parentheses! 1486 # the famous parentheses!
1483 (r'(\(|\))', Punctuation), 1487 (r'(\(|\))', Punctuation),
1484 ], 1488 ],
1485 } 1489 }
1490
1491
1492 class FactorLexer(RegexLexer):
1493 """
1494 Lexer for the `Factor <http://factorcode.org>`_ language.
1495
1496 *New in Pygments 1.4.*
1497 """
1498 name = 'Factor'
1499 aliases = ['factor']
1500 filenames = ['*.factor']
1501 mimetypes = ['text/x-factor']
1502
1503 flags = re.MULTILINE | re.UNICODE
1504
1505 builtin_kernel = (
1506 r'(?:or|2bi|2tri|while|wrapper|nip|4dip|wrapper\\?|bi\\*|'
1507 r'callstack>array|both\\?|hashcode|die|dupd|callstack|'
1508 r'callstack\\?|3dup|tri@|pick|curry|build|\\?execute|3bi|'
1509 r'prepose|>boolean|\\?if|clone|eq\\?|tri\\*|\\?|=|swapd|'
1510 r'2over|2keep|3keep|clear|2dup|when|not|tuple\\?|dup|2bi\\*|'
1511 r'2tri\\*|call|tri-curry|object|bi@|do|unless\\*|if\\*|loop|'
1512 r'bi-curry\\*|drop|when\\*|assert=|retainstack|assert\\?|-rot|'
1513 r'execute|2bi@|2tri@|boa|with|either\\?|3drop|bi|curry\\?|'
1514 r'datastack|until|3dip|over|3curry|tri-curry\\*|tri-curry@|swap|'
1515 r'and|2nip|throw|bi-curry|\\(clone\\)|hashcode\\*|compose|2dip|if|3tri|'
1516 r'unless|compose\\?|tuple|keep|2curry|equal\\?|assert|tri|2drop|'
1517 r'most|<wrapper>|boolean\\?|identity-hashcode|identity-tuple\\?|'
1518 r'null|new|dip|bi-curry@|rot|xor|identity-tuple|boolean)\s'
1519 )
1520
1521 builtin_assocs = (
1522 r'(?:\\?at|assoc\\?|assoc-clone-like|assoc=|delete-at\\*|'
1523 r'assoc-partition|extract-keys|new-assoc|value\\?|assoc-size|'
1524 r'map>assoc|push-at|assoc-like|key\\?|assoc-intersect|'
1525 r'assoc-refine|update|assoc-union|assoc-combine|at\\*|'
1526 r'assoc-empty\\?|at\\+|set-at|assoc-all\\?|assoc-subset\\?|'
1527 r'assoc-hashcode|change-at|assoc-each|assoc-diff|zip|values|'
1528 r'value-at|rename-at|inc-at|enum\\?|at|cache|assoc>map|<enum>|'
1529 r'assoc|assoc-map|enum|value-at\\*|assoc-map-as|>alist|'
1530 r'assoc-filter-as|clear-assoc|assoc-stack|maybe-set-at|'
1531 r'substitute|assoc-filter|2cache|delete-at|assoc-find|keys|'
1532 r'assoc-any\\?|unzip)\s'
1533 )
1534
1535 builtin_combinators = (
1536 r'(?:case|execute-effect|no-cond|no-case\\?|3cleave>quot|2cleave|'
1537 r'cond>quot|wrong-values\\?|no-cond\\?|cleave>quot|no-case|'
1538 r'case>quot|3cleave|wrong-values|to-fixed-point|alist>quot|'
1539 r'case-find|cond|cleave|call-effect|2cleave>quot|recursive-hashcode|'
1540 r'linear-case-quot|spread|spread>quot)\s'
1541 )
1542
1543 builtin_math = (
1544 r'(?:number=|if-zero|next-power-of-2|each-integer|\\?1\\+|'
1545 r'fp-special\\?|imaginary-part|unless-zero|float>bits|number\\?|'
1546 r'fp-infinity\\?|bignum\\?|fp-snan\\?|denominator|fp-bitwise=|\\*|'
1547 r'\\+|power-of-2\\?|-|u>=|/|>=|bitand|log2-expects-positive|<|'
1548 r'log2|>|integer\\?|number|bits>double|2/|zero\\?|(find-integer)|'
1549 r'bits>float|float\\?|shift|ratio\\?|even\\?|ratio|fp-sign|bitnot|'
1550 r'>fixnum|complex\\?|/i|/f|byte-array>bignum|when-zero|sgn|>bignum|'
1551 r'next-float|u<|u>|mod|recip|rational|find-last-integer|>float|'
1552 r'(all-integers\\?)|2^|times|integer|fixnum\\?|neg|fixnum|sq|'
1553 r'bignum|(each-integer)|bit\\?|fp-qnan\\?|find-integer|complex|'
1554 r'<fp-nan>|real|double>bits|bitor|rem|fp-nan-payload|all-integers\\?|'
1555 r'real-part|log2-expects-positive\\?|prev-float|align|unordered\\?|'
1556 r'float|fp-nan\\?|abs|bitxor|u<=|odd\\?|<=|/mod|rational\\?|>integer|'
1557 r'real\\?|numerator)\s'
1558 )
1559
1560 builtin_sequences = (
1561 r'(?:member-eq\\?|append|assert-sequence=|find-last-from|trim-head-slice|'
1562 r'clone-like|3sequence|assert-sequence\\?|map-as|last-index-from|'
1563 r'reversed|index-from|cut\\*|pad-tail|remove-eq!|concat-as|'
1564 r'but-last|snip|trim-tail|nths|nth|2selector|sequence|slice\\?|'
1565 r'<slice>|partition|remove-nth|tail-slice|empty\\?|tail\\*|'
1566 r'if-empty|find-from|virtual-sequence\\?|member\\?|set-length|'
1567 r'drop-prefix|unclip|unclip-last-slice|iota|map-sum|'
1568 r'bounds-error\\?|sequence-hashcode-step|selector-for|'
1569 r'accumulate-as|map|start|midpoint@|\\(accumulate\\)|rest-slice|'
1570 r'prepend|fourth|sift|accumulate!|new-sequence|follow|map!|'
1571 r'like|first4|1sequence|reverse|slice|unless-empty|padding|'
1572 r'virtual@|repetition\\?|set-last|index|4sequence|max-length|'
1573 r'set-second|immutable-sequence|first2|first3|replicate-as|'
1574 r'reduce-index|unclip-slice|supremum|suffix!|insert-nth|'
1575 r'trim-tail-slice|tail|3append|short|count|suffix|concat|'
1576 r'flip|filter|sum|immutable\\?|reverse!|2sequence|map-integers|'
1577 r'delete-all|start\\*|indices|snip-slice|check-slice|sequence\\?|'
1578 r'head|map-find|filter!|append-as|reduce|sequence=|halves|'
1579 r'collapse-slice|interleave|2map|filter-as|binary-reduce|'
1580 r'slice-error\\?|product|bounds-check\\?|bounds-check|harvest|'
1581 r'immutable|virtual-exemplar|find|produce|remove|pad-head|last|'
1582 r'replicate|set-fourth|remove-eq|shorten|reversed\\?|'
1583 r'map-find-last|3map-as|2unclip-slice|shorter\\?|3map|find-last|'
1584 r'head-slice|pop\\*|2map-as|tail-slice\\*|but-last-slice|'
1585 r'2map-reduce|iota\\?|collector-for|accumulate|each|selector|'
1586 r'append!|new-resizable|cut-slice|each-index|head-slice\\*|'
1587 r'2reverse-each|sequence-hashcode|pop|set-nth|\\?nth|'
1588 r'<flat-slice>|second|join|when-empty|collector|'
1589 r'immutable-sequence\\?|<reversed>|all\\?|3append-as|'
1590 r'virtual-sequence|subseq\\?|remove-nth!|push-either|new-like|'
1591 r'length|last-index|push-if|2all\\?|lengthen|assert-sequence|'
1592 r'copy|map-reduce|move|third|first|3each|tail\\?|set-first|'
1593 r'prefix|bounds-error|any\\?|<repetition>|trim-slice|exchange|'
1594 r'surround|2reduce|cut|change-nth|min-length|set-third|produce-as|'
1595 r'push-all|head\\?|delete-slice|rest|sum-lengths|2each|head\\*|'
1596 r'infimum|remove!|glue|slice-error|subseq|trim|replace-slice|'
1597 r'push|repetition|map-index|trim-head|unclip-last|mismatch)\s'
1598 )
1599
1600 builtin_namespaces = (
1601 r'(?:global|\\+@|change|set-namestack|change-global|init-namespaces|'
1602 r'on|off|set-global|namespace|set|with-scope|bind|with-variable|'
1603 r'inc|dec|counter|initialize|namestack|get|get-global|make-assoc)\s'
1604 )
1605
1606 builtin_arrays = (
1607 r'(?:<array>|2array|3array|pair|>array|1array|4array|pair\\?|'
1608 r'array|resize-array|array\\?)\s'
1609 )
1610
1611 builtin_io = (
1612 r'(?:\\+character\\+|bad-seek-type\\?|readln|each-morsel|stream-seek|'
1613 r'read|print|with-output-stream|contents|write1|stream-write1|'
1614 r'stream-copy|stream-element-type|with-input-stream|'
1615 r'stream-print|stream-read|stream-contents|stream-tell|'
1616 r'tell-output|bl|seek-output|bad-seek-type|nl|stream-nl|write|'
1617 r'flush|stream-lines|\\+byte\\+|stream-flush|read1|'
1618 r'seek-absolute\\?|stream-read1|lines|stream-readln|'
1619 r'stream-read-until|each-line|seek-end|with-output-stream\\*|'
1620 r'seek-absolute|with-streams|seek-input|seek-relative\\?|'
1621 r'input-stream|stream-write|read-partial|seek-end\\?|'
1622 r'seek-relative|error-stream|read-until|with-input-stream\\*|'
1623 r'with-streams\\*|tell-input|each-block|output-stream|'
1624 r'stream-read-partial|each-stream-block|each-stream-line)\s'
1625 )
1626
1627 builtin_strings = (
1628 r'(?:resize-string|>string|<string>|1string|string|string\\?)\s'
1629 )
1630
1631 builtin_vectors = (
1632 r'(?:vector\\?|<vector>|\\?push|vector|>vector|1vector)\s'
1633 )
1634
1635 builtin_continuations = (
1636 r'(?:with-return|restarts|return-continuation|with-datastack|'
1637 r'recover|rethrow-restarts|<restart>|ifcc|set-catchstack|'
1638 r'>continuation<|cleanup|ignore-errors|restart\\?|'
1639 r'compute-restarts|attempt-all-error|error-thread|continue|'
1640 r'<continuation>|attempt-all-error\\?|condition\\?|'
1641 r'<condition>|throw-restarts|error|catchstack|continue-with|'
1642 r'thread-error-hook|continuation|rethrow|callcc1|'
1643 r'error-continuation|callcc0|attempt-all|condition|'
1644 r'continuation\\?|restart|return)\s'
1645 )
1646
1647 tokens = {
1648 'root': [
1649 # TODO: (( inputs -- outputs ))
1650 # TODO: << ... >>
1651
1652 # defining words
1653 (r'(\s*)(:|::|MACRO:|MEMO:)(\s+)(\S+)',
1654 bygroups(Text, Keyword, Text, Name.Function)),
1655 (r'(\s*)(M:)(\s+)(\S+)(\s+)(\S+)',
1656 bygroups(Text, Keyword, Text, Name.Class, Text, Name.Function)),
1657 (r'(\s*)(GENERIC:)(\s+)(\S+)',
1658 bygroups(Text, Keyword, Text, Name.Function)),
1659 (r'(\s*)(HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)',
1660 bygroups(Text, Keyword, Text, Name.Function, Text, Name.Function)),
1661 (r'(\()(\s+)', bygroups(Name.Function, Text), 'stackeffect'),
1662 (r'\;\s', Keyword),
1663
1664 # imports and namespaces
1665 (r'(USING:)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text), 'import'),
1666 (r'(USE:)(\s+)(\S+)', bygroups(Keyword.Namespace, Text, Name.Namespace)),
1667 (r'(UNUSE:)(\s+)(\S+)', bygroups(Keyword.Namespace, Text, Name.Namespace)),
1668 (r'(QUALIFIED:)(\s+)(\S+)',
1669 bygroups(Keyword.Namespace, Text, Name.Namespace)),
1670 (r'(QUALIFIED-WITH:)(\s+)(\S+)',
1671 bygroups(Keyword.Namespace, Text, Name.Namespace)),
1672 (r'(FROM:|EXCLUDE:)(\s+)(\S+)(\s+)(=>)',
1673 bygroups(Keyword.Namespace, Text, Name.Namespace, Text, Text)),
1674 (r'(IN:)(\s+)(\S+)', bygroups(Keyword.Namespace, Text, Name.Namespace)),
1675 (r'(?:ALIAS|DEFER|FORGET|POSTPONE):', Keyword.Namespace),
1676
1677 # tuples and classes
1678 (r'(TUPLE:)(\s+)(\S+)(\s+<\s+)(\S+)',
1679 bygroups(Keyword, Text, Name.Class, Text, Name.Class), 'slots'),
1680 (r'(TUPLE:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class), 'slots'),
1681 (r'(UNION:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class)),
1682 (r'(INTERSECTION:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class)),
1683 (r'(PREDICATE:)(\s+)(\S+)(\s+<\s+)(\S+)',
1684 bygroups(Keyword, Text, Name.Class, Text, Name.Class)),
1685 (r'(C:)(\s+)(\S+)(\s+)(\S+)',
1686 bygroups(Keyword, Text, Name.Function, Text, Name.Class)),
1687 (r'INSTANCE:', Keyword),
1688 (r'SLOT:', Keyword),
1689 (r'MIXIN:', Keyword),
1690 (r'(?:SINGLETON|SINGLETONS):', Keyword),
1691
1692 # other syntax
1693 (r'CONSTANT:', Keyword),
1694 (r'(?:SYMBOL|SYMBOLS):', Keyword),
1695 (r'ERROR:', Keyword),
1696 (r'SYNTAX:', Keyword),
1697 (r'(HELP:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Function)),
1698 (r'(MAIN:)(\s+)(\S+)', bygroups(Keyword.Namespace, Text, Name.Function)),
1699 (r'(?:ALIEN|TYPEDEF|FUNCTION|STRUCT):', Keyword),
1700
1701 # vocab.private
1702 # TODO: words inside vocab.private should have red names?
1703 (r'(?:<PRIVATE|PRIVATE>)', Keyword.Namespace),
1704
1705 # strings
1706 (r'"""\s+(?:.|\n)*?\s+"""', String),
1707 (r'"(?:\\\\|\\"|[^"])*"', String),
1708 (r'CHAR:\s+(\\[\\abfnrstv]*|\S)\s', String.Char),
1709
1710 # comments
1711 (r'\!\s+.*$', Comment),
1712 (r'#\!\s+.*$', Comment),
1713
1714 # boolean constants
1715 (r'(t|f)\s', Name.Constant),
1716
1717 # numbers
1718 (r'-?\d+\.\d+\s', Number.Float),
1719 (r'-?\d+\s', Number.Integer),
1720 (r'HEX:\s+[a-fA-F\d]+\s', Number.Hex),
1721 (r'BIN:\s+[01]+\s', Number.Integer),
1722 (r'OCT:\s+[0-7]+\s', Number.Oct),
1723
1724 # operators
1725 (r'[-+/*=<>^]\s', Operator),
1726
1727 # keywords
1728 (r'(?:deprecated|final|foldable|flushable|inline|recursive)\s', Keyword),
1729
1730 # builtins
1731 (builtin_kernel, Name.Builtin),
1732 (builtin_assocs, Name.Builtin),
1733 (builtin_combinators, Name.Builtin),
1734 (builtin_math, Name.Builtin),
1735 (builtin_sequences, Name.Builtin),
1736 (builtin_namespaces, Name.Builtin),
1737 (builtin_arrays, Name.Builtin),
1738 (builtin_io, Name.Builtin),
1739 (builtin_strings, Name.Builtin),
1740 (builtin_vectors, Name.Builtin),
1741 (builtin_continuations, Name.Builtin),
1742
1743 # whitespaces - usually not relevant
1744 (r'\s+', Text),
1745
1746 # everything else is text
1747 (r'\S+', Text),
1748 ],
1749
1750 'stackeffect': [
1751 (r'\s*\(', Name.Function, 'stackeffect'),
1752 (r'\)', Name.Function, '#pop'),
1753 (r'\-\-', Name.Function),
1754 (r'\s+', Text),
1755 (r'\S+', Name.Variable),
1756 ],
1757
1758 'slots': [
1759 (r'\s+', Text),
1760 (r';\s', Keyword, '#pop'),
1761 (r'\S+', Name.Variable),
1762 ],
1763
1764 'import': [
1765 (r';', Keyword, '#pop'),
1766 (r'\S+', Name.Namespace),
1767 (r'\s+', Text),
1768 ],
1769 }
1770
1771
1772 class IokeLexer(RegexLexer):
1773 """
1774 For `Ioke <http://ioke.org/>`_ (a strongly typed, dynamic,
1775 prototype based programming language) source.
1776
1777 *New in Pygments 1.4.*
1778 """
1779 name = 'Ioke'
1780 filenames = ['*.ik']
1781 aliases = ['ioke', 'ik']
1782 mimetypes = ['text/x-iokesrc']
1783 tokens = {
1784 'interpolatableText': [
1785 (r'(\\b|\\e|\\t|\\n|\\f|\\r|\\"|\\\\|\\#|\\\Z|\\u[0-9a-fA-F]{1,4}'
1786 r'|\\[0-3]?[0-7]?[0-7])', String.Escape),
1787 (r'#{', Punctuation, 'textInterpolationRoot')
1788 ],
1789
1790 'text': [
1791 (r'(?<!\\)"', String, '#pop'),
1792 include('interpolatableText'),
1793 (r'[^"]', String)
1794 ],
1795
1796 'documentation': [
1797 (r'(?<!\\)"', String.Doc, '#pop'),
1798 include('interpolatableText'),
1799 (r'[^"]', String.Doc)
1800 ],
1801
1802 'textInterpolationRoot': [
1803 (r'}', Punctuation, '#pop'),
1804 include('root')
1805 ],
1806
1807 'slashRegexp': [
1808 (r'(?<!\\)/[oxpniums]*', String.Regex, '#pop'),
1809 include('interpolatableText'),
1810 (r'\\/', String.Regex),
1811 (r'[^/]', String.Regex)
1812 ],
1813
1814 'squareRegexp': [
1815 (r'(?<!\\)][oxpniums]*', String.Regex, '#pop'),
1816 include('interpolatableText'),
1817 (r'\\]', String.Regex),
1818 (r'[^\]]', String.Regex)
1819 ],
1820
1821 'squareText': [
1822 (r'(?<!\\)]', String, '#pop'),
1823 include('interpolatableText'),
1824 (r'[^\]]', String)
1825 ],
1826
1827 'root': [
1828 (r'\n', Text),
1829 (r'\s+', Text),
1830
1831 # Comments
1832 (r';(.*?)\n', Comment),
1833 (r'\A#!(.*?)\n', Comment),
1834
1835 #Regexps
1836 (r'#/', String.Regex, 'slashRegexp'),
1837 (r'#r\[', String.Regex, 'squareRegexp'),
1838
1839 #Symbols
1840 (r':[a-zA-Z0-9_!:?]+', String.Symbol),
1841 (r'[a-zA-Z0-9_!:?]+:(?![a-zA-Z0-9_!?])', String.Other),
1842 (r':"(\\\\|\\"|[^"])*"', String.Symbol),
1843
1844 #Documentation
1845 (r'((?<=fn\()|(?<=fnx\()|(?<=method\()|(?<=macro\()|(?<=lecro\()'
1846 r'|(?<=syntax\()|(?<=dmacro\()|(?<=dlecro\()|(?<=dlecrox\()'
1847 r'|(?<=dsyntax\())[\s\n\r]*"', String.Doc, 'documentation'),
1848
1849 #Text
1850 (r'"', String, 'text'),
1851 (r'#\[', String, 'squareText'),
1852
1853 #Mimic
1854 (r'[a-zA-Z0-9_][a-zA-Z0-9!?_:]+(?=\s*=.*mimic\s)', Name.Entity),
1855
1856 #Assignment
1857 (r'[a-zA-Z_][a-zA-Z0-9_!:?]*(?=[\s]*[+*/-]?=[^=].*($|\.))', Name.Variable),
1858
1859 # keywords
1860 (r'(break|cond|continue|do|ensure|for|for:dict|for:set|if|let|'
1861 r'loop|p:for|p:for:dict|p:for:set|return|unless|until|while|'
1862 r'with)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
1863
1864 # Origin
1865 (r'(eval|mimic|print|println)(?![a-zA-Z0-9!:_?])', Keyword),
1866
1867 # Base
1868 (r'(cell\?|cellNames|cellOwner\?|cellOwner|cells|cell|'
1869 r'documentation|hash|identity|mimic|removeCell\!|undefineCell\!)'
1870 r'(?![a-zA-Z0-9!:_?])', Keyword),
1871
1872 # Ground
1873 (r'(stackTraceAsText)(?![a-zA-Z0-9!:_?])', Keyword),
1874
1875 #DefaultBehaviour Literals
1876 (r'(dict|list|message|set)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
1877
1878 #DefaultBehaviour Case
1879 (r'(case|case:and|case:else|case:nand|case:nor|case:not|case:or|'
1880 r'case:otherwise|case:xor)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
1881
1882 #DefaultBehaviour Reflection
1883 (r'(asText|become\!|derive|freeze\!|frozen\?|in\?|is\?|kind\?|'
1884 r'mimic\!|mimics|mimics\?|prependMimic\!|removeAllMimics\!|'
1885 r'removeMimic\!|same\?|send|thaw\!|uniqueHexId)'
1886 r'(?![a-zA-Z0-9!:_?])', Keyword),
1887
1888 #DefaultBehaviour Aspects
1889 (r'(after|around|before)(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
1890
1891 # DefaultBehaviour
1892 (r'(kind|cellDescriptionDict|cellSummary|genSym|inspect|notice)'
1893 r'(?![a-zA-Z0-9!:_?])', Keyword),
1894 (r'(use|destructuring)', Keyword.Reserved),
1895
1896 #DefaultBehavior BaseBehavior
1897 (r'(cell\?|cellOwner\?|cellOwner|cellNames|cells|cell|'
1898 r'documentation|identity|removeCell!|undefineCell)'
1899 r'(?![a-zA-Z0-9!:_?])', Keyword),
1900
1901 #DefaultBehavior Internal
1902 (r'(internal:compositeRegexp|internal:concatenateText|'
1903 r'internal:createDecimal|internal:createNumber|'
1904 r'internal:createRegexp|internal:createText)'
1905 r'(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
1906
1907 #DefaultBehaviour Conditions
1908 (r'(availableRestarts|bind|error\!|findRestart|handle|'
1909 r'invokeRestart|rescue|restart|signal\!|warn\!)'
1910 r'(?![a-zA-Z0-9!:_?])', Keyword.Reserved),
1911
1912 # constants
1913 (r'(nil|false|true)(?![a-zA-Z0-9!:_?])', Name.Constant),
1914
1915 # names
1916 (r'(Arity|Base|Call|Condition|DateTime|Aspects|Pointcut|'
1917 r'Assignment|BaseBehavior|Boolean|Case|AndCombiner|Else|'
1918 r'NAndCombiner|NOrCombiner|NotCombiner|OrCombiner|XOrCombiner|'
1919 r'Conditions|Definitions|FlowControl|Internal|Literals|'
1920 r'Reflection|DefaultMacro|DefaultMethod|DefaultSyntax|Dict|'
1921 r'FileSystem|Ground|Handler|Hook|IO|IokeGround|Struct|'
1922 r'LexicalBlock|LexicalMacro|List|Message|Method|Mixins|'
1923 r'NativeMethod|Number|Origin|Pair|Range|Reflector|Regexp Match|'
1924 r'Regexp|Rescue|Restart|Runtime|Sequence|Set|Symbol|'
1925 r'System|Text|Tuple)(?![a-zA-Z0-9!:_?])', Name.Builtin),
1926
1927 # functions
1928 (r'(generateMatchMethod|aliasMethod|\u03bb|\u028E|fnx|fn|method|'
1929 r'dmacro|dlecro|syntax|macro|dlecrox|lecrox|lecro|syntax)'
1930 r'(?![a-zA-Z0-9!:_?])', Name.Function),
1931
1932 # Numbers
1933 (r'-?0[xX][0-9a-fA-F]+', Number.Hex),
1934 (r'-?(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
1935 (r'-?\d+', Number.Integer),
1936
1937 (r'#\(', Punctuation),
1938
1939 # Operators
1940 (r'(&&>>|\|\|>>|\*\*>>|:::|::|\.\.\.|===|\*\*>|\*\*=|&&>|&&=|'
1941 r'\|\|>|\|\|=|\->>|\+>>|!>>|<>>>|<>>|&>>|%>>|#>>|@>>|/>>|\*>>|'
1942 r'\?>>|\|>>|\^>>|~>>|\$>>|=>>|<<=|>>=|<=>|<\->|=~|!~|=>|\+\+|'
1943 r'\-\-|<=|>=|==|!=|&&|\.\.|\+=|\-=|\*=|\/=|%=|&=|\^=|\|=|<\-|'
1944 r'\+>|!>|<>|&>|%>|#>|\@>|\/>|\*>|\?>|\|>|\^>|~>|\$>|<\->|\->|'
1945 r'<<|>>|\*\*|\?\||\?&|\|\||>|<|\*|\/|%|\+|\-|&|\^|\||=|\$|!|~|'
1946 r'\?|#|\u2260|\u2218|\u2208|\u2209)', Operator),
1947 (r'(and|nand|or|xor|nor|return|import)(?![a-zA-Z0-9_!?])',
1948 Operator),
1949
1950 # Punctuation
1951 (r'(\`\`|\`|\'\'|\'|\.|\,|@|@@|\[|\]|\(|\)|{|})', Punctuation),
1952
1953 #kinds
1954 (r'[A-Z][a-zA-Z0-9_!:?]*', Name.Class),
1955
1956 #default cellnames
1957 (r'[a-z_][a-zA-Z0-9_!:?]*', Name)
1958 ]
1959 }

eric ide

mercurial