ThirdParty/Pygments/pygments/lexers/c_cpp.py

changeset 5713
6762afd9f963
parent 5072
aab59042fefb
child 6651
e8f3b5568b21
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
3 pygments.lexers.c_cpp 3 pygments.lexers.c_cpp
4 ~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for C/C++ languages. 6 Lexers for C/C++ languages.
7 7
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
44 ('^(' + _ws1 + ')(#)', 44 ('^(' + _ws1 + ')(#)',
45 bygroups(using(this), Comment.Preproc), 'macro'), 45 bygroups(using(this), Comment.Preproc), 'macro'),
46 (r'\n', Text), 46 (r'\n', Text),
47 (r'\s+', Text), 47 (r'\s+', Text),
48 (r'\\\n', Text), # line continuation 48 (r'\\\n', Text), # line continuation
49 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), 49 (r'//(\n|[\w\W]*?[^\\]\n)', Comment.Single),
50 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 50 (r'/(\\\n)?[*][\w\W]*?[*](\\\n)?/', Comment.Multiline),
51 # Open until EOF, so no ending delimeter
52 (r'/(\\\n)?[*][\w\W]*', Comment.Multiline),
51 ], 53 ],
52 'statements': [ 54 'statements': [
53 (r'L?"', String, 'string'), 55 (r'(L?)(")', bygroups(String.Affix, String), 'string'),
54 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), 56 (r"(L?)(')(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])(')",
57 bygroups(String.Affix, String.Char, String.Char, String.Char)),
55 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), 58 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
56 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), 59 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
57 (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), 60 (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
58 (r'0[0-7]+[LlUu]*', Number.Oct), 61 (r'0[0-7]+[LlUu]*', Number.Oct),
59 (r'\d+[LlUu]*', Number.Integer), 62 (r'\d+[LlUu]*', Number.Integer),
60 (r'\*/', Error), 63 (r'\*/', Error),
61 (r'[~!%^&*+=|?:<>/-]', Operator), 64 (r'[~!%^&*+=|?:<>/-]', Operator),
62 (r'[()\[\],.]', Punctuation), 65 (r'[()\[\],.]', Punctuation),
63 (words(('auto', 'break', 'case', 'const', 'continue', 'default', 'do', 66 (words(('asm', 'auto', 'break', 'case', 'const', 'continue',
64 'else', 'enum', 'extern', 'for', 'goto', 'if', 'register', 67 'default', 'do', 'else', 'enum', 'extern', 'for', 'goto',
65 'restricted', 'return', 'sizeof', 'static', 'struct', 68 'if', 'register', 'restricted', 'return', 'sizeof',
66 'switch', 'typedef', 'union', 'volatile', 'while'), 69 'static', 'struct', 'switch', 'typedef', 'union',
70 'volatile', 'while'),
67 suffix=r'\b'), Keyword), 71 suffix=r'\b'), Keyword),
68 (r'(bool|int|long|float|short|double|char|unsigned|signed|void)\b', 72 (r'(bool|int|long|float|short|double|char|unsigned|signed|void)\b',
69 Keyword.Type), 73 Keyword.Type),
70 (words(('inline', '_inline', '__inline', 'naked', 'restrict', 74 (words(('inline', '_inline', '__inline', 'naked', 'restrict',
71 'thread', 'typename'), suffix=r'\b'), Keyword.Reserved), 75 'thread', 'typename'), suffix=r'\b'), Keyword.Reserved),
121 (r'[^\\"\n]+', String), # all other characters 125 (r'[^\\"\n]+', String), # all other characters
122 (r'\\\n', String), # line continuation 126 (r'\\\n', String), # line continuation
123 (r'\\', String), # stray backslash 127 (r'\\', String), # stray backslash
124 ], 128 ],
125 'macro': [ 129 'macro': [
126 (r'(include)(' + _ws1 + ')([^\n]+)', bygroups(Comment.Preproc, Text, Comment.PreprocFile)), 130 (r'(include)(' + _ws1 + r')([^\n]+)',
131 bygroups(Comment.Preproc, Text, Comment.PreprocFile)),
127 (r'[^/\n]+', Comment.Preproc), 132 (r'[^/\n]+', Comment.Preproc),
128 (r'/[*](.|\n)*?[*]/', Comment.Multiline), 133 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
129 (r'//.*?\n', Comment.Single, '#pop'), 134 (r'//.*?\n', Comment.Single, '#pop'),
130 (r'/', Comment.Preproc), 135 (r'/', Comment.Preproc),
131 (r'(?<=\\)\n', Comment.Preproc), 136 (r'(?<=\\)\n', Comment.Preproc),
204 priority = 0.1 209 priority = 0.1
205 210
206 tokens = { 211 tokens = {
207 'statements': [ 212 'statements': [
208 (words(( 213 (words((
209 'asm', 'catch', 'const_cast', 'delete', 'dynamic_cast', 'explicit', 214 'catch', 'const_cast', 'delete', 'dynamic_cast', 'explicit',
210 'export', 'friend', 'mutable', 'namespace', 'new', 'operator', 215 'export', 'friend', 'mutable', 'namespace', 'new', 'operator',
211 'private', 'protected', 'public', 'reinterpret_cast', 216 'private', 'protected', 'public', 'reinterpret_cast',
212 'restrict', 'static_cast', 'template', 'this', 'throw', 'throws', 217 'restrict', 'static_cast', 'template', 'this', 'throw', 'throws',
213 'try', 'typeid', 'typename', 'using', 'virtual', 218 'try', 'typeid', 'typename', 'using', 'virtual',
214 'constexpr', 'nullptr', 'decltype', 'thread_local', 219 'constexpr', 'nullptr', 'decltype', 'thread_local',
215 'alignas', 'alignof', 'static_assert', 'noexcept', 'override', 220 'alignas', 'alignof', 'static_assert', 'noexcept', 'override',
216 'final'), suffix=r'\b'), Keyword), 221 'final'), suffix=r'\b'), Keyword),
217 (r'char(16_t|32_t)\b', Keyword.Type), 222 (r'char(16_t|32_t)\b', Keyword.Type),
218 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), 223 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
219 # C++11 raw strings 224 # C++11 raw strings
220 (r'R"\(', String, 'rawstring'), 225 (r'(R)(")([^\\()\s]{,16})(\()((?:.|\n)*?)(\)\3)(")',
226 bygroups(String.Affix, String, String.Delimiter, String.Delimiter,
227 String, String.Delimiter, String)),
228 # C++11 UTF-8/16/32 strings
229 (r'(u8|u|U)(")', bygroups(String.Affix, String), 'string'),
221 inherit, 230 inherit,
222 ], 231 ],
223 'root': [ 232 'root': [
224 inherit, 233 inherit,
225 # C++ Microsoft-isms 234 # C++ Microsoft-isms
232 'classname': [ 241 'classname': [
233 (r'[a-zA-Z_]\w*', Name.Class, '#pop'), 242 (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
234 # template specification 243 # template specification
235 (r'\s*(?=>)', Text, '#pop'), 244 (r'\s*(?=>)', Text, '#pop'),
236 ], 245 ],
237 'rawstring': [
238 (r'\)"', String, '#pop'),
239 (r'[^)]+', String),
240 (r'\)', String),
241 ],
242 } 246 }
243 247
244 def analyse_text(text): 248 def analyse_text(text):
245 if re.search('#include <[a-z_]+>', text): 249 if re.search('#include <[a-z_]+>', text):
246 return 0.2 250 return 0.2

eric ide

mercurial