diff options
author | Georg Brandl <georg@python.org> | 2014-09-19 17:17:59 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-09-19 17:17:59 +0200 |
commit | 35bb72a4734b52beeddf0d9d27c98ee675742223 (patch) | |
tree | 98dc3125085aeac07403fd1e7e3ff18aa50694e2 | |
parent | ee30ccc917dd4e811514a07adb7c940bdd1564f4 (diff) | |
download | pygments-35bb72a4734b52beeddf0d9d27c98ee675742223.tar.gz |
More application of words().
-rw-r--r-- | pygments/lexers/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/agile.py | 3 | ||||
-rw-r--r-- | pygments/lexers/c_like/d.py | 11 | ||||
-rw-r--r-- | pygments/lexers/lisp.py | 20 | ||||
-rw-r--r-- | pygments/lexers/misc/factor.py | 332 | ||||
-rw-r--r-- | pygments/lexers/perl.py | 66 | ||||
-rw-r--r-- | pygments/lexers/ruby.py | 84 | ||||
-rw-r--r-- | pygments/lexers/scripting.py | 12 |
8 files changed, 272 insertions, 258 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 9907a9ac..068edc4f 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -199,7 +199,7 @@ LEXERS = { 'LiveScriptLexer': ('pygments.lexers.web', 'LiveScript', ('live-script', 'livescript'), ('*.ls',), ('text/livescript',)), 'LlvmLexer': ('pygments.lexers.asm', 'LLVM', ('llvm',), ('*.ll',), ('text/x-llvm',)), 'LogosLexer': ('pygments.lexers.c_like.objective', 'Logos', ('logos',), ('*.x', '*.xi', '*.xm', '*.xmi'), ('text/x-logos',)), - 'LogtalkLexer': ('pygments.lexers.other', 'Logtalk', ('logtalk',), ('*.lgt',), ('text/x-logtalk',)), + 'LogtalkLexer': ('pygments.lexers.other', 'Logtalk', ('logtalk',), ('*.lgt', '*.logtalk'), ('text/x-logtalk',)), 'LuaLexer': ('pygments.lexers.scripting', 'Lua', ('lua',), ('*.lua', '*.wlua'), ('text/x-lua', 'application/x-lua')), 'MOOCodeLexer': ('pygments.lexers.other', 'MOOCode', ('moocode', 'moo'), ('*.moo',), ('text/x-moocode',)), 'MakefileLexer': ('pygments.lexers.text', 'Makefile', ('make', 'makefile', 'mf', 'bsdmake'), ('*.mak', '*.mk', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'), ('text/x-makefile',)), diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py index e17d82ae..c90d3847 100644 --- a/pygments/lexers/agile.py +++ b/pygments/lexers/agile.py @@ -15,9 +15,10 @@ from pygments.lexers.python import PythonLexer, PythonConsoleLexer, \ PythonTracebackLexer, Python3Lexer, Python3TracebackLexer, DgLexer from pygments.lexers.ruby import RubyLexer, RubyConsoleLexer, FancyLexer from pygments.lexers.perl import PerlLexer, Perl6Lexer -from pygments.lexers.lua import LuaLexer, MoonScriptLexer from pygments.lexers.c_like.d import CrocLexer, MiniDLexer from pygments.lexers.misc.iolang import IoLexer from pygments.lexers.misc.tcl import TclLexer +from pygments.lexers.misc.factor import FactorLexer +from pygments.lexers.scripting import LuaLexer, MoonScriptLexer __all__ = [] diff --git a/pygments/lexers/c_like/d.py b/pygments/lexers/c_like/d.py index e2440f37..d629673c 100644 --- a/pygments/lexers/c_like/d.py +++ b/pygments/lexers/c_like/d.py @@ -196,10 +196,13 @@ class CrocLexer(RegexLexer): (r'//(.*?)\n', Comment.Single), (r'/\*', Comment.Multiline, 'nestedcomment'), # Keywords - (r'(as|assert|break|case|catch|class|continue|default' - r'|do|else|finally|for|foreach|function|global|namespace' - r'|if|import|in|is|local|module|return|scope|super|switch' - r'|this|throw|try|vararg|while|with|yield)\b', Keyword), + (words(( + 'as', 'assert', 'break', 'case', 'catch', 'class', 'continue', + 'default', 'do', 'else', 'finally', 'for', 'foreach', 'function', + 'global', 'namespace', 'if', 'import', 'in', 'is', 'local', + 'module', 'return', 'scope', 'super', 'switch', 'this', 'throw', + 'try', 'vararg', 'while', 'with', 'yield'), suffix=r'\b'), + Keyword), (r'(false|true|null)\b', Keyword.Constant), # FloatLiteral (r'([0-9][0-9_]*)(?=[.eE])(\.[0-9][0-9_]*)?([eE][+\-]?[0-9_]+)?', diff --git a/pygments/lexers/lisp.py b/pygments/lexers/lisp.py index 9e5b037c..f09f2c8e 100644 --- a/pygments/lexers/lisp.py +++ b/pygments/lexers/lisp.py @@ -9,9 +9,7 @@ :license: BSD, see LICENSE for details. """ -import re - -from pygments.lexer import RegexLexer, include, bygroups +from pygments.lexer import RegexLexer, include, bygroups, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation @@ -31,7 +29,7 @@ class HyLexer(RegexLexer): filenames = ['*.hy'] mimetypes = ['text/x-hy', 'application/x-hy'] - special_forms = [ + special_forms = ( 'cond', 'for', '->', '->>', 'car', 'cdr', 'first', 'rest', 'let', 'when', 'unless', 'import', 'do', 'progn', 'get', 'slice', 'assoc', 'with-decorator', @@ -39,20 +37,20 @@ class HyLexer(RegexLexer): 'quasiquote', 'unquote', 'unquote-splice', 'quote', '|', '<<=', '>>=', 'foreach', 'while', 'eval-and-compile', 'eval-when-compile' - ] + ) - declarations = [ + declarations = ( 'def', 'defn', 'defun', 'defmacro', 'defclass', 'lambda', 'fn', 'setv' - ] + ) - hy_builtins = [] + hy_builtins = () - hy_core = [ + hy_core = ( 'cycle', 'dec', 'distinct', 'drop', 'even?', 'filter', 'inc', 'instance?', 'iterable?', 'iterate', 'iterator?', 'neg?', 'none?', 'nth', 'numeric?', 'odd?', 'pos?', 'remove', 'repeat', 'repeatedly', 'take', 'take_nth', 'take_while', 'zero?' - ] + ) builtins = hy_builtins + hy_core @@ -62,7 +60,7 @@ class HyLexer(RegexLexer): valid_name = r'(?!#)[\w!$%*+<=>?/.#-]+' def _multi_escape(entries): - return '(%s)' % ('|'.join(re.escape(entry) + ' ' for entry in entries)) + return words(entries, suffix=' ') tokens = { 'root': [ diff --git a/pygments/lexers/misc/factor.py b/pygments/lexers/misc/factor.py index c51a45a6..04051976 100644 --- a/pygments/lexers/misc/factor.py +++ b/pygments/lexers/misc/factor.py @@ -11,7 +11,7 @@ import re -from pygments.lexer import RegexLexer, bygroups, default +from pygments.lexer import RegexLexer, bygroups, default, words from pygments.token import Text, Comment, Keyword, Name, String, Number __all__ = ['FactorLexer'] @@ -30,174 +30,168 @@ class FactorLexer(RegexLexer): flags = re.MULTILINE | re.UNICODE - builtin_kernel = ( - r'(?:-rot|2bi|2bi@|2bi\*|2curry|2dip|2drop|2dup|2keep|2nip|' - r'2over|2tri|2tri@|2tri\*|3bi|3curry|3dip|3drop|3dup|3keep|' - r'3tri|4dip|4drop|4dup|4keep|<wrapper>|=|>boolean|\(clone\)|' - r'\?|\?execute|\?if|and|assert|assert=|assert\?|bi|bi-curry|' - r'bi-curry@|bi-curry\*|bi@|bi\*|boa|boolean|boolean\?|both\?|' - r'build|call|callstack|callstack>array|callstack\?|clear|clone|' - r'compose|compose\?|curry|curry\?|datastack|die|dip|do|drop|' - r'dup|dupd|either\?|eq\?|equal\?|execute|hashcode|hashcode\*|' - r'identity-hashcode|identity-tuple|identity-tuple\?|if|if\*|' - r'keep|loop|most|new|nip|not|null|object|or|over|pick|prepose|' - r'retainstack|rot|same\?|swap|swapd|throw|tri|tri-curry|' - r'tri-curry@|tri-curry\*|tri@|tri\*|tuple|tuple\?|unless|' - r'unless\*|until|when|when\*|while|with|wrapper|wrapper\?|xor)\s' - ) - - builtin_assocs = ( - r'(?:2cache|<enum>|>alist|\?at|\?of|assoc|assoc-all\?|' - r'assoc-any\?|assoc-clone-like|assoc-combine|assoc-diff|' - r'assoc-diff!|assoc-differ|assoc-each|assoc-empty\?|' - r'assoc-filter|assoc-filter!|assoc-filter-as|assoc-find|' - r'assoc-hashcode|assoc-intersect|assoc-like|assoc-map|' - r'assoc-map-as|assoc-partition|assoc-refine|assoc-size|' - r'assoc-stack|assoc-subset\?|assoc-union|assoc-union!|' - r'assoc=|assoc>map|assoc\?|at|at+|at\*|cache|change-at|' - r'clear-assoc|delete-at|delete-at\*|enum|enum\?|extract-keys|' - r'inc-at|key\?|keys|map>assoc|maybe-set-at|new-assoc|of|' - r'push-at|rename-at|set-at|sift-keys|sift-values|substitute|' - r'unzip|value-at|value-at\*|value\?|values|zip)\s' - ) - - builtin_combinators = ( - r'(?:2cleave|2cleave>quot|3cleave|3cleave>quot|4cleave|' - r'4cleave>quot|alist>quot|call-effect|case|case-find|' - r'case>quot|cleave|cleave>quot|cond|cond>quot|deep-spread>quot|' - r'execute-effect|linear-case-quot|no-case|no-case\?|no-cond|' - r'no-cond\?|recursive-hashcode|shallow-spread>quot|spread|' - r'to-fixed-point|wrong-values|wrong-values\?)\s' - ) - - builtin_math = ( - r'(?:-|/|/f|/i|/mod|2/|2\^|<|<=|<fp-nan>|>|>=|>bignum|' - r'>fixnum|>float|>integer|\(all-integers\?\)|' - r'\(each-integer\)|\(find-integer\)|\*|\+|\?1\+|' - r'abs|align|all-integers\?|bignum|bignum\?|bit\?|bitand|' - r'bitnot|bitor|bits>double|bits>float|bitxor|complex|' - r'complex\?|denominator|double>bits|each-integer|even\?|' - r'find-integer|find-last-integer|fixnum|fixnum\?|float|' - r'float>bits|float\?|fp-bitwise=|fp-infinity\?|fp-nan-payload|' - r'fp-nan\?|fp-qnan\?|fp-sign|fp-snan\?|fp-special\?|' - r'if-zero|imaginary-part|integer|integer>fixnum|' - r'integer>fixnum-strict|integer\?|log2|log2-expects-positive|' - r'log2-expects-positive\?|mod|neg|neg\?|next-float|' - r'next-power-of-2|number|number=|number\?|numerator|odd\?|' - r'out-of-fixnum-range|out-of-fixnum-range\?|power-of-2\?|' - r'prev-float|ratio|ratio\?|rational|rational\?|real|' - r'real-part|real\?|recip|rem|sgn|shift|sq|times|u<|u<=|u>|' - r'u>=|unless-zero|unordered\?|when-zero|zero\?)\s' - ) - - builtin_sequences = ( - r'(?:1sequence|2all\?|2each|2map|2map-as|2map-reduce|2reduce|' - r'2selector|2sequence|3append|3append-as|3each|3map|3map-as|' - r'3sequence|4sequence|<repetition>|<reversed>|<slice>|\?first|' - r'\?last|\?nth|\?second|\?set-nth|accumulate|accumulate!|' - r'accumulate-as|all\?|any\?|append|append!|append-as|' - r'assert-sequence|assert-sequence=|assert-sequence\?|' - r'binary-reduce|bounds-check|bounds-check\?|bounds-error|' - r'bounds-error\?|but-last|but-last-slice|cartesian-each|' - r'cartesian-map|cartesian-product|change-nth|check-slice|' - r'check-slice-error|clone-like|collapse-slice|collector|' - r'collector-for|concat|concat-as|copy|count|cut|cut-slice|' - r'cut\*|delete-all|delete-slice|drop-prefix|each|each-from|' - r'each-index|empty\?|exchange|filter|filter!|filter-as|find|' - r'find-from|find-index|find-index-from|find-last|find-last-from|' - r'first|first2|first3|first4|flip|follow|fourth|glue|halves|' - r'harvest|head|head-slice|head-slice\*|head\*|head\?|' - r'if-empty|immutable|immutable-sequence|immutable-sequence\?|' - r'immutable\?|index|index-from|indices|infimum|infimum-by|' - r'insert-nth|interleave|iota|iota-tuple|iota-tuple\?|join|' - r'join-as|last|last-index|last-index-from|length|lengthen|' - r'like|longer|longer\?|longest|map|map!|map-as|map-find|' - r'map-find-last|map-index|map-integers|map-reduce|map-sum|' - r'max-length|member-eq\?|member\?|midpoint@|min-length|' - r'mismatch|move|new-like|new-resizable|new-sequence|' - r'non-negative-integer-expected|non-negative-integer-expected\?|' - r'nth|nths|pad-head|pad-tail|padding|partition|pop|pop\*|' - r'prefix|prepend|prepend-as|produce|produce-as|product|push|' - r'push-all|push-either|push-if|reduce|reduce-index|remove|' - r'remove!|remove-eq|remove-eq!|remove-nth|remove-nth!|repetition|' - r'repetition\?|replace-slice|replicate|replicate-as|rest|' - r'rest-slice|reverse|reverse!|reversed|reversed\?|second|' - r'selector|selector-for|sequence|sequence-hashcode|sequence=|' - r'sequence\?|set-first|set-fourth|set-last|set-length|set-nth|' - r'set-second|set-third|short|shorten|shorter|shorter\?|' - r'shortest|sift|slice|slice-error|slice-error\?|slice\?|' - r'snip|snip-slice|start|start\*|subseq|subseq\?|suffix|' - r'suffix!|sum|sum-lengths|supremum|supremum-by|surround|tail|' - r'tail-slice|tail-slice\*|tail\*|tail\?|third|trim|' - r'trim-head|trim-head-slice|trim-slice|trim-tail|trim-tail-slice|' - r'unclip|unclip-last|unclip-last-slice|unclip-slice|unless-empty|' - r'virtual-exemplar|virtual-sequence|virtual-sequence\?|virtual@|' - r'when-empty)\s' - ) - - builtin_namespaces = ( - r'(?:\+@|change|change-global|counter|dec|get|get-global|' - r'global|inc|init-namespaces|initialize|is-global|make-assoc|' - r'namespace|namestack|off|on|set|set-global|set-namestack|' - r'toggle|with-global|with-scope|with-variable|with-variables)\s' - ) - - builtin_arrays = ( - r'(?:1array|2array|3array|4array|<array>|>array|array|array\?|' - r'pair|pair\?|resize-array)\s' - ) - - builtin_io = ( - r'(?:\(each-stream-block-slice\)|\(each-stream-block\)|' - r'\(stream-contents-by-block\)|\(stream-contents-by-element\)|' - r'\(stream-contents-by-length-or-block\)|' - r'\(stream-contents-by-length\)|\+byte\+|\+character\+|' - r'bad-seek-type|bad-seek-type\?|bl|contents|each-block|' - r'each-block-size|each-block-slice|each-line|each-morsel|' - r'each-stream-block|each-stream-block-slice|each-stream-line|' - r'error-stream|flush|input-stream|input-stream\?|' - r'invalid-read-buffer|invalid-read-buffer\?|lines|nl|' - r'output-stream|output-stream\?|print|read|read-into|' - r'read-partial|read-partial-into|read-until|read1|readln|' - r'seek-absolute|seek-absolute\?|seek-end|seek-end\?|' - r'seek-input|seek-output|seek-relative|seek-relative\?|' - r'stream-bl|stream-contents|stream-contents\*|stream-copy|' - r'stream-copy\*|stream-element-type|stream-flush|' - r'stream-length|stream-lines|stream-nl|stream-print|' - r'stream-read|stream-read-into|stream-read-partial|' - r'stream-read-partial-into|stream-read-partial-unsafe|' - r'stream-read-unsafe|stream-read-until|stream-read1|' - r'stream-readln|stream-seek|stream-seekable\?|stream-tell|' - r'stream-write|stream-write1|tell-input|tell-output|' - r'with-error-stream|with-error-stream\*|with-error>output|' - r'with-input-output\+error-streams|' - r'with-input-output\+error-streams\*|with-input-stream|' - r'with-input-stream\*|with-output-stream|with-output-stream\*|' - r'with-output>error|with-output\+error-stream|' - r'with-output\+error-stream\*|with-streams|with-streams\*|' - r'write|write1)\s' - ) - - builtin_strings = ( - r'(?:1string|<string>|>string|resize-string|string|string\?)\s' - ) - - builtin_vectors = ( - r'(?:1vector|<vector>|>vector|\?push|vector|vector\?)\s' - ) - - builtin_continuations = ( - r'(?:<condition>|<continuation>|<restart>|attempt-all|' - r'attempt-all-error|attempt-all-error\?|callback-error-hook|' - r'callcc0|callcc1|cleanup|compute-restarts|condition|' - r'condition\?|continuation|continuation\?|continue|' - r'continue-restart|continue-with|current-continuation|' - r'error|error-continuation|error-in-thread|error-thread|' - r'ifcc|ignore-errors|in-callback\?|original-error|recover|' - r'restart|restart\?|restarts|rethrow|rethrow-restarts|' - r'return|return-continuation|thread-error-hook|throw-continue|' - r'throw-restarts|with-datastack|with-return)\s' - ) + builtin_kernel = words(( + '-rot', '2bi', '2bi@', '2bi*', '2curry', '2dip', '2drop', '2dup', '2keep', '2nip', + '2over', '2tri', '2tri@', '2tri*', '3bi', '3curry', '3dip', '3drop', '3dup', '3keep', + '3tri', '4dip', '4drop', '4dup', '4keep', '<wrapper>', '=', '>boolean', 'clone', + '?', '?execute', '?if', 'and', 'assert', 'assert=', 'assert?', 'bi', 'bi-curry', + 'bi-curry@', 'bi-curry*', 'bi@', 'bi*', 'boa', 'boolean', 'boolean?', 'both?', + 'build', 'call', 'callstack', 'callstack>array', 'callstack?', 'clear', '(clone)', + 'compose', 'compose?', 'curry', 'curry?', 'datastack', 'die', 'dip', 'do', 'drop', + 'dup', 'dupd', 'either?', 'eq?', 'equal?', 'execute', 'hashcode', 'hashcode*', + 'identity-hashcode', 'identity-tuple', 'identity-tuple?', 'if', 'if*', + 'keep', 'loop', 'most', 'new', 'nip', 'not', 'null', 'object', 'or', 'over', + 'pick', 'prepose', 'retainstack', 'rot', 'same?', 'swap', 'swapd', 'throw', + 'tri', 'tri-curry', 'tri-curry@', 'tri-curry*', 'tri@', 'tri*', 'tuple', + 'tuple?', 'unless', 'unless*', 'until', 'when', 'when*', 'while', 'with', + 'wrapper', 'wrapper?', 'xor'), suffix=r'\s') + + builtin_assocs = words(( + '2cache', '<enum>', '>alist', '?at', '?of', 'assoc', 'assoc-all?', + 'assoc-any?', 'assoc-clone-like', 'assoc-combine', 'assoc-diff', + 'assoc-diff!', 'assoc-differ', 'assoc-each', 'assoc-empty?', + 'assoc-filter', 'assoc-filter!', 'assoc-filter-as', 'assoc-find', + 'assoc-hashcode', 'assoc-intersect', 'assoc-like', 'assoc-map', + 'assoc-map-as', 'assoc-partition', 'assoc-refine', 'assoc-size', + 'assoc-stack', 'assoc-subset?', 'assoc-union', 'assoc-union!', + 'assoc=', 'assoc>map', 'assoc?', 'at', 'at+', 'at*', 'cache', 'change-at', + 'clear-assoc', 'delete-at', 'delete-at*', 'enum', 'enum?', 'extract-keys', + 'inc-at', 'key?', 'keys', 'map>assoc', 'maybe-set-at', 'new-assoc', 'of', + 'push-at', 'rename-at', 'set-at', 'sift-keys', 'sift-values', 'substitute', + 'unzip', 'value-at', 'value-at*', 'value?', 'values', 'zip'), suffix=r'\s') + + builtin_combinators = words(( + '2cleave', '2cleave>quot', '3cleave', '3cleave>quot', '4cleave', + '4cleave>quot', 'alist>quot', 'call-effect', 'case', 'case-find', + 'case>quot', 'cleave', 'cleave>quot', 'cond', 'cond>quot', 'deep-spread>quot', + 'execute-effect', 'linear-case-quot', 'no-case', 'no-case?', 'no-cond', + 'no-cond?', 'recursive-hashcode', 'shallow-spread>quot', 'spread', + 'to-fixed-point', 'wrong-values', 'wrong-values?'), suffix=r'\s') + + builtin_math = words(( + '-', '/', '/f', '/i', '/mod', '2/', '2^', '<', '<=', '<fp-nan>', '>', + '>=', '>bignum', '>fixnum', '>float', '>integer', '(all-integers?)', + '(each-integer)', '(find-integer)', '*', '+', '?1+', + 'abs', 'align', 'all-integers?', 'bignum', 'bignum?', 'bit?', 'bitand', + 'bitnot', 'bitor', 'bits>double', 'bits>float', 'bitxor', 'complex', + 'complex?', 'denominator', 'double>bits', 'each-integer', 'even?', + 'find-integer', 'find-last-integer', 'fixnum', 'fixnum?', 'float', + 'float>bits', 'float?', 'fp-bitwise=', 'fp-infinity?', 'fp-nan-payload', + 'fp-nan?', 'fp-qnan?', 'fp-sign', 'fp-snan?', 'fp-special?', + 'if-zero', 'imaginary-part', 'integer', 'integer>fixnum', + 'integer>fixnum-strict', 'integer?', 'log2', 'log2-expects-positive', + 'log2-expects-positive?', 'mod', 'neg', 'neg?', 'next-float', + 'next-power-of-2', 'number', 'number=', 'number?', 'numerator', 'odd?', + 'out-of-fixnum-range', 'out-of-fixnum-range?', 'power-of-2?', + 'prev-float', 'ratio', 'ratio?', 'rational', 'rational?', 'real', + 'real-part', 'real?', 'recip', 'rem', 'sgn', 'shift', 'sq', 'times', + 'u<', 'u<=', 'u>', 'u>=', 'unless-zero', 'unordered?', 'when-zero', + 'zero?'), suffix=r'\s') + + builtin_sequences = words(( + '1sequence', '2all?', '2each', '2map', '2map-as', '2map-reduce', '2reduce', + '2selector', '2sequence', '3append', '3append-as', '3each', '3map', '3map-as', + '3sequence', '4sequence', '<repetition>', '<reversed>', '<slice>', '?first', + '?last', '?nth', '?second', '?set-nth', 'accumulate', 'accumulate!', + 'accumulate-as', 'all?', 'any?', 'append', 'append!', 'append-as', + 'assert-sequence', 'assert-sequence=', 'assert-sequence?', + 'binary-reduce', 'bounds-check', 'bounds-check?', 'bounds-error', + 'bounds-error?', 'but-last', 'but-last-slice', 'cartesian-each', + 'cartesian-map', 'cartesian-product', 'change-nth', 'check-slice', + 'check-slice-error', 'clone-like', 'collapse-slice', 'collector', + 'collector-for', 'concat', 'concat-as', 'copy', 'count', 'cut', 'cut-slice', + 'cut*', 'delete-all', 'delete-slice', 'drop-prefix', 'each', 'each-from', + 'each-index', 'empty?', 'exchange', 'filter', 'filter!', 'filter-as', 'find', + 'find-from', 'find-index', 'find-index-from', 'find-last', 'find-last-from', + 'first', 'first2', 'first3', 'first4', 'flip', 'follow', 'fourth', 'glue', 'halves', + 'harvest', 'head', 'head-slice', 'head-slice*', 'head*', 'head?', + 'if-empty', 'immutable', 'immutable-sequence', 'immutable-sequence?', + 'immutable?', 'index', 'index-from', 'indices', 'infimum', 'infimum-by', + 'insert-nth', 'interleave', 'iota', 'iota-tuple', 'iota-tuple?', 'join', + 'join-as', 'last', 'last-index', 'last-index-from', 'length', 'lengthen', + 'like', 'longer', 'longer?', 'longest', 'map', 'map!', 'map-as', 'map-find', + 'map-find-last', 'map-index', 'map-integers', 'map-reduce', 'map-sum', + 'max-length', 'member-eq?', 'member?', 'midpoint@', 'min-length', + 'mismatch', 'move', 'new-like', 'new-resizable', 'new-sequence', + 'non-negative-integer-expected', 'non-negative-integer-expected?', + 'nth', 'nths', 'pad-head', 'pad-tail', 'padding', 'partition', 'pop', 'pop*', + 'prefix', 'prepend', 'prepend-as', 'produce', 'produce-as', 'product', 'push', + 'push-all', 'push-either', 'push-if', 'reduce', 'reduce-index', 'remove', + 'remove!', 'remove-eq', 'remove-eq!', 'remove-nth', 'remove-nth!', 'repetition', + 'repetition?', 'replace-slice', 'replicate', 'replicate-as', 'rest', + 'rest-slice', 'reverse', 'reverse!', 'reversed', 'reversed?', 'second', + 'selector', 'selector-for', 'sequence', 'sequence-hashcode', 'sequence=', + 'sequence?', 'set-first', 'set-fourth', 'set-last', 'set-length', 'set-nth', + 'set-second', 'set-third', 'short', 'shorten', 'shorter', 'shorter?', + 'shortest', 'sift', 'slice', 'slice-error', 'slice-error?', 'slice?', + 'snip', 'snip-slice', 'start', 'start*', 'subseq', 'subseq?', 'suffix', + 'suffix!', 'sum', 'sum-lengths', 'supremum', 'supremum-by', 'surround', 'tail', + 'tail-slice', 'tail-slice*', 'tail*', 'tail?', 'third', 'trim', + 'trim-head', 'trim-head-slice', 'trim-slice', 'trim-tail', 'trim-tail-slice', + 'unclip', 'unclip-last', 'unclip-last-slice', 'unclip-slice', 'unless-empty', + 'virtual-exemplar', 'virtual-sequence', 'virtual-sequence?', 'virtual@', + 'when-empty'), suffix=r'\s') + + builtin_namespaces = words(( + '+@', 'change', 'change-global', 'counter', 'dec', 'get', 'get-global', + 'global', 'inc', 'init-namespaces', 'initialize', 'is-global', 'make-assoc', + 'namespace', 'namestack', 'off', 'on', 'set', 'set-global', 'set-namestack', + 'toggle', 'with-global', 'with-scope', 'with-variable', 'with-variables'), + suffix=r'\s') + + builtin_arrays = words(( + '1array', '2array', '3array', '4array', '<array>', '>array', 'array', + 'array?', 'pair', 'pair?', 'resize-array'), suffix=r'\s') + + builtin_io = words(( + '(each-stream-block-slice)', '(each-stream-block)', + '(stream-contents-by-block)', '(stream-contents-by-element)', + '(stream-contents-by-length-or-block)', + '(stream-contents-by-length)', '+byte+', '+character+', + 'bad-seek-type', 'bad-seek-type?', 'bl', 'contents', 'each-block', + 'each-block-size', 'each-block-slice', 'each-line', 'each-morsel', + 'each-stream-block', 'each-stream-block-slice', 'each-stream-line', + 'error-stream', 'flush', 'input-stream', 'input-stream?', + 'invalid-read-buffer', 'invalid-read-buffer?', 'lines', 'nl', + 'output-stream', 'output-stream?', 'print', 'read', 'read-into', + 'read-partial', 'read-partial-into', 'read-until', 'read1', 'readln', + 'seek-absolute', 'seek-absolute?', 'seek-end', 'seek-end?', + 'seek-input', 'seek-output', 'seek-relative', 'seek-relative?', + 'stream-bl', 'stream-contents', 'stream-contents*', 'stream-copy', + 'stream-copy*', 'stream-element-type', 'stream-flush', + 'stream-length', 'stream-lines', 'stream-nl', 'stream-print', + 'stream-read', 'stream-read-into', 'stream-read-partial', + 'stream-read-partial-into', 'stream-read-partial-unsafe', + 'stream-read-unsafe', 'stream-read-until', 'stream-read1', + 'stream-readln', 'stream-seek', 'stream-seekable?', 'stream-tell', + 'stream-write', 'stream-write1', 'tell-input', 'tell-output', + 'with-error-stream', 'with-error-stream*', 'with-error>output', + 'with-input-output+error-streams', + 'with-input-output+error-streams*', 'with-input-stream', + 'with-input-stream*', 'with-output-stream', 'with-output-stream*', + 'with-output>error', 'with-output+error-stream', + 'with-output+error-stream*', 'with-streams', 'with-streams*', + 'write', 'write1'), suffix=r'\s') + + builtin_strings = words(( + '1string', '<string>', '>string', 'resize-string', 'string', + 'string?'), suffix=r'\s') + + builtin_vectors = words(( + '1vector', '<vector>', '>vector', '?push', 'vector', 'vector?'), + suffix=r'\s') + + builtin_continuations = words(( + '<condition>', '<continuation>', '<restart>', 'attempt-all', + 'attempt-all-error', 'attempt-all-error?', 'callback-error-hook', + 'callcc0', 'callcc1', 'cleanup', 'compute-restarts', 'condition', + 'condition?', 'continuation', 'continuation?', 'continue', + 'continue-restart', 'continue-with', 'current-continuation', + 'error', 'error-continuation', 'error-in-thread', 'error-thread', + 'ifcc', 'ignore-errors', 'in-callback?', 'original-error', 'recover', + 'restart', 'restart?', 'restarts', 'rethrow', 'rethrow-restarts', + 'return', 'return-continuation', 'thread-error-hook', 'throw-continue', + 'throw-restarts', 'with-datastack', 'with-return'), suffix=r'\s') tokens = { 'root': [ diff --git a/pygments/lexers/perl.py b/pygments/lexers/perl.py index fbd1c47f..56c5e0ec 100644 --- a/pygments/lexers/perl.py +++ b/pygments/lexers/perl.py @@ -12,7 +12,7 @@ import re from pygments.lexer import RegexLexer, ExtendedRegexLexer, include, bygroups, \ - using, this, default + using, this, default, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation from pygments.util import shebang_matches @@ -48,9 +48,12 @@ class PerlLexer(RegexLexer): 'root': [ (r'\#.*?$', Comment.Single), (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline), - (r'(case|continue|do|else|elsif|for|foreach|if|last|my|' - r'next|our|redo|reset|then|unless|until|while|use|' - r'print|new|BEGIN|CHECK|INIT|END|return)\b', Keyword), + (words(( + 'case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach', + 'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then', + 'unless', 'until', 'while', 'use', 'print', 'new', 'BEGIN', + 'CHECK', 'INIT', 'END', 'return'), suffix=r'\b'), + Keyword), (r'(format)(\s+)(\w+)(\s*)(=)(\s*\n)', bygroups(Keyword, Text, Name, Text, Punctuation, Text), 'format'), (r'(eq|lt|gt|le|ge|ne|not|and|or|cmp)\b', Operator.Word), @@ -76,33 +79,34 @@ class PerlLexer(RegexLexer): (r'((?<==~)|(?<=\())\s*/(\\\\|\\[^\\]|[^\\/])*/[gcimosx]*', String.Regex), (r'\s+', Text), - (r'(abs|accept|alarm|atan2|bind|binmode|bless|caller|chdir|' - r'chmod|chomp|chop|chown|chr|chroot|close|closedir|connect|' - r'continue|cos|crypt|dbmclose|dbmopen|defined|delete|die|' - r'dump|each|endgrent|endhostent|endnetent|endprotoent|' - r'endpwent|endservent|eof|eval|exec|exists|exit|exp|fcntl|' - r'fileno|flock|fork|format|formline|getc|getgrent|getgrgid|' - r'getgrnam|gethostbyaddr|gethostbyname|gethostent|getlogin|' - r'getnetbyaddr|getnetbyname|getnetent|getpeername|getpgrp|' - r'getppid|getpriority|getprotobyname|getprotobynumber|' - r'getprotoent|getpwent|getpwnam|getpwuid|getservbyname|' - r'getservbyport|getservent|getsockname|getsockopt|glob|gmtime|' - r'goto|grep|hex|import|index|int|ioctl|join|keys|kill|last|' - r'lc|lcfirst|length|link|listen|local|localtime|log|lstat|' - r'map|mkdir|msgctl|msgget|msgrcv|msgsnd|my|next|no|oct|open|' - r'opendir|ord|our|pack|package|pipe|pop|pos|printf|' - r'prototype|push|quotemeta|rand|read|readdir|' - r'readline|readlink|readpipe|recv|redo|ref|rename|require|' - r'reverse|rewinddir|rindex|rmdir|scalar|seek|seekdir|' - r'select|semctl|semget|semop|send|setgrent|sethostent|setnetent|' - r'setpgrp|setpriority|setprotoent|setpwent|setservent|' - r'setsockopt|shift|shmctl|shmget|shmread|shmwrite|shutdown|' - r'sin|sleep|socket|socketpair|sort|splice|split|sprintf|sqrt|' - r'srand|stat|study|substr|symlink|syscall|sysopen|sysread|' - r'sysseek|system|syswrite|tell|telldir|tie|tied|time|times|tr|' - r'truncate|uc|ucfirst|umask|undef|unlink|unpack|unshift|untie|' - r'utime|values|vec|wait|waitpid|wantarray|warn|write' - r')\b', Name.Builtin), + (words(( + 'abs', 'accept', 'alarm', 'atan2', 'bind', 'binmode', 'bless', 'caller', 'chdir', + 'chmod', 'chomp', 'chop', 'chown', 'chr', 'chroot', 'close', 'closedir', 'connect', + 'continue', 'cos', 'crypt', 'dbmclose', 'dbmopen', 'defined', 'delete', 'die', + 'dump', 'each', 'endgrent', 'endhostent', 'endnetent', 'endprotoent', + 'endpwent', 'endservent', 'eof', 'eval', 'exec', 'exists', 'exit', 'exp', 'fcntl', + 'fileno', 'flock', 'fork', 'format', 'formline', 'getc', 'getgrent', 'getgrgid', + 'getgrnam', 'gethostbyaddr', 'gethostbyname', 'gethostent', 'getlogin', + 'getnetbyaddr', 'getnetbyname', 'getnetent', 'getpeername', 'getpgrp', + 'getppid', 'getpriority', 'getprotobyname', 'getprotobynumber', + 'getprotoent', 'getpwent', 'getpwnam', 'getpwuid', 'getservbyname', + 'getservbyport', 'getservent', 'getsockname', 'getsockopt', 'glob', 'gmtime', + 'goto', 'grep', 'hex', 'import', 'index', 'int', 'ioctl', 'join', 'keys', 'kill', 'last', + 'lc', 'lcfirst', 'length', 'link', 'listen', 'local', 'localtime', 'log', 'lstat', + 'map', 'mkdir', 'msgctl', 'msgget', 'msgrcv', 'msgsnd', 'my', 'next', 'no', 'oct', 'open', + 'opendir', 'ord', 'our', 'pack', 'package', 'pipe', 'pop', 'pos', 'printf', + 'prototype', 'push', 'quotemeta', 'rand', 'read', 'readdir', + 'readline', 'readlink', 'readpipe', 'recv', 'redo', 'ref', 'rename', 'require', + 'reverse', 'rewinddir', 'rindex', 'rmdir', 'scalar', 'seek', 'seekdir', + 'select', 'semctl', 'semget', 'semop', 'send', 'setgrent', 'sethostent', 'setnetent', + 'setpgrp', 'setpriority', 'setprotoent', 'setpwent', 'setservent', + 'setsockopt', 'shift', 'shmctl', 'shmget', 'shmread', 'shmwrite', 'shutdown', + 'sin', 'sleep', 'socket', 'socketpair', 'sort', 'splice', 'split', 'sprintf', 'sqrt', + 'srand', 'stat', 'study', 'substr', 'symlink', 'syscall', 'sysopen', 'sysread', + 'sysseek', 'system', 'syswrite', 'tell', 'telldir', 'tie', 'tied', 'time', 'times', 'tr', + 'truncate', 'uc', 'ucfirst', 'umask', 'undef', 'unlink', 'unpack', 'unshift', 'untie', + 'utime', 'values', 'vec', 'wait', 'waitpid', 'wantarray', 'warn', 'write'), suffix=r'\b'), + Name.Builtin), (r'((__(DATA|DIE|WARN)__)|(STD(IN|OUT|ERR)))\b', Name.Builtin.Pseudo), (r'<<([\'"]?)([a-zA-Z_]\w*)\1;?\n.*?\n\2\n', String), (r'__END__', Comment.Preproc, 'end-part'), diff --git a/pygments/lexers/ruby.py b/pygments/lexers/ruby.py index 291674d0..eadb670d 100644 --- a/pygments/lexers/ruby.py +++ b/pygments/lexers/ruby.py @@ -12,7 +12,7 @@ import re from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, include, \ - bygroups, default, LexerContext, do_insertions + bygroups, default, LexerContext, do_insertions, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Error, Generic from pygments.util import shebang_matches @@ -186,10 +186,12 @@ class RubyLexer(ExtendedRegexLexer): (r'#.*?$', Comment.Single), (r'=begin\s.*?\n=end.*?$', Comment.Multiline), # keywords - (r'(BEGIN|END|alias|begin|break|case|defined\?|' - r'do|else|elsif|end|ensure|for|if|in|next|redo|' - r'rescue|raise|retry|return|super|then|undef|unless|until|when|' - r'while|yield)\b', Keyword), + (words(( + 'BEGIN', 'END', 'alias', 'begin', 'break', 'case', 'defined?', + 'do', 'else', 'elsif', 'end', 'ensure', 'for', 'if', 'in', 'next', 'redo', + 'rescue', 'raise', 'retry', 'return', 'super', 'then', 'undef', + 'unless', 'until', 'when', 'while', 'yield'), suffix=r'\b'), + Keyword), # start of function, class and module names (r'(module)(\s+)([a-zA-Z_]\w*' r'(?:::[a-zA-Z_]\w*)*)', @@ -198,37 +200,43 @@ class RubyLexer(ExtendedRegexLexer): (r'def(?=[*%&^`~+-/\[<>=])', Keyword, 'funcname'), (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), # special methods - (r'(initialize|new|loop|include|extend|raise|attr_reader|' - r'attr_writer|attr_accessor|attr|catch|throw|private|' - r'module_function|public|protected|true|false|nil)\b', + (words(( + 'initialize', 'new', 'loop', 'include', 'extend', 'raise', 'attr_reader', + 'attr_writer', 'attr_accessor', 'attr', 'catch', 'throw', 'private', + 'module_function', 'public', 'protected', 'true', 'false', 'nil'), + suffix=r'\b'), Keyword.Pseudo), (r'(not|and|or)\b', Operator.Word), - (r'(autoload|block_given|const_defined|eql|equal|frozen|include|' - r'instance_of|is_a|iterator|kind_of|method_defined|nil|' - r'private_method_defined|protected_method_defined|' - r'public_method_defined|respond_to|tainted)\?', Name.Builtin), + (words(( + 'autoload', 'block_given', 'const_defined', 'eql', 'equal', 'frozen', 'include', + 'instance_of', 'is_a', 'iterator', 'kind_of', 'method_defined', 'nil', + 'private_method_defined', 'protected_method_defined', + 'public_method_defined', 'respond_to', 'tainted'), suffix=r'\?'), + Name.Builtin), (r'(chomp|chop|exit|gsub|sub)!', Name.Builtin), - (r'(?<!\.)(Array|Float|Integer|String|__id__|__send__|abort|' - r'ancestors|at_exit|autoload|binding|callcc|caller|' - r'catch|chomp|chop|class_eval|class_variables|' - r'clone|const_defined\?|const_get|const_missing|const_set|' - r'constants|display|dup|eval|exec|exit|extend|fail|fork|' - r'format|freeze|getc|gets|global_variables|gsub|' - r'hash|id|included_modules|inspect|instance_eval|' - r'instance_method|instance_methods|' - r'instance_variable_get|instance_variable_set|instance_variables|' - r'lambda|load|local_variables|loop|' - r'method|method_missing|methods|module_eval|name|' - r'object_id|open|p|print|printf|private_class_method|' - r'private_instance_methods|' - r'private_methods|proc|protected_instance_methods|' - r'protected_methods|public_class_method|' - r'public_instance_methods|public_methods|' - r'putc|puts|raise|rand|readline|readlines|require|' - r'scan|select|self|send|set_trace_func|singleton_methods|sleep|' - r'split|sprintf|srand|sub|syscall|system|taint|' - r'test|throw|to_a|to_s|trace_var|trap|untaint|untrace_var|' - r'warn)\b', Name.Builtin), + (words(( + 'Array', 'Float', 'Integer', 'String', '__id__', '__send__', 'abort', + 'ancestors', 'at_exit', 'autoload', 'binding', 'callcc', 'caller', + 'catch', 'chomp', 'chop', 'class_eval', 'class_variables', + 'clone', 'const_defined?', 'const_get', 'const_missing', 'const_set', + 'constants', 'display', 'dup', 'eval', 'exec', 'exit', 'extend', 'fail', 'fork', + 'format', 'freeze', 'getc', 'gets', 'global_variables', 'gsub', + 'hash', 'id', 'included_modules', 'inspect', 'instance_eval', + 'instance_method', 'instance_methods', + 'instance_variable_get', 'instance_variable_set', 'instance_variables', + 'lambda', 'load', 'local_variables', 'loop', + 'method', 'method_missing', 'methods', 'module_eval', 'name', + 'object_id', 'open', 'p', 'print', 'printf', 'private_class_method', + 'private_instance_methods', + 'private_methods', 'proc', 'protected_instance_methods', + 'protected_methods', 'public_class_method', + 'public_instance_methods', 'public_methods', + 'putc', 'puts', 'raise', 'rand', 'readline', 'readlines', 'require', + 'scan', 'select', 'self', 'send', 'set_trace_func', 'singleton_methods', 'sleep', + 'split', 'sprintf', 'srand', 'sub', 'syscall', 'system', 'taint', + 'test', 'throw', 'to_a', 'to_s', 'trace_var', 'trap', 'untaint', + 'untrace_var', 'warn'), prefix=r'(?<!\.)', suffix=r'\b'), + Name.Builtin), (r'__(FILE|LINE)__\b', Name.Builtin.Pseudo), # normal heredocs (r'(?<!\w)(<<-?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)', @@ -469,10 +477,12 @@ class FancyLexer(RegexLexer): (r'(self|super|nil|false|true)\b', Name.Constant), (r'[(){};,/?\|:\\]', Punctuation), # names - (r'(Object|Array|Hash|Directory|File|Class|String|Number|' - r'Enumerable|FancyEnumerable|Block|TrueClass|NilClass|' - r'FalseClass|Tuple|Symbol|Stack|Set|FancySpec|Method|Package|' - r'Range)\b', Name.Builtin), + (words(( + 'Object', 'Array', 'Hash', 'Directory', 'File', 'Class', 'String', + 'Number', 'Enumerable', 'FancyEnumerable', 'Block', 'TrueClass', + 'NilClass', 'FalseClass', 'Tuple', 'Symbol', 'Stack', 'Set', + 'FancySpec', 'Method', 'Package', 'Range'), suffix=r'\b'), + Name.Builtin), # functions (r'[a-zA-Z](\w|[-+?!=*/^><%])*:', Name.Function), # operators, must be below functions diff --git a/pygments/lexers/scripting.py b/pygments/lexers/scripting.py index d5ec2405..2d8a58a4 100644 --- a/pygments/lexers/scripting.py +++ b/pygments/lexers/scripting.py @@ -11,7 +11,8 @@ import re -from pygments.lexer import RegexLexer, include, bygroups, default, combined +from pygments.lexer import RegexLexer, include, bygroups, default, combined, \ + words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation from pygments.util import get_bool_opt, get_list_opt, iteritems @@ -174,9 +175,12 @@ class MoonScriptLexer(LuaLexer): (r'[;,]', Punctuation), (r'[\[\]\{\}\(\)]', Keyword.Type), (r'[a-zA-Z_]\w*:', Name.Variable), - (r"(class|extends|if|then|super|do|with|import|export|" - r"while|elseif|return|for|in|from|when|using|else|" - r"and|or|not|switch|break)\b", Keyword), + (words(( + 'class', 'extends', 'if', 'then', 'super', 'do', 'with', + 'import', 'export', 'while', 'elseif', 'return', 'for', 'in', + 'from', 'when', 'using', 'else', 'and', 'or', 'not', 'switch', + 'break'), suffix=r'\b'), + Keyword), (r'(true|false|nil)\b', Keyword.Constant), (r'(and|or|not)\b', Operator.Word), (r'(self)\b', Name.Builtin.Pseudo), |