1 package h
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Hexdump = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Hexdump",
12 Aliases: []string{"hexdump"},
13 Filenames: []string{},
14 MimeTypes: []string{},
15 },
16 hexdumpRules,
17 ))
18
19 func hexdumpRules() Rules {
20 return Rules{
21 "root": {
22 {`\n`, Text, nil},
23 Include("offset"),
24 {`([0-9A-Ha-h]{2})(\-)([0-9A-Ha-h]{2})`, ByGroups(LiteralNumberHex, Punctuation, LiteralNumberHex), nil},
25 {`[0-9A-Ha-h]{2}`, LiteralNumberHex, nil},
26 {`(\s{2,3})(\>)(.{16})(\<)$`, ByGroups(Text, Punctuation, LiteralString, Punctuation), Push("bracket-strings")},
27 {`(\s{2,3})(\|)(.{16})(\|)$`, ByGroups(Text, Punctuation, LiteralString, Punctuation), Push("piped-strings")},
28 {`(\s{2,3})(\>)(.{1,15})(\<)$`, ByGroups(Text, Punctuation, LiteralString, Punctuation), nil},
29 {`(\s{2,3})(\|)(.{1,15})(\|)$`, ByGroups(Text, Punctuation, LiteralString, Punctuation), nil},
30 {`(\s{2,3})(.{1,15})$`, ByGroups(Text, LiteralString), nil},
31 {`(\s{2,3})(.{16}|.{20})$`, ByGroups(Text, LiteralString), Push("nonpiped-strings")},
32 {`\s`, Text, nil},
33 {`^\*`, Punctuation, nil},
34 },
35 "offset": {
36 {`^([0-9A-Ha-h]+)(:)`, ByGroups(NameLabel, Punctuation), Push("offset-mode")},
37 {`^[0-9A-Ha-h]+`, NameLabel, nil},
38 },
39 "offset-mode": {
40 {`\s`, Text, Pop(1)},
41 {`[0-9A-Ha-h]+`, NameLabel, nil},
42 {`:`, Punctuation, nil},
43 },
44 "piped-strings": {
45 {`\n`, Text, nil},
46 Include("offset"),
47 {`[0-9A-Ha-h]{2}`, LiteralNumberHex, nil},
48 {`(\s{2,3})(\|)(.{1,16})(\|)$`, ByGroups(Text, Punctuation, LiteralString, Punctuation), nil},
49 {`\s`, Text, nil},
50 {`^\*`, Punctuation, nil},
51 },
52 "bracket-strings": {
53 {`\n`, Text, nil},
54 Include("offset"),
55 {`[0-9A-Ha-h]{2}`, LiteralNumberHex, nil},
56 {`(\s{2,3})(\>)(.{1,16})(\<)$`, ByGroups(Text, Punctuation, LiteralString, Punctuation), nil},
57 {`\s`, Text, nil},
58 {`^\*`, Punctuation, nil},
59 },
60 "nonpiped-strings": {
61 {`\n`, Text, nil},
62 Include("offset"),
63 {`([0-9A-Ha-h]{2})(\-)([0-9A-Ha-h]{2})`, ByGroups(LiteralNumberHex, Punctuation, LiteralNumberHex), nil},
64 {`[0-9A-Ha-h]{2}`, LiteralNumberHex, nil},
65 {`(\s{19,})(.{1,20}?)$`, ByGroups(Text, LiteralString), nil},
66 {`(\s{2,3})(.{1,20})$`, ByGroups(Text, LiteralString), nil},
67 {`\s`, Text, nil},
68 {`^\*`, Punctuation, nil},
69 },
70 }
71 }
72
View as plain text