blob: d41ead1f2038bcf2ae858164f50bf39c906eb564 [file] [log] [blame]
Ben Olmsteadc0d77842019-07-31 17:34:05 -07001" Copyright 2019 Google LLC
2"
3" Licensed under the Apache License, Version 2.0 (the "License");
4" you may not use this file except in compliance with the License.
5" You may obtain a copy of the License at
6"
7" https://www.apache.org/licenses/LICENSE-2.0
8"
9" Unless required by applicable law or agreed to in writing, software
10" distributed under the License is distributed on an "AS IS" BASIS,
11" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12" See the License for the specific language governing permissions and
13" limitations under the License.
14
15" Vim syntax file for Emboss.
16
17" Quit when a (custom) syntax file was already loaded.
18if exists('b:current_syntax')
19 finish
20endif
21
22" TODO(bolms): Generate the syntax patterns from the patterns in tokenizer.py.
23" Note that Python regex syntax and Vim regexp syntax differ significantly, and
24" the matching logic Vim uses for syntactic elements is significantly different
25" from what a tokenizer uses.
26
27syn clear
28
29" Emboss keywords.
30syn keyword embStructure struct union enum bits external
31syn keyword embKeyword $reserved $default
32syn keyword embKeyword $static_size_in_bits $is_statically_sized this
Faraaz Sareshwalac49a9ec2022-07-06 16:52:23 -070033syn keyword embKeyword $next $max $present $upper_bound $lower_bound
Ben Olmsteadc0d77842019-07-31 17:34:05 -070034syn keyword embKeyword import as
35syn keyword embKeyword if let
36syn keyword embBoolean true false
37syn keyword embIdentifier $size_in_bits $size_in_bytes
38syn keyword embIdentifier $max_size_in_bits $max_size_in_bytes
39syn keyword embIdentifier $min_size_in_bits $min_size_in_bytes
40
41" Per standard convention, highlight to-do patterns in comments.
42syn keyword embTodo contained TODO FIXME XXX
43
44" When more than one syntax pattern matches a particular chunk of text, Vim
45" picks the last one. These 'catch-all' patterns will match any word or number,
46" valid or invalid; valid tokens will be matched again by later patterns,
47" overriding the embBadNumber or embBadWord match.
48syn match embBadNumber display '\v\C<[0-9][0-9a-zA-Z_$]*>'
49syn match embBadWord display '\v\C<[A-Za-z_$][A-Za-z0-9_$]*>'
50
51" Type names are always CamelCase, enum constants are always SHOUTY_CASE, and
52" most other identifiers (field names, attribute names) are snake_case.
53syn match embType display '\v\C<[A-Z][A-Z0-9]*[a-z][A-Za-z0-9]*>'
54syn match embConstant display '\v\C<[A-Z][A-Z0-9_]+>'
55syn match embIdentifier display '\v\C<[a-z][a-z0-9_]*>'
56
57" Decimal integers both with and without thousands separators.
58syn match embNumber display '\v\C<\d+>'
59syn match embNumber display '\v\C<\d{1,3}(_\d{3})*>'
60
61" Hex integers with and without word/doubleword separators.
62syn match embNumber display '\v\C<0[xX]\x+>'
63syn match embNumber display '\v\C<0[xX]\x{1,4}(_\x{4})*>'
64syn match embNumber display '\v\C<0[xX]\x{1,8}(_\x{8})*>'
65
66" Binary integers with and without byte/nibble separators.
67syn match embNumber display '\v\C<0[bB][01]+>'
68syn match embNumber display '\v\C<0[bB][01]{1,4}(_[01]{4})*>'
69syn match embNumber display '\v\C<0[bB][01]{1,8}(_[01]{8})*>'
70
71" Strings
72syn match embString display '\v\C"([^"\n\\]|\\[n\\"])*"'
73
74" Comments and documentation.
75syn match embComment display contains=embTodo '\v\C\#.*$'
76syn match embDocumentation display contains=embTodo '\v\C\-\- .*$'
77syn match embDocumentation display '\v\C\-\-$'
78syn match embBadDocumentation display '\v\C\-\-[^ ].*$'
79
80
81" Most Emboss constructs map neatly onto the standard Vim syntax types.
82hi def link embComment Comment
83hi def link embConstant Constant
84hi def link embIdentifier Identifier
85hi def link embNumber Number
86hi def link embOperator Operator
87hi def link embString String
88hi def link embStructure Structure
89hi def link embTodo Todo
90hi def link embType Type
91
92" SpecialComment seems to be the best match for embDocumentation, as it is used
93" for things like javadoc.
94hi def link embDocumentation SpecialComment
95hi def link embBadDocumentation Error
96hi def link embBadWord Error
97hi def link embBadNumber Error
98
99let b:current_syntax = 'emboss'