xref: /vim-8.2.3635/runtime/syntax/hex.vim (revision 36e294c0)
1" Vim syntax file
2" Language:	Intel HEX
3" Maintainer:	Markus Heidelberg <[email protected]>
4" Previous version:	Sams Ricahrd <[email protected]>
5" Last Change:	2015 Feb 24
6
7" Each record (line) is built as follows:
8"
9"    field       digits          states
10"
11"  +----------+
12"  | start    |  1 (':')         hexRecStart
13"  +----------+
14"  | count    |  2               hexDataByteCount
15"  +----------+
16"  | address  |  4               hexNoAddress, hexDataAddress, (hexAddressFieldUnknown)
17"  +----------+
18"  | type     |  2               hexRecType, (hexRecTypeUnknown)
19"  +----------+
20"  | data     |  0..510          hexDataOdd, hexDataEven, hexExtendedAddress, hexStartAddress, (hexDataFieldUnknown, hexDataUnexpected)
21"  +----------+
22"  | checksum |  2               hexChecksum
23"  +----------+
24"
25" States in parentheses in the upper format description indicate that they
26" should not appear in a valid file.
27
28" For version 5.x: Clear all syntax items
29" For version 6.x: Quit when a syntax file was already loaded
30if version < 600
31  syntax clear
32elseif exists("b:current_syntax")
33  finish
34endif
35
36syn match hexRecStart "^:"
37
38syn match hexDataByteCount "^:[0-9a-fA-F]\{2}" contains=hexRecStart nextgroup=hexAddress
39
40syn match hexAddress "[0-9a-fA-F]\{4}" transparent contained nextgroup=hexRecTypeUnknown,hexRecType
41" The address field groups include the record type field in the last 2
42" characters, the proper match for highlighting follows below.
43syn match hexAddressFieldUnknown "^:[0-9a-fA-F]\{8}"      contains=hexDataByteCount nextgroup=hexDataFieldUnknown,hexChecksum
44syn match hexDataAddress         "^:[0-9a-fA-F]\{6}00"    contains=hexDataByteCount nextgroup=hexDataOdd,hexChecksum
45syn match hexNoAddress           "^:[0-9a-fA-F]\{6}01"    contains=hexDataByteCount nextgroup=hexDataUnexpected,hexChecksum
46syn match hexNoAddress           "^:[0-9a-fA-F]\{6}0[24]" contains=hexDataByteCount nextgroup=hexExtendedAddress
47syn match hexNoAddress           "^:[0-9a-fA-F]\{6}0[35]" contains=hexDataByteCount nextgroup=hexStartAddress
48
49syn match hexRecTypeUnknown "[0-9a-fA-F]\{2}" contained
50syn match hexRecType        "0[0-5]"          contained
51
52syn match hexDataFieldUnknown "[0-9a-fA-F]\{2}" contained nextgroup=hexDataFieldUnknown,hexChecksum
53" alternating highlight per byte for easier reading
54syn match hexDataOdd          "[0-9a-fA-F]\{2}" contained nextgroup=hexDataEven,hexChecksum
55syn match hexDataEven         "[0-9a-fA-F]\{2}" contained nextgroup=hexDataOdd,hexChecksum
56" data bytes which should not exist
57syn match hexDataUnexpected   "[0-9a-fA-F]\{2}" contained nextgroup=hexDataUnexpected,hexChecksum
58" Data digit pair regex usage also results in only highlighting the checksum
59" if the number of data characters is even.
60
61" special data fields
62syn match hexExtendedAddress "[0-9a-fA-F]\{4}" contained nextgroup=hexDataUnexpected,hexChecksum
63syn match hexStartAddress    "[0-9a-fA-F]\{8}" contained nextgroup=hexDataUnexpected,hexChecksum
64
65syn match hexChecksum "[0-9a-fA-F]\{2}$" contained
66
67" Folding Data Records below an Extended Segment/Linear Address Record
68syn region hexExtAdrBlock start="^:[0-9a-fA-F]\{7}[24]" skip="^:[0-9a-fA-F]\{7}0" end="^:"me=s-1 fold transparent
69
70" Define the default highlighting.
71" For version 5.7 and earlier: only when not done already
72" For version 5.8 and later: only when an item doesn't have highlighting yet
73if version >= 508 || !exists("did_hex_syntax_inits")
74  if version < 508
75    let did_hex_syntax_inits = 1
76    command -nargs=+ HiLink hi link <args>
77  else
78    command -nargs=+ HiLink hi def link <args>
79  endif
80
81  " The default methods for highlighting. Can be overridden later
82  HiLink hexRecStart            hexRecType
83  HiLink hexDataByteCount       Constant
84  hi def hexAddressFieldUnknown term=italic cterm=italic gui=italic
85  HiLink hexDataAddress         Comment
86  HiLink hexNoAddress           DiffAdd
87  HiLink hexRecTypeUnknown      hexRecType
88  HiLink hexRecType             WarningMsg
89  hi def hexDataFieldUnknown    term=italic cterm=italic gui=italic
90  hi def hexDataOdd             term=bold cterm=bold gui=bold
91  hi def hexDataEven            term=NONE cterm=NONE gui=NONE
92  HiLink hexDataUnexpected      Error
93  HiLink hexExtendedAddress     hexDataAddress
94  HiLink hexStartAddress        hexDataAddress
95  HiLink hexChecksum            DiffChange
96
97  delcommand HiLink
98endif
99
100let b:current_syntax = "hex"
101
102" vim: ts=8
103