Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/hexdump.py: 100%
8 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:16 +0000
1"""
2 pygments.lexers.hexdump
3 ~~~~~~~~~~~~~~~~~~~~~~~
5 Lexers for hexadecimal dumps.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, bygroups, include
12from pygments.token import Name, Number, String, Punctuation, Whitespace
14__all__ = ['HexdumpLexer']
17class HexdumpLexer(RegexLexer):
18 """
19 For typical hex dump output formats by the UNIX and GNU/Linux tools ``hexdump``,
20 ``hd``, ``hexcat``, ``od`` and ``xxd``, and the DOS tool ``DEBUG``. For example:
22 .. sourcecode:: hexdump
24 00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
25 00000010 02 00 3e 00 01 00 00 00 c5 48 40 00 00 00 00 00 |..>......H@.....|
27 The specific supported formats are the outputs of:
29 * ``hexdump FILE``
30 * ``hexdump -C FILE`` -- the `canonical` format used in the example.
31 * ``hd FILE`` -- same as ``hexdump -C FILE``.
32 * ``hexcat FILE``
33 * ``od -t x1z FILE``
34 * ``xxd FILE``
35 * ``DEBUG.EXE FILE.COM`` and entering ``d`` to the prompt.
37 .. versionadded:: 2.1
38 """
39 name = 'Hexdump'
40 aliases = ['hexdump']
42 hd = r'[0-9A-Ha-h]'
44 tokens = {
45 'root': [
46 (r'\n', Whitespace),
47 include('offset'),
48 (r'('+hd+r'{2})(\-)('+hd+r'{2})',
49 bygroups(Number.Hex, Punctuation, Number.Hex)),
50 (hd+r'{2}', Number.Hex),
51 (r'(\s{2,3})(\>)(.{16})(\<)$',
52 bygroups(Whitespace, Punctuation, String, Punctuation), 'bracket-strings'),
53 (r'(\s{2,3})(\|)(.{16})(\|)$',
54 bygroups(Whitespace, Punctuation, String, Punctuation), 'piped-strings'),
55 (r'(\s{2,3})(\>)(.{1,15})(\<)$',
56 bygroups(Whitespace, Punctuation, String, Punctuation)),
57 (r'(\s{2,3})(\|)(.{1,15})(\|)$',
58 bygroups(Whitespace, Punctuation, String, Punctuation)),
59 (r'(\s{2,3})(.{1,15})$', bygroups(Whitespace, String)),
60 (r'(\s{2,3})(.{16}|.{20})$', bygroups(Whitespace, String), 'nonpiped-strings'),
61 (r'\s', Whitespace),
62 (r'^\*', Punctuation),
63 ],
64 'offset': [
65 (r'^('+hd+'+)(:)', bygroups(Name.Label, Punctuation), 'offset-mode'),
66 (r'^'+hd+'+', Name.Label),
67 ],
68 'offset-mode': [
69 (r'\s', Whitespace, '#pop'),
70 (hd+'+', Name.Label),
71 (r':', Punctuation)
72 ],
73 'piped-strings': [
74 (r'\n', Whitespace),
75 include('offset'),
76 (hd+r'{2}', Number.Hex),
77 (r'(\s{2,3})(\|)(.{1,16})(\|)$',
78 bygroups(Whitespace, Punctuation, String, Punctuation)),
79 (r'\s', Whitespace),
80 (r'^\*', Punctuation),
81 ],
82 'bracket-strings': [
83 (r'\n', Whitespace),
84 include('offset'),
85 (hd+r'{2}', Number.Hex),
86 (r'(\s{2,3})(\>)(.{1,16})(\<)$',
87 bygroups(Whitespace, Punctuation, String, Punctuation)),
88 (r'\s', Whitespace),
89 (r'^\*', Punctuation),
90 ],
91 'nonpiped-strings': [
92 (r'\n', Whitespace),
93 include('offset'),
94 (r'('+hd+r'{2})(\-)('+hd+r'{2})',
95 bygroups(Number.Hex, Punctuation, Number.Hex)),
96 (hd+r'{2}', Number.Hex),
97 (r'(\s{19,})(.{1,20}?)$', bygroups(Whitespace, String)),
98 (r'(\s{2,3})(.{1,20})$', bygroups(Whitespace, String)),
99 (r'\s', Whitespace),
100 (r'^\*', Punctuation),
101 ],
102 }