ThirdParty/Pygments/pygments/lexers/agile.py

changeset 684
2f29a0b6e1c7
parent 12
1d8dd9706f46
child 808
8f85926125ef
equal deleted inserted replaced
682:91114a975eda 684:2f29a0b6e1c7
3 pygments.lexers.agile 3 pygments.lexers.agile
4 ~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for agile languages. 6 Lexers for agile languages.
7 7
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2010 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 try:
14 set
15 except NameError:
16 from sets import Set as set
17 13
18 from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, \ 14 from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, \
19 LexerContext, include, combined, do_insertions, bygroups, using 15 LexerContext, include, combined, do_insertions, bygroups, using
20 from pygments.token import Error, Text, \ 16 from pygments.token import Error, Text, Other, \
21 Comment, Operator, Keyword, Name, String, Number, Generic, Punctuation 17 Comment, Operator, Keyword, Name, String, Number, Generic, Punctuation
22 from pygments.util import get_bool_opt, get_list_opt, shebang_matches 18 from pygments.util import get_bool_opt, get_list_opt, shebang_matches
23 from pygments import unistring as uni 19 from pygments import unistring as uni
24 20
25 21
39 For `Python <http://www.python.org>`_ source code. 35 For `Python <http://www.python.org>`_ source code.
40 """ 36 """
41 37
42 name = 'Python' 38 name = 'Python'
43 aliases = ['python', 'py'] 39 aliases = ['python', 'py']
44 filenames = ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript'] 40 filenames = ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac']
45 mimetypes = ['text/x-python', 'application/x-python'] 41 mimetypes = ['text/x-python', 'application/x-python']
46 42
47 tokens = { 43 tokens = {
48 'root': [ 44 'root': [
49 (r'\n', Text), 45 (r'\n', Text),
317 if line.startswith('>>> ') or line.startswith('... '): 313 if line.startswith('>>> ') or line.startswith('... '):
318 tb = 0 314 tb = 0
319 insertions.append((len(curcode), 315 insertions.append((len(curcode),
320 [(0, Generic.Prompt, line[:4])])) 316 [(0, Generic.Prompt, line[:4])]))
321 curcode += line[4:] 317 curcode += line[4:]
322 elif line.rstrip() == '...': 318 elif line.rstrip() == '...' and not tb:
323 tb = 0 319 # only a new >>> prompt can end an exception block
320 # otherwise an ellipsis in place of the traceback frames
321 # will be mishandled
324 insertions.append((len(curcode), 322 insertions.append((len(curcode),
325 [(0, Generic.Prompt, '...')])) 323 [(0, Generic.Prompt, '...')]))
326 curcode += line[3:] 324 curcode += line[3:]
327 else: 325 else:
328 if curcode: 326 if curcode:
366 364
367 tokens = { 365 tokens = {
368 'root': [ 366 'root': [
369 (r'^Traceback \(most recent call last\):\n', Generic.Traceback, 'intb'), 367 (r'^Traceback \(most recent call last\):\n', Generic.Traceback, 'intb'),
370 # SyntaxError starts with this. 368 # SyntaxError starts with this.
371 (r'^(?= File "[^"]+", line \d+\n)', Generic.Traceback, 'intb'), 369 (r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
370 (r'^.*\n', Other),
372 ], 371 ],
373 'intb': [ 372 'intb': [
374 (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)', 373 (r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
375 bygroups(Text, Name.Builtin, Text, Number, Text, Name.Identifier, Text)), 374 bygroups(Text, Name.Builtin, Text, Number, Text, Name.Identifier, Text)),
376 (r'^( File )("[^"]+")(, line )(\d+)(\n)', 375 (r'^( File )("[^"]+")(, line )(\d+)(\n)',
557 name+'-regex')) 556 name+'-regex'))
558 557
559 # these must come after %<brace>! 558 # these must come after %<brace>!
560 states['strings'] += [ 559 states['strings'] += [
561 # %r regex 560 # %r regex
562 (r'(%r([^a-zA-Z0-9]))([^\2\\]*(?:\\.[^\2\\]*)*)(\2[mixounse]*)', 561 (r'(%r([^a-zA-Z0-9]))((?:\\\2|(?!\2).)*)(\2[mixounse]*)',
563 intp_regex_callback), 562 intp_regex_callback),
564 # regular fancy strings with qsw 563 # regular fancy strings with qsw
565 (r'%[qsw]([^a-zA-Z0-9])([^\1\\]*(?:\\.[^\1\\]*)*)\1', String.Other), 564 (r'%[qsw]([^a-zA-Z0-9])((?:\\\1|(?!\1).)*)\1', String.Other),
566 (r'(%[QWx]([^a-zA-Z0-9]))([^\2\\]*(?:\\.[^\2\\]*)*)(\2)', 565 (r'(%[QWx]([^a-zA-Z0-9]))((?:\\\2|(?!\2).)*)(\2)',
567 intp_string_callback), 566 intp_string_callback),
568 # special forms of fancy strings after operators or 567 # special forms of fancy strings after operators or
569 # in method calls with braces 568 # in method calls with braces
570 (r'(?<=[-+/*%=<>&!^|~,(])(\s*)(%([\t ])(?:[^\3\\]*(?:\\.[^\3\\]*)*)\3)', 569 (r'(?<=[-+/*%=<>&!^|~,(])(\s*)(%([\t ])(?:(?:\\\3|(?!\3).)*)\3)',
571 bygroups(Text, String.Other, None)), 570 bygroups(Text, String.Other, None)),
572 # and because of fixed width lookbehinds the whole thing a 571 # and because of fixed width lookbehinds the whole thing a
573 # second time for line startings... 572 # second time for line startings...
574 (r'^(\s*)(%([\t ])(?:[^\3\\]*(?:\\.[^\3\\]*)*)\3)', 573 (r'^(\s*)(%([\t ])(?:(?:\\\3|(?!\3).)*)\3)',
575 bygroups(Text, String.Other, None)), 574 bygroups(Text, String.Other, None)),
576 # all regular fancy strings without qsw 575 # all regular fancy strings without qsw
577 (r'(%([^a-zA-Z0-9\s]))([^\2\\]*(?:\\.[^\2\\]*)*)(\2)', 576 (r'(%([^a-zA-Z0-9\s]))((?:\\\2|(?!\2).)*)(\2)',
578 intp_string_callback), 577 intp_string_callback),
579 ] 578 ]
580 579
581 return states 580 return states
582 581
654 r'(?<=^sub!\s)|' 653 r'(?<=^sub!\s)|'
655 r'(?<=^gsub!\s)|' 654 r'(?<=^gsub!\s)|'
656 r'(?<=^match\s)|' 655 r'(?<=^match\s)|'
657 r'(?<=^if\s)|' 656 r'(?<=^if\s)|'
658 r'(?<=^elsif\s)' 657 r'(?<=^elsif\s)'
659 r')(\s*)(/)(?!=)', bygroups(Text, String.Regex), 'multiline-regex'), 658 r')(\s*)(/)', bygroups(Text, String.Regex), 'multiline-regex'),
660 # multiline regex (in method calls) 659 # multiline regex (in method calls)
661 (r'(?<=\(|,)/', String.Regex, 'multiline-regex'), 660 (r'(?<=\(|,)/', String.Regex, 'multiline-regex'),
662 # multiline regex (this time the funny no whitespace rule) 661 # multiline regex (this time the funny no whitespace rule)
663 (r'(\s+)(/[^\s=])', String.Regex, 'multiline-regex'), 662 (r'(\s+)(/[^\s=])', String.Regex, 'multiline-regex'),
664 # lex numbers and ignore following regular expressions which 663 # lex numbers and ignore following regular expressions which
830 (r'\[(\\\\|\\\]|[^\]])*\][egimosx]*', String.Regex, '#pop'), 829 (r'\[(\\\\|\\\]|[^\]])*\][egimosx]*', String.Regex, '#pop'),
831 (r'\((\\\\|\\\)|[^\)])*\)[egimosx]*', String.Regex, '#pop'), 830 (r'\((\\\\|\\\)|[^\)])*\)[egimosx]*', String.Regex, '#pop'),
832 (r'@(\\\\|\\\@|[^\@])*@[egimosx]*', String.Regex, '#pop'), 831 (r'@(\\\\|\\\@|[^\@])*@[egimosx]*', String.Regex, '#pop'),
833 (r'%(\\\\|\\\%|[^\%])*%[egimosx]*', String.Regex, '#pop'), 832 (r'%(\\\\|\\\%|[^\%])*%[egimosx]*', String.Regex, '#pop'),
834 (r'\$(\\\\|\\\$|[^\$])*\$[egimosx]*', String.Regex, '#pop'), 833 (r'\$(\\\\|\\\$|[^\$])*\$[egimosx]*', String.Regex, '#pop'),
835 (r'!(\\\\|\\!|[^!])*![egimosx]*', String.Regex, '#pop'),
836 ], 834 ],
837 'root': [ 835 'root': [
838 (r'\#.*?$', Comment.Single), 836 (r'\#.*?$', Comment.Single),
839 (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline), 837 (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline),
840 (r'(case|continue|do|else|elsif|for|foreach|if|last|my|' 838 (r'(case|continue|do|else|elsif|for|foreach|if|last|my|'
854 (r's<(\\\\|\\>|[^>])*>\s*', String.Regex, 'balanced-regex'), 852 (r's<(\\\\|\\>|[^>])*>\s*', String.Regex, 'balanced-regex'),
855 (r's\[(\\\\|\\\]|[^\]])*\]\s*', String.Regex, 'balanced-regex'), 853 (r's\[(\\\\|\\\]|[^\]])*\]\s*', String.Regex, 'balanced-regex'),
856 (r's\((\\\\|\\\)|[^\)])*\)\s*', String.Regex, 'balanced-regex'), 854 (r's\((\\\\|\\\)|[^\)])*\)\s*', String.Regex, 'balanced-regex'),
857 855
858 (r'm?/(\\\\|\\/|[^/\n])*/[gcimosx]*', String.Regex), 856 (r'm?/(\\\\|\\/|[^/\n])*/[gcimosx]*', String.Regex),
857 (r'm(?=[/!\\{<\[\(@%\$])', String.Regex, 'balanced-regex'),
859 (r'((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[gcimosx]*', String.Regex), 858 (r'((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[gcimosx]*', String.Regex),
860 (r'\s+', Text), 859 (r'\s+', Text),
861 (r'(abs|accept|alarm|atan2|bind|binmode|bless|caller|chdir|' 860 (r'(abs|accept|alarm|atan2|bind|binmode|bless|caller|chdir|'
862 r'chmod|chomp|chop|chown|chr|chroot|close|closedir|connect|' 861 r'chmod|chomp|chop|chown|chr|chroot|close|closedir|connect|'
863 r'continue|cos|crypt|dbmclose|dbmopen|defined|delete|die|' 862 r'continue|cos|crypt|dbmclose|dbmopen|defined|delete|die|'
901 (r'<([^\s>]+)>', String.Regexp), 900 (r'<([^\s>]+)>', String.Regexp),
902 (r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'), 901 (r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'),
903 (r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'), 902 (r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'),
904 (r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'), 903 (r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'),
905 (r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'), 904 (r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'),
906 (r'(q|qq|qw|qr|qx)(.)[.\n]*?\1', String.Other), 905 (r'(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2', String.Other),
907 (r'package\s+', Keyword, 'modulename'), 906 (r'package\s+', Keyword, 'modulename'),
908 (r'sub\s+', Keyword, 'funcname'), 907 (r'sub\s+', Keyword, 'funcname'),
909 (r'(\[\]|\*\*|::|<<|>>|>=|<=|<=>|={3}|!=|=~|' 908 (r'(\[\]|\*\*|::|<<|>>|>=|<=|<=>|={3}|!=|=~|'
910 r'!~|&&?|\|\||\.{1,3})', Operator), 909 r'!~|&&?|\|\||\.{1,3})', Operator),
911 (r'[-+/*%=<>&^|!\\~]=?', Operator), 910 (r'[-+/*%=<>&^|!\\~]=?', Operator),
965 'lt-string': [ 964 'lt-string': [
966 (r'\\[\<\>\\]', String.Other), 965 (r'\\[\<\>\\]', String.Other),
967 (r'\\', String.Other), 966 (r'\\', String.Other),
968 (r'\<', String.Other, 'lt-string'), 967 (r'\<', String.Other, 'lt-string'),
969 (r'\>', String.Other, '#pop'), 968 (r'\>', String.Other, '#pop'),
970 (r'[^\<\>]]+', String.Other) 969 (r'[^\<\>]+', String.Other)
971 ], 970 ],
972 'end-part': [ 971 'end-part': [
973 (r'.+', Comment.Preproc, '#pop') 972 (r'.+', Comment.Preproc, '#pop')
974 ] 973 ]
975 } 974 }
1010 filenames = ['*.lua'] 1009 filenames = ['*.lua']
1011 mimetypes = ['text/x-lua', 'application/x-lua'] 1010 mimetypes = ['text/x-lua', 'application/x-lua']
1012 1011
1013 tokens = { 1012 tokens = {
1014 'root': [ 1013 'root': [
1014 # lua allows a file to start with a shebang
1015 (r'#!(.*?)$', Comment.Preproc),
1016 (r'', Text, 'base'),
1017 ],
1018 'base': [
1015 (r'(?s)--\[(=*)\[.*?\]\1\]', Comment.Multiline), 1019 (r'(?s)--\[(=*)\[.*?\]\1\]', Comment.Multiline),
1016 ('--.*$', Comment.Single), 1020 ('--.*$', Comment.Single),
1017 1021
1018 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float), 1022 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
1019 (r'(?i)\d+e[+-]?\d+', Number.Float), 1023 (r'(?i)\d+e[+-]?\d+', Number.Float),
1258 tokens = { 1262 tokens = {
1259 'root': [ 1263 'root': [
1260 include('command'), 1264 include('command'),
1261 include('basic'), 1265 include('basic'),
1262 include('data'), 1266 include('data'),
1267 (r'}', Keyword), # HACK: somehow we miscounted our braces
1263 ], 1268 ],
1264 'command': _gen_command_rules(keyword_cmds_re, builtin_cmds_re), 1269 'command': _gen_command_rules(keyword_cmds_re, builtin_cmds_re),
1265 'command-in-brace': _gen_command_rules(keyword_cmds_re, 1270 'command-in-brace': _gen_command_rules(keyword_cmds_re,
1266 builtin_cmds_re, 1271 builtin_cmds_re,
1267 "-in-brace"), 1272 "-in-brace"),
1307 (r'\]', Keyword, ('#pop', '#pop')), 1312 (r'\]', Keyword, ('#pop', '#pop')),
1308 include('params') 1313 include('params')
1309 ], 1314 ],
1310 'string': [ 1315 'string': [
1311 (r'\[', String.Double, 'string-square'), 1316 (r'\[', String.Double, 'string-square'),
1312 (r'(\\\\|\\[0-7]+|\\.|[^"])', String.Double), 1317 (r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\])', String.Double),
1313 (r'"', String.Double, '#pop') 1318 (r'"', String.Double, '#pop')
1314 ], 1319 ],
1315 'string-square': [ 1320 'string-square': [
1316 (r'\[', String.Double, 'string-square'), 1321 (r'\[', String.Double, 'string-square'),
1317 (r'(\\\\|\\[0-7]+|\\.|[^\]])', String.Double), 1322 (r'(?s)(\\\\|\\[0-7]+|\\.|\\\n|[^\]\\])', String.Double),
1318 (r'\]', String.Double, '#pop') 1323 (r'\]', String.Double, '#pop')
1319 ], 1324 ],
1320 'brace': [ 1325 'brace': [
1321 (r'}', Keyword, '#pop'), 1326 (r'}', Keyword, '#pop'),
1322 include('command-in-brace'), 1327 include('command-in-brace'),
1436 #(r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number), 1441 #(r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number),
1437 1442
1438 # strings, symbols and characters 1443 # strings, symbols and characters
1439 (r'"(\\\\|\\"|[^"])*"', String), 1444 (r'"(\\\\|\\"|[^"])*"', String),
1440 (r"'" + valid_name, String.Symbol), 1445 (r"'" + valid_name, String.Symbol),
1441 (r"\\([()/'\".'_!§$%& ?;=+-]{1}|[a-zA-Z0-9]+)", String.Char), 1446 (r"\\([()/'\".'_!§$%& ?;=#+-]{1}|[a-zA-Z0-9]+)", String.Char),
1442 1447
1443 # constants 1448 # constants
1444 (r'(#t|#f)', Name.Constant), 1449 (r'(#t|#f)', Name.Constant),
1445 1450
1446 # special operators 1451 # special operators

eric ide

mercurial