pygments.rb 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/README.md +2 -0
  2. data/lexers +0 -0
  3. data/lib/pygments/version.rb +1 -1
  4. data/test/test_pygments.rb +1 -1
  5. data/vendor/custom_lexers/github.py +15 -9
  6. data/vendor/pygments-main/AUTHORS +12 -2
  7. data/vendor/pygments-main/CHANGES +52 -2
  8. data/vendor/pygments-main/REVISION +1 -1
  9. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +52 -0
  10. data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +67 -44
  11. data/vendor/pygments-main/pygmentize +1 -1
  12. data/vendor/pygments-main/pygments/filters/__init__.py +2 -2
  13. data/vendor/pygments-main/pygments/formatter.py +3 -0
  14. data/vendor/pygments-main/pygments/lexers/__init__.py +11 -0
  15. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +2880 -3124
  16. data/vendor/pygments-main/pygments/lexers/_mapping.py +30 -20
  17. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +1 -1
  18. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +206 -20
  19. data/vendor/pygments-main/pygments/lexers/agile.py +378 -5
  20. data/vendor/pygments-main/pygments/lexers/asm.py +2 -2
  21. data/vendor/pygments-main/pygments/lexers/compiled.py +235 -8
  22. data/vendor/pygments-main/pygments/lexers/dotnet.py +88 -47
  23. data/vendor/pygments-main/pygments/lexers/functional.py +195 -62
  24. data/vendor/pygments-main/pygments/lexers/github.py +15 -9
  25. data/vendor/pygments-main/pygments/lexers/jvm.py +14 -11
  26. data/vendor/pygments-main/pygments/lexers/math.py +284 -18
  27. data/vendor/pygments-main/pygments/lexers/other.py +132 -21
  28. data/vendor/pygments-main/pygments/lexers/shell.py +29 -15
  29. data/vendor/pygments-main/pygments/lexers/sql.py +1 -1
  30. data/vendor/pygments-main/pygments/lexers/templates.py +8 -8
  31. data/vendor/pygments-main/pygments/lexers/text.py +59 -9
  32. data/vendor/pygments-main/pygments/lexers/web.py +832 -210
  33. data/vendor/pygments-main/pygments/modeline.py +40 -0
  34. data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
  35. data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
  36. data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
  37. data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
  38. data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
  39. data/vendor/pygments-main/tests/examplefiles/example.ceylon +29 -10
  40. data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
  41. data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
  42. data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
  43. data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
  44. data/vendor/pygments-main/tests/examplefiles/example.stan +86 -75
  45. data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +40 -30
  46. data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
  47. data/vendor/pygments-main/tests/examplefiles/objc_example.m +7 -0
  48. data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
  49. data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
  50. data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
  51. data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
  52. data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
  53. data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
  54. data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
  55. data/vendor/pygments-main/tests/examplefiles/type.lisp +16 -0
  56. data/vendor/pygments-main/tests/test_basic_api.py +3 -3
  57. data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
  58. metadata +21 -2
@@ -12,7 +12,7 @@
12
12
  import re
13
13
 
14
14
  from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, \
15
- LexerContext, include, combined, do_insertions, bygroups, using
15
+ LexerContext, include, combined, do_insertions, bygroups, using, this
16
16
  from pygments.token import Error, Text, Other, \
17
17
  Comment, Operator, Keyword, Name, String, Number, Generic, Punctuation
18
18
  from pygments.util import get_bool_opt, get_list_opt, shebang_matches
@@ -23,7 +23,7 @@ __all__ = ['PythonLexer', 'PythonConsoleLexer', 'PythonTracebackLexer',
23
23
  'Python3Lexer', 'Python3TracebackLexer', 'RubyLexer',
24
24
  'RubyConsoleLexer', 'PerlLexer', 'LuaLexer', 'MoonScriptLexer',
25
25
  'CrocLexer', 'MiniDLexer', 'IoLexer', 'TclLexer', 'FactorLexer',
26
- 'FancyLexer', 'DgLexer']
26
+ 'FancyLexer', 'DgLexer', 'Perl6Lexer']
27
27
 
28
28
  # b/w compatibility
29
29
  from pygments.lexers.functional import SchemeLexer
@@ -185,7 +185,8 @@ class PythonLexer(RegexLexer):
185
185
  }
186
186
 
187
187
  def analyse_text(text):
188
- return shebang_matches(text, r'pythonw?(2(\.\d)?)?')
188
+ return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \
189
+ 'import ' in text[:1000]
189
190
 
190
191
 
191
192
  class Python3Lexer(RegexLexer):
@@ -234,7 +235,14 @@ class Python3Lexer(RegexLexer):
234
235
  r'TypeError|UnboundLocalError|UnicodeDecodeError|'
235
236
  r'UnicodeEncodeError|UnicodeError|UnicodeTranslateError|'
236
237
  r'UnicodeWarning|UserWarning|ValueError|VMSError|Warning|'
237
- r'WindowsError|ZeroDivisionError)\b', Name.Exception),
238
+ r'WindowsError|ZeroDivisionError|'
239
+ # new builtin exceptions from PEP 3151
240
+ r'BlockingIOError|ChildProcessError|ConnectionError|'
241
+ r'BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|'
242
+ r'ConnectionResetError|FileExistsError|FileNotFoundError|'
243
+ r'InterruptedError|IsADirectoryError|NotADirectoryError|'
244
+ r'PermissionError|ProcessLookupError|TimeoutError)\b',
245
+ Name.Exception),
238
246
  ]
239
247
  tokens['numbers'] = [
240
248
  (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
@@ -421,10 +429,13 @@ class Python3TracebackLexer(RegexLexer):
421
429
  r'exception occurred:\n\n', Generic.Traceback),
422
430
  (r'^The above exception was the direct cause of the '
423
431
  r'following exception:\n\n', Generic.Traceback),
432
+ (r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
424
433
  ],
425
434
  'intb': [
426
435
  (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
427
436
  bygroups(Text, Name.Builtin, Text, Number, Text, Name, Text)),
437
+ (r'^( File )("[^"]+")(, line )(\d+)(\n)',
438
+ bygroups(Text, Name.Builtin, Text, Number, Text)),
428
439
  (r'^( )(.+)(\n)',
429
440
  bygroups(Text, using(Python3Lexer), Text)),
430
441
  (r'^([ \t]*)(\.\.\.)(\n)',
@@ -521,7 +532,7 @@ class RubyLexer(ExtendedRegexLexer):
521
532
  (r":'(\\\\|\\'|[^'])*'", String.Symbol),
522
533
  (r"'(\\\\|\\'|[^'])*'", String.Single),
523
534
  (r':"', String.Symbol, 'simple-sym'),
524
- (r'([a-zA-Z_][a-zA-Z0-9]*)(:)',
535
+ (r'([a-zA-Z_][a-zA-Z0-9]*)(:)(?!:)',
525
536
  bygroups(String.Symbol, Punctuation)), # Since Ruby 1.9
526
537
  (r'"', String.Double, 'simple-string'),
527
538
  (r'(?<!\.)`', String.Backtick, 'simple-backtick'),
@@ -1915,3 +1926,365 @@ class DgLexer(RegexLexer):
1915
1926
  (r"'''", String, '#pop')
1916
1927
  ],
1917
1928
  }
1929
+
1930
+ class Perl6Lexer(ExtendedRegexLexer):
1931
+ """
1932
+ For `Perl 6 <http://www.perl6.org>`_ source code.
1933
+
1934
+ *New in Pygments 1.7.*
1935
+ """
1936
+
1937
+ name = 'Perl6'
1938
+ aliases = ['perl6', 'pl6']
1939
+ filenames = ['*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6',
1940
+ '*.6pm', '*.p6m', '*.pm6']
1941
+ mimetypes = ['text/x-perl6', 'application/x-perl6']
1942
+ flags = re.MULTILINE | re.DOTALL | re.UNICODE
1943
+
1944
+ PERL6_IDENTIFIER_RANGE = "['a-zA-Z0-9_:-]"
1945
+
1946
+ PERL6_KEYWORDS = (
1947
+ 'BEGIN', 'CATCH', 'CHECK', 'CONTROL', 'END', 'ENTER', 'FIRST', 'INIT',
1948
+ 'KEEP', 'LAST', 'LEAVE', 'NEXT', 'POST', 'PRE', 'START', 'TEMP',
1949
+ 'UNDO', 'as', 'assoc', 'async', 'augment', 'binary', 'break', 'but',
1950
+ 'cached', 'category', 'class', 'constant', 'contend', 'continue',
1951
+ 'copy', 'deep', 'default', 'defequiv', 'defer', 'die', 'do', 'else',
1952
+ 'elsif', 'enum', 'equiv', 'exit', 'export', 'fail', 'fatal', 'for',
1953
+ 'gather', 'given', 'goto', 'grammar', 'handles', 'has', 'if', 'inline',
1954
+ 'irs', 'is', 'last', 'leave', 'let', 'lift', 'loop', 'looser', 'macro',
1955
+ 'make', 'maybe', 'method', 'module', 'multi', 'my', 'next', 'of',
1956
+ 'ofs', 'only', 'oo', 'ors', 'our', 'package', 'parsed', 'prec',
1957
+ 'proto', 'readonly', 'redo', 'ref', 'regex', 'reparsed', 'repeat',
1958
+ 'require', 'required', 'return', 'returns', 'role', 'rule', 'rw',
1959
+ 'self', 'slang', 'state', 'sub', 'submethod', 'subset', 'supersede',
1960
+ 'take', 'temp', 'tighter', 'token', 'trusts', 'try', 'unary',
1961
+ 'unless', 'until', 'use', 'warn', 'when', 'where', 'while', 'will',
1962
+ )
1963
+
1964
+ PERL6_BUILTINS = (
1965
+ 'ACCEPTS', 'HOW', 'REJECTS', 'VAR', 'WHAT', 'WHENCE', 'WHERE', 'WHICH',
1966
+ 'WHO', 'abs', 'acos', 'acosec', 'acosech', 'acosh', 'acotan', 'acotanh',
1967
+ 'all', 'any', 'approx', 'arity', 'asec', 'asech', 'asin', 'asinh'
1968
+ 'assuming', 'atan', 'atan2', 'atanh', 'attr', 'bless', 'body', 'by'
1969
+ 'bytes', 'caller', 'callsame', 'callwith', 'can', 'capitalize', 'cat',
1970
+ 'ceiling', 'chars', 'chmod', 'chomp', 'chop', 'chr', 'chroot',
1971
+ 'circumfix', 'cis', 'classify', 'clone', 'close', 'cmp_ok', 'codes',
1972
+ 'comb', 'connect', 'contains', 'context', 'cos', 'cosec', 'cosech',
1973
+ 'cosh', 'cotan', 'cotanh', 'count', 'defined', 'delete', 'diag',
1974
+ 'dies_ok', 'does', 'e', 'each', 'eager', 'elems', 'end', 'eof', 'eval',
1975
+ 'eval_dies_ok', 'eval_elsewhere', 'eval_lives_ok', 'evalfile', 'exists',
1976
+ 'exp', 'first', 'flip', 'floor', 'flunk', 'flush', 'fmt', 'force_todo',
1977
+ 'fork', 'from', 'getc', 'gethost', 'getlogin', 'getpeername', 'getpw',
1978
+ 'gmtime', 'graphs', 'grep', 'hints', 'hyper', 'im', 'index', 'infix',
1979
+ 'invert', 'is_approx', 'is_deeply', 'isa', 'isa_ok', 'isnt', 'iterator',
1980
+ 'join', 'key', 'keys', 'kill', 'kv', 'lastcall', 'lazy', 'lc', 'lcfirst',
1981
+ 'like', 'lines', 'link', 'lives_ok', 'localtime', 'log', 'log10', 'map',
1982
+ 'max', 'min', 'minmax', 'name', 'new', 'nextsame', 'nextwith', 'nfc',
1983
+ 'nfd', 'nfkc', 'nfkd', 'nok_error', 'nonce', 'none', 'normalize', 'not',
1984
+ 'nothing', 'ok', 'once', 'one', 'open', 'opendir', 'operator', 'ord',
1985
+ 'p5chomp', 'p5chop', 'pack', 'pair', 'pairs', 'pass', 'perl', 'pi',
1986
+ 'pick', 'plan', 'plan_ok', 'polar', 'pop', 'pos', 'postcircumfix',
1987
+ 'postfix', 'pred', 'prefix', 'print', 'printf', 'push', 'quasi',
1988
+ 'quotemeta', 'rand', 're', 'read', 'readdir', 'readline', 'reduce',
1989
+ 'reverse', 'rewind', 'rewinddir', 'rindex', 'roots', 'round',
1990
+ 'roundrobin', 'run', 'runinstead', 'sameaccent', 'samecase', 'say',
1991
+ 'sec', 'sech', 'sech', 'seek', 'shape', 'shift', 'sign', 'signature',
1992
+ 'sin', 'sinh', 'skip', 'skip_rest', 'sleep', 'slurp', 'sort', 'splice',
1993
+ 'split', 'sprintf', 'sqrt', 'srand', 'strand', 'subst', 'substr', 'succ',
1994
+ 'sum', 'symlink', 'tan', 'tanh', 'throws_ok', 'time', 'times', 'to',
1995
+ 'todo', 'trim', 'trim_end', 'trim_start', 'true', 'truncate', 'uc',
1996
+ 'ucfirst', 'undef', 'undefine', 'uniq', 'unlike', 'unlink', 'unpack',
1997
+ 'unpolar', 'unshift', 'unwrap', 'use_ok', 'value', 'values', 'vec',
1998
+ 'version_lt', 'void', 'wait', 'want', 'wrap', 'write', 'zip',
1999
+ )
2000
+
2001
+ PERL6_BUILTIN_CLASSES = (
2002
+ 'Abstraction', 'Any', 'AnyChar', 'Array', 'Associative', 'Bag', 'Bit',
2003
+ 'Blob', 'Block', 'Bool', 'Buf', 'Byte', 'Callable', 'Capture', 'Char', 'Class',
2004
+ 'Code', 'Codepoint', 'Comparator', 'Complex', 'Decreasing', 'Exception',
2005
+ 'Failure', 'False', 'Grammar', 'Grapheme', 'Hash', 'IO', 'Increasing',
2006
+ 'Int', 'Junction', 'KeyBag', 'KeyExtractor', 'KeyHash', 'KeySet',
2007
+ 'KitchenSink', 'List', 'Macro', 'Mapping', 'Match', 'Matcher', 'Method',
2008
+ 'Module', 'Num', 'Object', 'Ordered', 'Ordering', 'OrderingPair',
2009
+ 'Package', 'Pair', 'Positional', 'Proxy', 'Range', 'Rat', 'Regex',
2010
+ 'Role', 'Routine', 'Scalar', 'Seq', 'Set', 'Signature', 'Str', 'StrLen',
2011
+ 'StrPos', 'Sub', 'Submethod', 'True', 'UInt', 'Undef', 'Version', 'Void',
2012
+ 'Whatever', 'bit', 'bool', 'buf', 'buf1', 'buf16', 'buf2', 'buf32',
2013
+ 'buf4', 'buf64', 'buf8', 'complex', 'int', 'int1', 'int16', 'int2',
2014
+ 'int32', 'int4', 'int64', 'int8', 'num', 'rat', 'rat1', 'rat16', 'rat2',
2015
+ 'rat32', 'rat4', 'rat64', 'rat8', 'uint', 'uint1', 'uint16', 'uint2',
2016
+ 'uint32', 'uint4', 'uint64', 'uint8', 'utf16', 'utf32', 'utf8',
2017
+ )
2018
+
2019
+ PERL6_OPERATORS = (
2020
+ 'X', 'Z', 'after', 'also', 'and', 'andthen', 'before', 'cmp', 'div',
2021
+ 'eq', 'eqv', 'extra', 'ff', 'fff', 'ge', 'gt', 'le', 'leg', 'lt', 'm',
2022
+ 'mm', 'mod', 'ne', 'or', 'orelse', 'rx', 's', 'tr', 'x', 'xor', 'xx',
2023
+ '++', '--', '**', '!', '+', '-', '~', '?', '|', '||', '+^', '~^', '?^',
2024
+ '^', '*', '/', '%', '%%', '+&', '+<', '+>', '~&', '~<', '~>', '?&',
2025
+ 'gcd', 'lcm', '+', '-', '+|', '+^', '~|', '~^', '?|', '?^',
2026
+ '~', '&', '^', 'but', 'does', '<=>', '..', '..^', '^..', '^..^',
2027
+ '!=', '==', '<', '<=', '>', '>=', '~~', '===', '!eqv',
2028
+ '&&', '||', '^^', '//', 'min', 'max', '??', '!!', 'ff', 'fff', 'so',
2029
+ 'not', '<==', '==>', '<<==', '==>>',
2030
+ )
2031
+
2032
+ # Perl 6 has a *lot* of possible bracketing characters
2033
+ # this list was lifted from STD.pm6 (https://github.com/perl6/std)
2034
+ PERL6_BRACKETS = {
2035
+ u'\u0028' : u'\u0029', u'\u003c' : u'\u003e', u'\u005b' : u'\u005d', u'\u007b' : u'\u007d',
2036
+ u'\u00ab' : u'\u00bb', u'\u0f3a' : u'\u0f3b', u'\u0f3c' : u'\u0f3d', u'\u169b' : u'\u169c',
2037
+ u'\u2018' : u'\u2019', u'\u201a' : u'\u2019', u'\u201b' : u'\u2019', u'\u201c' : u'\u201d',
2038
+ u'\u201e' : u'\u201d', u'\u201f' : u'\u201d', u'\u2039' : u'\u203a', u'\u2045' : u'\u2046',
2039
+ u'\u207d' : u'\u207e', u'\u208d' : u'\u208e', u'\u2208' : u'\u220b', u'\u2209' : u'\u220c',
2040
+ u'\u220a' : u'\u220d', u'\u2215' : u'\u29f5', u'\u223c' : u'\u223d', u'\u2243' : u'\u22cd',
2041
+ u'\u2252' : u'\u2253', u'\u2254' : u'\u2255', u'\u2264' : u'\u2265', u'\u2266' : u'\u2267',
2042
+ u'\u2268' : u'\u2269', u'\u226a' : u'\u226b', u'\u226e' : u'\u226f', u'\u2270' : u'\u2271',
2043
+ u'\u2272' : u'\u2273', u'\u2274' : u'\u2275', u'\u2276' : u'\u2277', u'\u2278' : u'\u2279',
2044
+ u'\u227a' : u'\u227b', u'\u227c' : u'\u227d', u'\u227e' : u'\u227f', u'\u2280' : u'\u2281',
2045
+ u'\u2282' : u'\u2283', u'\u2284' : u'\u2285', u'\u2286' : u'\u2287', u'\u2288' : u'\u2289',
2046
+ u'\u228a' : u'\u228b', u'\u228f' : u'\u2290', u'\u2291' : u'\u2292', u'\u2298' : u'\u29b8',
2047
+ u'\u22a2' : u'\u22a3', u'\u22a6' : u'\u2ade', u'\u22a8' : u'\u2ae4', u'\u22a9' : u'\u2ae3',
2048
+ u'\u22ab' : u'\u2ae5', u'\u22b0' : u'\u22b1', u'\u22b2' : u'\u22b3', u'\u22b4' : u'\u22b5',
2049
+ u'\u22b6' : u'\u22b7', u'\u22c9' : u'\u22ca', u'\u22cb' : u'\u22cc', u'\u22d0' : u'\u22d1',
2050
+ u'\u22d6' : u'\u22d7', u'\u22d8' : u'\u22d9', u'\u22da' : u'\u22db', u'\u22dc' : u'\u22dd',
2051
+ u'\u22de' : u'\u22df', u'\u22e0' : u'\u22e1', u'\u22e2' : u'\u22e3', u'\u22e4' : u'\u22e5',
2052
+ u'\u22e6' : u'\u22e7', u'\u22e8' : u'\u22e9', u'\u22ea' : u'\u22eb', u'\u22ec' : u'\u22ed',
2053
+ u'\u22f0' : u'\u22f1', u'\u22f2' : u'\u22fa', u'\u22f3' : u'\u22fb', u'\u22f4' : u'\u22fc',
2054
+ u'\u22f6' : u'\u22fd', u'\u22f7' : u'\u22fe', u'\u2308' : u'\u2309', u'\u230a' : u'\u230b',
2055
+ u'\u2329' : u'\u232a', u'\u23b4' : u'\u23b5', u'\u2768' : u'\u2769', u'\u276a' : u'\u276b',
2056
+ u'\u276c' : u'\u276d', u'\u276e' : u'\u276f', u'\u2770' : u'\u2771', u'\u2772' : u'\u2773',
2057
+ u'\u2774' : u'\u2775', u'\u27c3' : u'\u27c4', u'\u27c5' : u'\u27c6', u'\u27d5' : u'\u27d6',
2058
+ u'\u27dd' : u'\u27de', u'\u27e2' : u'\u27e3', u'\u27e4' : u'\u27e5', u'\u27e6' : u'\u27e7',
2059
+ u'\u27e8' : u'\u27e9', u'\u27ea' : u'\u27eb', u'\u2983' : u'\u2984', u'\u2985' : u'\u2986',
2060
+ u'\u2987' : u'\u2988', u'\u2989' : u'\u298a', u'\u298b' : u'\u298c', u'\u298d' : u'\u298e',
2061
+ u'\u298f' : u'\u2990', u'\u2991' : u'\u2992', u'\u2993' : u'\u2994', u'\u2995' : u'\u2996',
2062
+ u'\u2997' : u'\u2998', u'\u29c0' : u'\u29c1', u'\u29c4' : u'\u29c5', u'\u29cf' : u'\u29d0',
2063
+ u'\u29d1' : u'\u29d2', u'\u29d4' : u'\u29d5', u'\u29d8' : u'\u29d9', u'\u29da' : u'\u29db',
2064
+ u'\u29f8' : u'\u29f9', u'\u29fc' : u'\u29fd', u'\u2a2b' : u'\u2a2c', u'\u2a2d' : u'\u2a2e',
2065
+ u'\u2a34' : u'\u2a35', u'\u2a3c' : u'\u2a3d', u'\u2a64' : u'\u2a65', u'\u2a79' : u'\u2a7a',
2066
+ u'\u2a7d' : u'\u2a7e', u'\u2a7f' : u'\u2a80', u'\u2a81' : u'\u2a82', u'\u2a83' : u'\u2a84',
2067
+ u'\u2a8b' : u'\u2a8c', u'\u2a91' : u'\u2a92', u'\u2a93' : u'\u2a94', u'\u2a95' : u'\u2a96',
2068
+ u'\u2a97' : u'\u2a98', u'\u2a99' : u'\u2a9a', u'\u2a9b' : u'\u2a9c', u'\u2aa1' : u'\u2aa2',
2069
+ u'\u2aa6' : u'\u2aa7', u'\u2aa8' : u'\u2aa9', u'\u2aaa' : u'\u2aab', u'\u2aac' : u'\u2aad',
2070
+ u'\u2aaf' : u'\u2ab0', u'\u2ab3' : u'\u2ab4', u'\u2abb' : u'\u2abc', u'\u2abd' : u'\u2abe',
2071
+ u'\u2abf' : u'\u2ac0', u'\u2ac1' : u'\u2ac2', u'\u2ac3' : u'\u2ac4', u'\u2ac5' : u'\u2ac6',
2072
+ u'\u2acd' : u'\u2ace', u'\u2acf' : u'\u2ad0', u'\u2ad1' : u'\u2ad2', u'\u2ad3' : u'\u2ad4',
2073
+ u'\u2ad5' : u'\u2ad6', u'\u2aec' : u'\u2aed', u'\u2af7' : u'\u2af8', u'\u2af9' : u'\u2afa',
2074
+ u'\u2e02' : u'\u2e03', u'\u2e04' : u'\u2e05', u'\u2e09' : u'\u2e0a', u'\u2e0c' : u'\u2e0d',
2075
+ u'\u2e1c' : u'\u2e1d', u'\u2e20' : u'\u2e21', u'\u3008' : u'\u3009', u'\u300a' : u'\u300b',
2076
+ u'\u300c' : u'\u300d', u'\u300e' : u'\u300f', u'\u3010' : u'\u3011', u'\u3014' : u'\u3015',
2077
+ u'\u3016' : u'\u3017', u'\u3018' : u'\u3019', u'\u301a' : u'\u301b', u'\u301d' : u'\u301e',
2078
+ u'\ufd3e' : u'\ufd3f', u'\ufe17' : u'\ufe18', u'\ufe35' : u'\ufe36', u'\ufe37' : u'\ufe38',
2079
+ u'\ufe39' : u'\ufe3a', u'\ufe3b' : u'\ufe3c', u'\ufe3d' : u'\ufe3e', u'\ufe3f' : u'\ufe40',
2080
+ u'\ufe41' : u'\ufe42', u'\ufe43' : u'\ufe44', u'\ufe47' : u'\ufe48', u'\ufe59' : u'\ufe5a',
2081
+ u'\ufe5b' : u'\ufe5c', u'\ufe5d' : u'\ufe5e', u'\uff08' : u'\uff09', u'\uff1c' : u'\uff1e',
2082
+ u'\uff3b' : u'\uff3d', u'\uff5b' : u'\uff5d', u'\uff5f' : u'\uff60', u'\uff62' : u'\uff63',
2083
+ }
2084
+
2085
+ def _build_word_match(words, boundary_regex_fragment = None, prefix = '', suffix = ''):
2086
+ if boundary_regex_fragment is None:
2087
+ return r'\b(' + prefix + r'|'.join([ re.escape(x) for x in words]) + suffix + r')\b'
2088
+ else:
2089
+ return r'(?<!' + boundary_regex_fragment + ')' + prefix + '(' + \
2090
+ r'|'.join([ re.escape(x) for x in words]) + r')' + suffix + '(?!' + boundary_regex_fragment + ')'
2091
+
2092
+ def brackets_callback(token_class):
2093
+ def callback(lexer, match, context):
2094
+ groups = match.groupdict()
2095
+ opening_chars = groups['delimiter']
2096
+ n_chars = len(opening_chars)
2097
+ adverbs = groups.get('adverbs')
2098
+
2099
+ closer = Perl6Lexer.PERL6_BRACKETS.get(opening_chars[0])
2100
+ text = context.text
2101
+
2102
+ if closer is None: # it's not a mirrored character, which means we
2103
+ # just need to look for the next occurrence
2104
+
2105
+ end_pos = text.find(opening_chars, match.start('delimiter') + n_chars)
2106
+ else: # we need to look for the corresponding closing character,
2107
+ # keep nesting in mind
2108
+ closing_chars = closer * n_chars
2109
+ nesting_level = 1
2110
+
2111
+ search_pos = match.start('delimiter')
2112
+
2113
+ while nesting_level > 0:
2114
+ next_open_pos = text.find(opening_chars, search_pos + n_chars)
2115
+ next_close_pos = text.find(closing_chars, search_pos + n_chars)
2116
+
2117
+ if next_close_pos == -1:
2118
+ next_close_pos = len(text)
2119
+ nesting_level = 0
2120
+ elif next_open_pos != -1 and next_open_pos < next_close_pos:
2121
+ nesting_level += 1
2122
+ search_pos = next_open_pos
2123
+ else: # next_close_pos < next_open_pos
2124
+ nesting_level -= 1
2125
+ search_pos = next_close_pos
2126
+
2127
+ end_pos = next_close_pos
2128
+
2129
+ if adverbs is not None and re.search(r':to\b', adverbs):
2130
+ heredoc_terminator = text[match.start('delimiter') + n_chars : end_pos]
2131
+ end_heredoc = re.search(r'^\s*' + re.escape(heredoc_terminator) + r'\s*$', text[ match.end('delimiter') : ], re.MULTILINE)
2132
+
2133
+ if end_heredoc:
2134
+ end_pos = match.end('delimiter') + end_heredoc.end()
2135
+ else:
2136
+ end_pos = len(text)
2137
+
2138
+ yield match.start(), token_class, text[match.start() : end_pos + n_chars]
2139
+ context.pos = end_pos + n_chars
2140
+
2141
+ return callback
2142
+
2143
+ def opening_brace_callback(lexer, match, context):
2144
+ stack = context.stack
2145
+
2146
+ yield match.start(), Text, context.text[match.start() : match.end()]
2147
+ context.pos = match.end()
2148
+
2149
+ # if we encounter an opening brace and we're one level
2150
+ # below a token state, it means we need to increment
2151
+ # the nesting level for braces so we know later when
2152
+ # we should return to the token rules.
2153
+ if len(stack) > 2 and stack[-2] == 'token':
2154
+ context.perl6_token_nesting_level += 1
2155
+
2156
+ def closing_brace_callback(lexer, match, context):
2157
+ stack = context.stack
2158
+
2159
+ yield match.start(), Text, context.text[match.start() : match.end()]
2160
+ context.pos = match.end()
2161
+
2162
+ # if we encounter a free closing brace and we're one level
2163
+ # below a token state, it means we need to check the nesting
2164
+ # level to see if we need to return to the token state.
2165
+ if len(stack) > 2 and stack[-2] == 'token':
2166
+ context.perl6_token_nesting_level -= 1
2167
+ if context.perl6_token_nesting_level == 0:
2168
+ stack.pop()
2169
+
2170
+ def embedded_perl6_callback(lexer, match, context):
2171
+ context.perl6_token_nesting_level = 1
2172
+ yield match.start(), Text, context.text[match.start() : match.end()]
2173
+ context.pos = match.end()
2174
+ context.stack.append('root')
2175
+
2176
+ # If you're modifying these rules, be careful if you need to process '{' or '}' characters.
2177
+ # We have special logic for processing these characters (due to the fact that you can nest
2178
+ # Perl 6 code in regex blocks), so if you need to process one of them, make sure you also
2179
+ # process the corresponding one!
2180
+ tokens = {
2181
+ 'common' : [
2182
+ (r'#[`|=](?P<delimiter>(?P<first_char>[' + ''.join(PERL6_BRACKETS.keys()) + r'])(?P=first_char)*)', brackets_callback(Comment.Multiline)),
2183
+ (r'#[^\n]*$', Comment.Singleline),
2184
+ (r'^(\s*)=begin\s+(\w+)\b.*?^\1=end\s+\2', Comment.Multiline),
2185
+ (r'^(\s*)=for.*?\n\s*?\n', Comment.Multiline),
2186
+ (r'^=.*?\n\s*?\n', Comment.Multiline),
2187
+ (r'(regex|token|rule)(\s*' + PERL6_IDENTIFIER_RANGE + '+:sym)', bygroups(Keyword, Name), 'token-sym-brackets'),
2188
+ (r'(regex|token|rule)(?!' + PERL6_IDENTIFIER_RANGE + ')(\s*' + PERL6_IDENTIFIER_RANGE + '+)?', bygroups(Keyword, Name), 'pre-token'),
2189
+ # deal with a special case in the Perl 6 grammar (role q { ... })
2190
+ (r'(role)(\s+)(q)(\s*)', bygroups(Keyword, Text, Name, Text)),
2191
+ (_build_word_match(PERL6_KEYWORDS, PERL6_IDENTIFIER_RANGE), Keyword),
2192
+ (_build_word_match(PERL6_BUILTIN_CLASSES, PERL6_IDENTIFIER_RANGE, suffix = '(?::[UD])?'), Name.Builtin),
2193
+ (_build_word_match(PERL6_BUILTINS, PERL6_IDENTIFIER_RANGE), Name.Builtin),
2194
+ # copied from PerlLexer
2195
+ (r'[$@%&][.^:?=!~]?' + PERL6_IDENTIFIER_RANGE + u'+(?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable),
2196
+ (r'\$[!/](?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable.Global),
2197
+ (r'::\?\w+', Name.Variable.Global),
2198
+ (r'[$@%&]\*' + PERL6_IDENTIFIER_RANGE + u'+(?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable.Global),
2199
+ (r'\$(?:<.*?>)+', Name.Variable),
2200
+ (r'(?:q|qq|Q)[a-zA-Z]?\s*(?P<adverbs>:[\w\s:]+)?\s*(?P<delimiter>(?P<first_char>[^0-9a-zA-Z:\s])(?P=first_char)*)', brackets_callback(String)),
2201
+ # copied from PerlLexer
2202
+ (r'0_?[0-7]+(_[0-7]+)*', Number.Oct),
2203
+ (r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex),
2204
+ (r'0b[01]+(_[01]+)*', Number.Bin),
2205
+ (r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?', Number.Float),
2206
+ (r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float),
2207
+ (r'\d+(_\d+)*', Number.Integer),
2208
+ (r'(?<=~~)\s*/(?:\\\\|\\/|.)*?/', String.Regex),
2209
+ (r'(?<=[=(,])\s*/(?:\\\\|\\/|.)*?/', String.Regex),
2210
+ (r'm\w+(?=\()', Name),
2211
+ (r'(?:m|ms|rx)\s*(?P<adverbs>:[\w\s:]+)?\s*(?P<delimiter>(?P<first_char>[^0-9a-zA-Z:\s])(?P=first_char)*)', brackets_callback(String.Regex)),
2212
+ (r'(?:s|ss|tr)\s*(?::[\w\s:]+)?\s*/(?:\\\\|\\/|.)*?/(?:\\\\|\\/|.)*?/', String.Regex),
2213
+ (r'<[^\s=].*?\S>', String),
2214
+ (_build_word_match(PERL6_OPERATORS), Operator),
2215
+ (r'[0-9a-zA-Z_]' + PERL6_IDENTIFIER_RANGE + '*', Name),
2216
+ (r"'(\\\\|\\[^\\]|[^'\\])*'", String),
2217
+ (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
2218
+ ],
2219
+ 'root' : [
2220
+ include('common'),
2221
+ (r'\{', opening_brace_callback),
2222
+ (r'\}', closing_brace_callback),
2223
+ (r'.+?', Text),
2224
+ ],
2225
+ 'pre-token' : [
2226
+ include('common'),
2227
+ (r'\{', Text, ('#pop', 'token')),
2228
+ (r'.+?', Text),
2229
+ ],
2230
+ 'token-sym-brackets' : [
2231
+ (r'(?P<delimiter>(?P<first_char>[' + ''.join(PERL6_BRACKETS.keys()) + '])(?P=first_char)*)', brackets_callback(Name), ('#pop', 'pre-token')),
2232
+ (r'', Name, ('#pop', 'pre-token')),
2233
+ ],
2234
+ 'token': [
2235
+ (r'}', Text, '#pop'),
2236
+ (r'(?<=:)(?:my|our|state|constant|temp|let).*?;', using(this)),
2237
+ # make sure that quotes in character classes aren't treated as strings
2238
+ (r'<(?:[-!?+.]\s*)?\[.*?\]>', String.Regex),
2239
+ # make sure that '#' characters in quotes aren't treated as comments
2240
+ (r"(?<!\\)'(\\\\|\\[^\\]|[^'\\])*'", String.Regex),
2241
+ (r'(?<!\\)"(\\\\|\\[^\\]|[^"\\])*"', String.Regex),
2242
+ (r'#.*?$', Comment.Singleline),
2243
+ (r'\{', embedded_perl6_callback),
2244
+ ('.+?', String.Regex),
2245
+ ],
2246
+ }
2247
+
2248
+ def analyse_text(text):
2249
+ def strip_pod(lines):
2250
+ in_pod = False
2251
+ stripped_lines = []
2252
+
2253
+ for line in lines:
2254
+ if re.match(r'^=(?:end|cut)', line):
2255
+ in_pod = False
2256
+ elif re.match(r'^=\w+', line):
2257
+ in_pod = True
2258
+ elif not in_pod:
2259
+ stripped_lines.append(line)
2260
+
2261
+ return stripped_lines
2262
+
2263
+ lines = text.splitlines()
2264
+ lines = strip_pod(lines)
2265
+ text = '\n'.join(lines)
2266
+
2267
+ if shebang_matches(text, r'perl6|rakudo|niecza'):
2268
+ return True
2269
+
2270
+ if 'use v6' in text:
2271
+ return 0.91 # 0.01 greater than Perl says for 'my $'
2272
+ if re.search(r'[$@%]\*[A-Z]+', text): # Perl 6-style globals ($*OS)
2273
+ return 0.91
2274
+ if re.search(r'[$@%]\?[A-Z]+', text): # Perl 6 compiler variables ($?PACKAGE)
2275
+ return 0.91
2276
+ if re.search(r'[$@%][!.][A-Za-z0-9_-]+', text): # Perl 6 member variables
2277
+ return 0.91
2278
+
2279
+ for line in text.splitlines():
2280
+ if re.match(r'\s*(?:my|our)?\s*module', line): # module declarations
2281
+ return 0.91
2282
+ if re.match(r'\s*(?:my|our)?\s*role', line): # role declarations
2283
+ return 0.91
2284
+ if re.match(r'\s*(?:my|our)?\s*class\b', line): # class declarations
2285
+ return 0.91
2286
+ return False
2287
+
2288
+ def __init__(self, **options):
2289
+ super(Perl6Lexer, self).__init__(**options)
2290
+ self.encoding = options.get('encoding', 'utf-8')
@@ -25,7 +25,7 @@ class GasLexer(RegexLexer):
25
25
  For Gas (AT&T) assembly code.
26
26
  """
27
27
  name = 'GAS'
28
- aliases = ['gas']
28
+ aliases = ['gas', 'asm']
29
29
  filenames = ['*.s', '*.S']
30
30
  mimetypes = ['text/x-gas']
31
31
 
@@ -244,7 +244,7 @@ class LlvmLexer(RegexLexer):
244
244
  r'|align|addrspace|section|alias|module|asm|sideeffect|gc|dbg'
245
245
 
246
246
  r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
247
- r'|arm_aapcscc|arm_aapcs_vfpcc'
247
+ r'|arm_aapcscc|arm_aapcs_vfpcc|ptx_device|ptx_kernel'
248
248
 
249
249
  r'|cc|c'
250
250
 
@@ -23,13 +23,14 @@ from pygments.scanner import Scanner
23
23
  from pygments.lexers.functional import OcamlLexer
24
24
  from pygments.lexers.jvm import JavaLexer, ScalaLexer
25
25
 
26
- __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer',
27
- 'ObjectiveCLexer', 'ObjectiveCppLexer', 'FortranLexer', 'GLShaderLexer',
28
- 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer',
29
- 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
30
- 'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
26
+ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer',
27
+ 'NesCLexer', 'DylanLexer', 'ObjectiveCLexer', 'ObjectiveCppLexer',
28
+ 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer',
29
+ 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer',
30
+ 'Modula2Lexer', 'BlitzMaxLexer', 'BlitzBasicLexer', 'NimrodLexer',
31
+ 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer', 'SwigLexer',
31
32
  'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
32
- 'CobolFreeformatLexer', 'LogosLexer']
33
+ 'CobolFreeformatLexer', 'LogosLexer', 'ClayLexer']
33
34
 
34
35
 
35
36
  class CFamilyLexer(RegexLexer):
@@ -231,6 +232,63 @@ class CppLexer(CFamilyLexer):
231
232
  return 0.1
232
233
 
233
234
 
235
+ class SwigLexer(CppLexer):
236
+ """
237
+ For `SWIG <http://www.swig.org/>`_ source code.
238
+
239
+ *New in Pygments 1.7.*
240
+ """
241
+ name = 'SWIG'
242
+ aliases = ['Swig', 'swig']
243
+ filenames = ['*.swg', '*.i']
244
+ mimetypes = ['text/swig']
245
+ priority = 0.04 # Lower than C/C++ and Objective C/C++
246
+
247
+ tokens = {
248
+ 'statements': [
249
+ (r'(%[a-z_][a-z0-9_]*)', Name.Function), # SWIG directives
250
+ ('\$\**\&?[a-zA-Z0-9_]+', Name), # Special variables
251
+ (r'##*[a-zA-Z_][a-zA-Z0-9_]*', Comment.Preproc), # Stringification / additional preprocessor directives
252
+ inherit,
253
+ ],
254
+ }
255
+
256
+ # This is a far from complete set of SWIG directives
257
+ swig_directives = (
258
+ # Most common directives
259
+ '%apply', '%define', '%director', '%enddef', '%exception', '%extend',
260
+ '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include',
261
+ '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma',
262
+ '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap',
263
+ # Less common directives
264
+ '%arg', '%attribute', '%bang', '%begin', '%callback', '%catches', '%clear',
265
+ '%constant', '%copyctor', '%csconst', '%csconstvalue', '%csenum',
266
+ '%csmethodmodifiers', '%csnothrowexception', '%default', '%defaultctor',
267
+ '%defaultdtor', '%defined', '%delete', '%delobject', '%descriptor',
268
+ '%exceptionclass', '%exceptionvar', '%extend_smart_pointer', '%fragments',
269
+ '%header', '%ifcplusplus', '%ignorewarn', '%implicit', '%implicitconv',
270
+ '%init', '%javaconst', '%javaconstvalue', '%javaenum', '%javaexception',
271
+ '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar',
272
+ '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend',
273
+ '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall',
274
+ '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof',
275
+ '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn', '%warnfilter')
276
+
277
+ def analyse_text(text):
278
+ rv = 0.1 # Same as C/C++
279
+ # Search for SWIG directives, which are conventionally at the beginning of
280
+ # a line. The probability of them being within a line is low, so let another
281
+ # lexer win in this case.
282
+ matches = re.findall(r'^\s*(%[a-z_][a-z0-9_]*)', text, re.M)
283
+ for m in matches:
284
+ if m in SwigLexer.swig_directives:
285
+ rv = 0.98
286
+ break
287
+ else:
288
+ rv = 0.91 # Fraction higher than MatlabLexer
289
+ return rv
290
+
291
+
234
292
  class ECLexer(CLexer):
235
293
  """
236
294
  For eC source code with preprocessor directives.
@@ -266,6 +324,83 @@ class ECLexer(CLexer):
266
324
  }
267
325
 
268
326
 
327
+ class NesCLexer(CLexer):
328
+ """
329
+ For `nesC <https://github.com/tinyos/nesc>`_ source code with preprocessor
330
+ directives.
331
+
332
+ *New in Pygments 1.7.*
333
+ """
334
+ name = 'nesC'
335
+ aliases = ['nesc']
336
+ filenames = ['*.nc']
337
+ mimetypes = ['text/x-nescsrc']
338
+
339
+ tokens = {
340
+ 'statements': [
341
+ (r'(abstract|as|async|atomic|call|command|component|components|'
342
+ r'configuration|event|extends|generic|implementation|includes|'
343
+ r'interface|module|new|norace|post|provides|signal|task|uses)\b',
344
+ Keyword),
345
+ (r'(nx_struct|nx_union|nx_int8_t|nx_int16_t|nx_int32_t|nx_int64_t|'
346
+ r'nx_uint8_t|nx_uint16_t|nx_uint32_t|nx_uint64_t)\b',
347
+ Keyword.Type),
348
+ inherit,
349
+ ],
350
+ }
351
+
352
+
353
+ class ClayLexer(RegexLexer):
354
+ """
355
+ For `Clay <http://claylabs.com/clay/>`_ source.
356
+
357
+ *New in Pygments 1.7.*
358
+ """
359
+ name = 'Clay'
360
+ filenames = ['*.clay']
361
+ aliases = ['clay']
362
+ mimetypes = ['text/x-clay']
363
+ tokens = {
364
+ 'root': [
365
+ (r'\s', Text),
366
+ (r'//.*?$', Comment.Singleline),
367
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
368
+ (r'\b(public|private|import|as|record|variant|instance'
369
+ r'|define|overload|default|external|alias'
370
+ r'|rvalue|ref|forward|inline|noinline|forceinline'
371
+ r'|enum|var|and|or|not|if|else|goto|return|while'
372
+ r'|switch|case|break|continue|for|in|true|false|try|catch|throw'
373
+ r'|finally|onerror|staticassert|eval|when|newtype'
374
+ r'|__FILE__|__LINE__|__COLUMN__|__ARG__'
375
+ r')\b', Keyword),
376
+ (r'[~!%^&*+=|:<>/-]', Operator),
377
+ (r'[#(){}\[\],;.]', Punctuation),
378
+ (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
379
+ (r'\d+[LlUu]*', Number.Integer),
380
+ (r'\b(true|false)\b', Name.Builtin),
381
+ (r'(?i)[a-z_?][a-z_?0-9]*', Name),
382
+ (r'"""', String, 'tdqs'),
383
+ (r'"', String, 'dqs'),
384
+ ],
385
+ 'strings': [
386
+ (r'(?i)\\(x[0-9a-f]{2}|.)', String.Escape),
387
+ (r'.', String),
388
+ ],
389
+ 'nl': [
390
+ (r'\n', String),
391
+ ],
392
+ 'dqs': [
393
+ (r'"', String, '#pop'),
394
+ include('strings'),
395
+ ],
396
+ 'tdqs': [
397
+ (r'"""', String, '#pop'),
398
+ include('strings'),
399
+ include('nl'),
400
+ ],
401
+ }
402
+
403
+
269
404
  class DLexer(RegexLexer):
270
405
  """
271
406
  For D source.
@@ -1216,6 +1351,8 @@ def objective(baselexer):
1216
1351
  ('#pop', 'oc_classname')),
1217
1352
  (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
1218
1353
  ('#pop', 'oc_forward_classname')),
1354
+ # @ can also prefix other expressions like @{...} or @(...)
1355
+ (r'@', Punctuation),
1219
1356
  inherit,
1220
1357
  ],
1221
1358
  'oc_classname' : [
@@ -1471,7 +1608,15 @@ class PrologLexer(RegexLexer):
1471
1608
  (r'^#.*', Comment.Single),
1472
1609
  (r'/\*', Comment.Multiline, 'nested-comment'),
1473
1610
  (r'%.*', Comment.Single),
1474
- (r'[0-9]+', Number),
1611
+ # character literal
1612
+ (r'0\'.', String.Char),
1613
+ (r'0b[01]+', Number.Bin),
1614
+ (r'0o[0-7]+', Number.Oct),
1615
+ (r'0x[0-9a-fA-F]+', Number.Hex),
1616
+ # literal with prepended base
1617
+ (r'\d\d?\'[a-zA-Z0-9]+', Number.Integer),
1618
+ (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
1619
+ (r'\d+', Number.Integer),
1475
1620
  (r'[\[\](){}|.,;!]', Punctuation),
1476
1621
  (r':-|-->', Punctuation),
1477
1622
  (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|'
@@ -1522,7 +1667,7 @@ class CythonLexer(RegexLexer):
1522
1667
  """
1523
1668
 
1524
1669
  name = 'Cython'
1525
- aliases = ['cython', 'pyx']
1670
+ aliases = ['cython', 'pyx', 'pyrex']
1526
1671
  filenames = ['*.pyx', '*.pxd', '*.pxi']
1527
1672
  mimetypes = ['text/x-cython', 'application/x-cython']
1528
1673
 
@@ -2581,6 +2726,88 @@ class BlitzMaxLexer(RegexLexer):
2581
2726
  }
2582
2727
 
2583
2728
 
2729
+ class BlitzBasicLexer(RegexLexer):
2730
+ """
2731
+ For `BlitzBasic <http://blitzbasic.com>`_ source code.
2732
+
2733
+ *New in Pygments 1.7.*
2734
+ """
2735
+
2736
+ name = 'BlitzBasic'
2737
+ aliases = ['blitzbasic', 'b3d', 'bplus']
2738
+ filenames = ['*.bb', '*.decls']
2739
+ mimetypes = ['text/x-bb']
2740
+
2741
+ bb_vopwords = (r'\b(Shl|Shr|Sar|Mod|Or|And|Not|'
2742
+ r'Abs|Sgn|Handle|Int|Float|Str|'
2743
+ r'First|Last|Before|After)\b')
2744
+ bb_sktypes = r'@{1,2}|[#$%]'
2745
+ bb_name = r'[a-z][a-z0-9_]*'
2746
+ bb_var = (r'(%s)(?:([ \t]*)(%s)|([ \t]*)([.])([ \t]*)(?:(%s)))?') % \
2747
+ (bb_name, bb_sktypes, bb_name)
2748
+
2749
+ flags = re.MULTILINE | re.IGNORECASE
2750
+ tokens = {
2751
+ 'root': [
2752
+ # Text
2753
+ (r'[ \t]+', Text),
2754
+ # Comments
2755
+ (r";.*?\n", Comment.Single),
2756
+ # Data types
2757
+ ('"', String.Double, 'string'),
2758
+ # Numbers
2759
+ (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
2760
+ (r'\.[0-9]+(?!\.)', Number.Float),
2761
+ (r'[0-9]+', Number.Integer),
2762
+ (r'\$[0-9a-f]+', Number.Hex),
2763
+ (r'\%[10]+', Number), # Binary
2764
+ # Other
2765
+ (r'(?:%s|([+\-*/~=<>^]))' % (bb_vopwords), Operator),
2766
+ (r'[(),:\[\]\\]', Punctuation),
2767
+ (r'\.([ \t]*)(%s)' % bb_name, Name.Label),
2768
+ # Identifiers
2769
+ (r'\b(New)\b([ \t]+)(%s)' % (bb_name),
2770
+ bygroups(Keyword.Reserved, Text, Name.Class)),
2771
+ (r'\b(Gosub|Goto)\b([ \t]+)(%s)' % (bb_name),
2772
+ bygroups(Keyword.Reserved, Text, Name.Label)),
2773
+ (r'\b(Object)\b([ \t]*)([.])([ \t]*)(%s)\b' % (bb_name),
2774
+ bygroups(Operator, Text, Punctuation, Text, Name.Class)),
2775
+ (r'\b%s\b([ \t]*)(\()' % bb_var,
2776
+ bygroups(Name.Function, Text, Keyword.Type,Text, Punctuation,
2777
+ Text, Name.Class, Text, Punctuation)),
2778
+ (r'\b(Function)\b([ \t]+)%s' % bb_var,
2779
+ bygroups(Keyword.Reserved, Text, Name.Function, Text, Keyword.Type,
2780
+ Text, Punctuation, Text, Name.Class)),
2781
+ (r'\b(Type)([ \t]+)(%s)' % (bb_name),
2782
+ bygroups(Keyword.Reserved, Text, Name.Class)),
2783
+ # Keywords
2784
+ (r'\b(Pi|True|False|Null)\b', Keyword.Constant),
2785
+ (r'\b(Local|Global|Const|Field|Dim)\b', Keyword.Declaration),
2786
+ (r'\b(End|Return|Exit|'
2787
+ r'Chr|Len|Asc|'
2788
+ r'New|Delete|Insert|'
2789
+ r'Include|'
2790
+ r'Function|'
2791
+ r'Type|'
2792
+ r'If|Then|Else|ElseIf|EndIf|'
2793
+ r'For|To|Next|Step|Each|'
2794
+ r'While|Wend|'
2795
+ r'Repeat|Until|Forever|'
2796
+ r'Select|Case|Default|'
2797
+ r'Goto|Gosub|Data|Read|Restore)\b', Keyword.Reserved),
2798
+ # Final resolve (for variable names and such)
2799
+ # (r'(%s)' % (bb_name), Name.Variable),
2800
+ (bb_var, bygroups(Name.Variable, Text, Keyword.Type,
2801
+ Text, Punctuation, Text, Name.Class)),
2802
+ ],
2803
+ 'string': [
2804
+ (r'""', String.Double),
2805
+ (r'"C?', String.Double, '#pop'),
2806
+ (r'[^"]+', String.Double),
2807
+ ],
2808
+ }
2809
+
2810
+
2584
2811
  class NimrodLexer(RegexLexer):
2585
2812
  """
2586
2813
  For `Nimrod <http://nimrod-code.org/>`_ source code.