3 pygments.lexers.hexdump |
3 pygments.lexers.hexdump |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for hexadecimal dumps. |
6 Lexers for hexadecimal dumps. |
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 |
|
12 import re |
|
13 |
11 |
14 from pygments.lexer import RegexLexer, bygroups, include |
12 from pygments.lexer import RegexLexer, bygroups, include |
15 from pygments.token import Text, Name, Number, String, Punctuation |
13 from pygments.token import Text, Name, Number, String, Punctuation |
16 |
14 |
17 __all__ = ['HexdumpLexer'] |
15 __all__ = ['HexdumpLexer'] |
46 |
44 |
47 tokens = { |
45 tokens = { |
48 'root': [ |
46 'root': [ |
49 (r'\n', Text), |
47 (r'\n', Text), |
50 include('offset'), |
48 include('offset'), |
51 (r'('+hd+r'{2})(\-)('+hd+r'{2})', bygroups(Number.Hex, Punctuation, Number.Hex)), |
49 (r'('+hd+r'{2})(\-)('+hd+r'{2})', |
|
50 bygroups(Number.Hex, Punctuation, Number.Hex)), |
52 (hd+r'{2}', Number.Hex), |
51 (hd+r'{2}', Number.Hex), |
53 (r'(\s{2,3})(\>)(.{16})(\<)$', bygroups(Text, Punctuation, String, Punctuation), 'bracket-strings'), |
52 (r'(\s{2,3})(\>)(.{16})(\<)$', |
54 (r'(\s{2,3})(\|)(.{16})(\|)$', bygroups(Text, Punctuation, String, Punctuation), 'piped-strings'), |
53 bygroups(Text, Punctuation, String, Punctuation), 'bracket-strings'), |
55 (r'(\s{2,3})(\>)(.{1,15})(\<)$', bygroups(Text, Punctuation, String, Punctuation)), |
54 (r'(\s{2,3})(\|)(.{16})(\|)$', |
56 (r'(\s{2,3})(\|)(.{1,15})(\|)$', bygroups(Text, Punctuation, String, Punctuation)), |
55 bygroups(Text, Punctuation, String, Punctuation), 'piped-strings'), |
|
56 (r'(\s{2,3})(\>)(.{1,15})(\<)$', |
|
57 bygroups(Text, Punctuation, String, Punctuation)), |
|
58 (r'(\s{2,3})(\|)(.{1,15})(\|)$', |
|
59 bygroups(Text, Punctuation, String, Punctuation)), |
57 (r'(\s{2,3})(.{1,15})$', bygroups(Text, String)), |
60 (r'(\s{2,3})(.{1,15})$', bygroups(Text, String)), |
58 (r'(\s{2,3})(.{16}|.{20})$', bygroups(Text, String), 'nonpiped-strings'), |
61 (r'(\s{2,3})(.{16}|.{20})$', bygroups(Text, String), 'nonpiped-strings'), |
59 (r'\s', Text), |
62 (r'\s', Text), |
60 (r'^\*', Punctuation), |
63 (r'^\*', Punctuation), |
61 ], |
64 ], |
70 ], |
73 ], |
71 'piped-strings': [ |
74 'piped-strings': [ |
72 (r'\n', Text), |
75 (r'\n', Text), |
73 include('offset'), |
76 include('offset'), |
74 (hd+r'{2}', Number.Hex), |
77 (hd+r'{2}', Number.Hex), |
75 (r'(\s{2,3})(\|)(.{1,16})(\|)$', bygroups(Text, Punctuation, String, Punctuation)), |
78 (r'(\s{2,3})(\|)(.{1,16})(\|)$', |
|
79 bygroups(Text, Punctuation, String, Punctuation)), |
76 (r'\s', Text), |
80 (r'\s', Text), |
77 (r'^\*', Punctuation), |
81 (r'^\*', Punctuation), |
78 ], |
82 ], |
79 'bracket-strings': [ |
83 'bracket-strings': [ |
80 (r'\n', Text), |
84 (r'\n', Text), |
81 include('offset'), |
85 include('offset'), |
82 (hd+r'{2}', Number.Hex), |
86 (hd+r'{2}', Number.Hex), |
83 (r'(\s{2,3})(\>)(.{1,16})(\<)$', bygroups(Text, Punctuation, String, Punctuation)), |
87 (r'(\s{2,3})(\>)(.{1,16})(\<)$', |
|
88 bygroups(Text, Punctuation, String, Punctuation)), |
84 (r'\s', Text), |
89 (r'\s', Text), |
85 (r'^\*', Punctuation), |
90 (r'^\*', Punctuation), |
86 ], |
91 ], |
87 'nonpiped-strings': [ |
92 'nonpiped-strings': [ |
88 (r'\n', Text), |
93 (r'\n', Text), |
89 include('offset'), |
94 include('offset'), |
90 (r'('+hd+r'{2})(\-)('+hd+r'{2})', bygroups(Number.Hex, Punctuation, Number.Hex)), |
95 (r'('+hd+r'{2})(\-)('+hd+r'{2})', |
|
96 bygroups(Number.Hex, Punctuation, Number.Hex)), |
91 (hd+r'{2}', Number.Hex), |
97 (hd+r'{2}', Number.Hex), |
92 (r'(\s{19,})(.{1,20}?)$', bygroups(Text, String)), |
98 (r'(\s{19,})(.{1,20}?)$', bygroups(Text, String)), |
93 (r'(\s{2,3})(.{1,20})$', bygroups(Text, String)), |
99 (r'(\s{2,3})(.{1,20})$', bygroups(Text, String)), |
94 (r'\s', Text), |
100 (r'\s', Text), |
95 (r'^\*', Punctuation), |
101 (r'^\*', Punctuation), |