diff options
author | Marc 'BlackJack' Rintsch <marc@rintsch.de> | 2012-10-08 14:44:21 +0200 |
---|---|---|
committer | Marc 'BlackJack' Rintsch <marc@rintsch.de> | 2012-10-08 14:44:21 +0200 |
commit | 2867cf9479652aebd216e0c081e14bdc9aa4897b (patch) | |
tree | e604989bcd4cefaa987fc290cc1fc643e88de81a /pygments/lexers/compiled.py | |
parent | a3d52a8d57ea219fc56d1bb70eace7e72a56498e (diff) | |
parent | 520215091a7b8e4dad1da581b76d10e1d8faf67c (diff) | |
download | pygments-2867cf9479652aebd216e0c081e14bdc9aa4897b.tar.gz |
Merge main development.
Diffstat (limited to 'pygments/lexers/compiled.py')
-rw-r--r-- | pygments/lexers/compiled.py | 229 |
1 files changed, 195 insertions, 34 deletions
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 04077ec6..450a9c4d 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -27,7 +27,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer', - 'NimrodLexer', 'FantomLexer'] + 'NimrodLexer', 'FantomLexer', 'RustLexer', 'CUDALexer'] class CLexer(RegexLexer): @@ -41,6 +41,8 @@ class CLexer(RegexLexer): #: optional Comment or Whitespace _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + #: only one /* */ style comment + _ws1 = r':\s*/[*].*?[*]/\s*' tokens = { 'whitespace': [ @@ -48,9 +50,9 @@ class CLexer(RegexLexer): ('^#if\s+0', Comment.Preproc, 'if0'), ('^#', Comment.Preproc, 'macro'), # or with whitespace - ('^(' + _ws + r')(#if\s+0)', + ('^(' + _ws1 + r')(#if\s+0)', bygroups(using(this), Comment.Preproc), 'if0'), - ('^(' + _ws + ')(#)', + ('^(' + _ws1 + ')(#)', bygroups(using(this), Comment.Preproc), 'macro'), (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', bygroups(Text, Name.Label)), @@ -89,7 +91,7 @@ class CLexer(RegexLexer): (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')({)', + r'(' + _ws + r')?({)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation), 'function'), @@ -97,7 +99,7 @@ class CLexer(RegexLexer): (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')(;)', + r'(' + _ws + r')?(;)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation)), ('', Text, 'statement'), @@ -179,6 +181,8 @@ class CppLexer(RegexLexer): #: optional Comment or Whitespace _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + #: only one /* */ style comment + _ws1 = r':\s*/[*].*?[*]/\s*' tokens = { 'root': [ @@ -186,9 +190,9 @@ class CppLexer(RegexLexer): ('^#if\s+0', Comment.Preproc, 'if0'), ('^#', Comment.Preproc, 'macro'), # or with whitespace - ('^(' + _ws + r')(#if\s+0)', + ('^(' + _ws1 + r')(#if\s+0)', bygroups(using(this), Comment.Preproc), 'if0'), - ('^(' + _ws + ')(#)', + ('^(' + _ws1 + ')(#)', bygroups(using(this), Comment.Preproc), 'macro'), (r'\n', Text), (r'\s+', Text), @@ -270,6 +274,8 @@ class ECLexer(RegexLexer): #: optional Comment or Whitespace _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + #: only one /* */ style comment + _ws1 = r':\s*/[*].*?[*]/\s*' tokens = { 'whitespace': [ @@ -277,8 +283,8 @@ class ECLexer(RegexLexer): ('^#if\s+0', Comment.Preproc, 'if0'), ('^#', Comment.Preproc, 'macro'), # or with whitespace - ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'), - ('^' + _ws + '#', Comment.Preproc, 'macro'), + ('^' + _ws1 + r'#if\s+0', Comment.Preproc, 'if0'), + ('^' + _ws1 + '#', Comment.Preproc, 'macro'), (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', bygroups(Text, Name.Label)), (r'\n', Text), (r'\s+', Text), @@ -323,7 +329,7 @@ class ECLexer(RegexLexer): (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')({)', + r'(' + _ws + r')?({)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation), 'function'), @@ -331,7 +337,7 @@ class ECLexer(RegexLexer): (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')(;)', + r'(' + _ws + r')?(;)', bygroups(using(this), Name.Function, using(this), using(this), Punctuation)), ('', Text, 'statement'), @@ -1102,12 +1108,14 @@ class ObjectiveCLexer(RegexLexer): name = 'Objective-C' aliases = ['objective-c', 'objectivec', 'obj-c', 'objc'] - #XXX: objc has .h files too :-/ + # XXX: objc has .h files too :-/ filenames = ['*.m'] mimetypes = ['text/x-objective-c'] #: optional Comment or Whitespace _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + #: only one /* */ style comment + _ws1 = r':\s*/[*].*?[*]/\s*' tokens = { 'whitespace': [ @@ -1115,8 +1123,10 @@ class ObjectiveCLexer(RegexLexer): ('^#if\s+0', Comment.Preproc, 'if0'), ('^#', Comment.Preproc, 'macro'), # or with whitespace - ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'), - ('^' + _ws + '#', Comment.Preproc, 'macro'), + ('^(' + _ws1 + r')(#if\s+0)', + bygroups(using(this), Comment.Preproc), 'if0'), + ('^(' + _ws1 + ')(#)', + bygroups(using(this), Comment.Preproc), 'macro'), (r'\n', Text), (r'\s+', Text), (r'\\\n', Text), # line continuation @@ -1139,7 +1149,7 @@ class ObjectiveCLexer(RegexLexer): r'switch|typedef|union|volatile|virtual|while|in|@selector|' r'@private|@protected|@public|@encode|' r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' - r'@synthesize|@dynamic)\b', Keyword), + r'@synthesize|@dynamic|@optional)\b', Keyword), (r'(int|long|float|short|double|char|unsigned|signed|void|' r'id|BOOL|IBOutlet|IBAction|SEL)\b', Keyword.Type), (r'(_{0,2}inline|naked|restrict|thread|typename)\b', @@ -1149,6 +1159,10 @@ class ObjectiveCLexer(RegexLexer): (r'(TRUE|FALSE|nil|NULL)\b', Name.Builtin), ('[a-zA-Z$_][a-zA-Z0-9$_]*:(?!:)', Name.Label), ('[a-zA-Z$_][a-zA-Z0-9$_]*', Name), + (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), + ('#pop', 'classname')), + (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text), + ('#pop', 'forward_classname')), ], 'root': [ include('whitespace'), @@ -1156,7 +1170,7 @@ class ObjectiveCLexer(RegexLexer): (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')({)', + r'(' + _ws + r')?({)', bygroups(using(this), Name.Function, using(this), Text, Punctuation), 'function'), @@ -1171,7 +1185,7 @@ class ObjectiveCLexer(RegexLexer): (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name r'(\s*\([^;]*?\))' # signature - r'(' + _ws + r')(;)', + r'(' + _ws + r')?(;)', bygroups(using(this), Name.Function, using(this), Text, Punctuation)), (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), @@ -1807,19 +1821,34 @@ class GoLexer(RegexLexer): (r'\\\n', Text), # line continuations (r'//(.*?)\n', Comment.Single), (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), - (r'(break|default|func|interface|select' - r'|case|defer|go|map|struct' - r'|chan|else|goto|package|switch' - r'|const|fallthrough|if|range|type' - r'|continue|for|import|return|var)\b', Keyword + (r'(import|package)\b', Keyword.Namespace), + (r'(var|func|struct|map|chan|type|interface|const)\b', Keyword.Declaration), + (r'(break|default|select|case|defer|go' + r'|else|goto|switch|fallthrough|if|range' + r'|continue|for|return)\b', Keyword ), - # It seems the builtin types aren't actually keywords. - (r'(uint8|uint16|uint32|uint64' - r'|int8|int16|int32|int64' - r'|float32|float64|byte' - r'|uint|int|float|uintptr' - r'|string|close|closed|len|cap|new|make)\b', Name.Builtin + (r'(true|false|iota|nil)\b', Keyword.Constant), + # It seems the builtin types aren't actually keywords, but + # can be used as functions. So we need two declarations. + (r'(uint|uint8|uint16|uint32|uint64' + r'|int|int8|int16|int32|int64' + r'|float|float32|float64' + r'|complex64|complex128|byte|rune' + r'|string|bool|error|uintptr' + r'|print|println|panic|recover|close|complex|real|imag' + r'|len|cap|append|copy|delete|new|make)\b(\()', bygroups(Name.Builtin, Punctuation) ), + (r'(uint|uint8|uint16|uint32|uint64' + r'|int|int8|int16|int32|int64' + r'|float|float32|float64' + r'|complex64|complex128|byte|rune' + r'|string|bool|error|uintptr)\b', Keyword.Type + ), + # imaginary_lit + (r'\d+i', Number), + (r'\d+\.\d*([Ee][-+]\d+)?i', Number), + (r'\.\d+([Ee][-+]\d+)?i', Number), + (r'\d+[Ee][-+]\d+i', Number), # float_lit (r'\d+(\.\d+[eE][+\-]?\d+|' r'\.\d*|[eE][+\-]?\d+)', Number.Float), @@ -1843,11 +1872,10 @@ class GoLexer(RegexLexer): (r'"(\\\\|\\"|[^"])*"', String), # Tokens (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|' - r'|<-|\+\+|--|==|!=|:=|\.\.\.)|[+\-*/%&|^<>=!()\[\]{}.,;:]', - Punctuation - ), + r'|<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])', Operator), + (r'[|^<>=!()\[\]{}.,;:]', Punctuation), # identifier - (r'[a-zA-Z_]\w*', Name), + (r'[a-zA-Z_]\w*', Name.Other), ] } @@ -2120,8 +2148,6 @@ class AdaLexer(RegexLexer): flags = re.MULTILINE | re.I # Ignore case - _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' - tokens = { 'root': [ (r'[^\S\n]+', Text), @@ -2889,3 +2915,138 @@ class FantomLexer(RegexLexer): (r'.', Text) ], } + + +class RustLexer(RegexLexer): + """ + Lexer for Mozilla's Rust programming language. + + *New in Pygments 1.6.* + """ + name = 'Rust' + filenames = ['*.rs', '*.rc'] + aliases = ['rust'] + mimetypes = ['text/x-rustsrc'] + + tokens = { + 'root': [ + # Whitespace and Comments + (r'\n', Text), + (r'\s+', Text), + (r'//(.*?)\n', Comment.Single), + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + + # Keywords + (r'(alt|as|assert|be|break|check|claim|class|const' + r'|cont|copy|crust|do|else|enum|export|fail' + r'|false|fn|for|if|iface|impl|import|let|log' + r'|loop|mod|mut|native|pure|resource|ret|true' + r'|type|unsafe|use|white|note|bind|prove|unchecked' + r'|with|syntax|u8|u16|u32|u64|i8|i16|i32|i64|uint' + r'|int|f32|f64)\b', Keyword), + + # Character Literal + (r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""", + String.Char), + # Binary Literal + (r'0[Bb][01_]+', Number, 'number_lit'), + # Octal Literal + (r'0[0-7_]+', Number.Oct, 'number_lit'), + # Hexadecimal Literal + (r'0[xX][0-9a-fA-F_]+', Number.Hex, 'number_lit'), + # Decimal Literal + (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?' + r'[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+)?', Number, 'number_lit'), + # String Literal + (r'"', String, 'string'), + + # Operators and Punctuation + (r'[{}()\[\],.;]', Punctuation), + (r'[+\-*/%&|<>^!~@=:?]', Operator), + + # Identifier + (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), + + # Attributes + (r'#\[', Comment.Preproc, 'attribute['), + (r'#\(', Comment.Preproc, 'attribute('), + # Macros + (r'#[A-Za-z_][A-Za-z0-9_]*\[', Comment.Preproc, 'attribute['), + (r'#[A-Za-z_][A-Za-z0-9_]*\(', Comment.Preproc, 'attribute('), + ], + 'number_lit': [ + (r'(([ui](8|16|32|64)?)|(f(32|64)?))?', Keyword, '#pop'), + ], + 'string': [ + (r'"', String, '#pop'), + (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape), + (r'[^\\"]+', String), + (r'\\', String), + ], + 'attribute_common': [ + (r'"', String, 'string'), + (r'\[', Comment.Preproc, 'attribute['), + (r'\(', Comment.Preproc, 'attribute('), + ], + 'attribute[': [ + include('attribute_common'), + (r'\];?', Comment.Preproc, '#pop'), + (r'[^"\]]+', Comment.Preproc), + ], + 'attribute(': [ + include('attribute_common'), + (r'\);?', Comment.Preproc, '#pop'), + (r'[^"\)]+', Comment.Preproc), + ], + } + + +class CUDALexer(CLexer): + """ + For NVIDIA `CUDA™ <http://developer.nvidia.com/category/zone/cuda-zone>`_ + source. + + *New in Pygments 1.6.* + """ + name = 'CUDA' + filenames = ['*.cu', '*.cuh'] + aliases = ['cuda', 'cu'] + mimetypes = ['text/x-cuda'] + + function_qualifiers = ['__device__', '__global__', '__host__', + '__noinline__', '__forceinline__'] + variable_qualifiers = ['__device__', '__constant__', '__shared__', + '__restrict__'] + vector_types = ['char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3', + 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2', + 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1', + 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1', + 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4', + 'ulong4', 'longlong1', 'ulonglong1', 'longlong2', + 'ulonglong2', 'float1', 'float2', 'float3', 'float4', + 'double1', 'double2', 'dim3'] + variables = ['gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize'] + functions = ['__threadfence_block', '__threadfence', '__threadfence_system', + '__syncthreads', '__syncthreads_count', '__syncthreads_and', + '__syncthreads_or'] + execution_confs = ['<<<', '>>>'] + + def get_tokens_unprocessed(self, text): + for index, token, value in \ + CLexer.get_tokens_unprocessed(self, text): + if token is Name: + if value in self.variable_qualifiers: + token = Keyword.Type + elif value in self.vector_types: + token = Keyword.Type + elif value in self.variables: + token = Name.Builtin + elif value in self.execution_confs: + token = Keyword.Pseudo + elif value in self.function_qualifiers: + token = Keyword.Reserved + elif value in self.functions: + token = Name.Function + yield index, token, value |