Ben Olmstead | c0d7784 | 2019-07-31 17:34:05 -0700 | [diff] [blame] | 1 | " 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. |
| 18 | if exists('b:current_syntax') |
| 19 | finish |
| 20 | endif |
| 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 | |
| 27 | syn clear |
| 28 | |
| 29 | " Emboss keywords. |
| 30 | syn keyword embStructure struct union enum bits external |
| 31 | syn keyword embKeyword $reserved $default |
| 32 | syn keyword embKeyword $static_size_in_bits $is_statically_sized this |
Faraaz Sareshwala | c49a9ec | 2022-07-06 16:52:23 -0700 | [diff] [blame] | 33 | syn keyword embKeyword $next $max $present $upper_bound $lower_bound |
Ben Olmstead | c0d7784 | 2019-07-31 17:34:05 -0700 | [diff] [blame] | 34 | syn keyword embKeyword import as |
| 35 | syn keyword embKeyword if let |
| 36 | syn keyword embBoolean true false |
| 37 | syn keyword embIdentifier $size_in_bits $size_in_bytes |
| 38 | syn keyword embIdentifier $max_size_in_bits $max_size_in_bytes |
| 39 | syn keyword embIdentifier $min_size_in_bits $min_size_in_bytes |
| 40 | |
| 41 | " Per standard convention, highlight to-do patterns in comments. |
| 42 | syn 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. |
| 48 | syn match embBadNumber display '\v\C<[0-9][0-9a-zA-Z_$]*>' |
| 49 | syn 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. |
| 53 | syn match embType display '\v\C<[A-Z][A-Z0-9]*[a-z][A-Za-z0-9]*>' |
| 54 | syn match embConstant display '\v\C<[A-Z][A-Z0-9_]+>' |
| 55 | syn match embIdentifier display '\v\C<[a-z][a-z0-9_]*>' |
| 56 | |
| 57 | " Decimal integers both with and without thousands separators. |
| 58 | syn match embNumber display '\v\C<\d+>' |
| 59 | syn match embNumber display '\v\C<\d{1,3}(_\d{3})*>' |
| 60 | |
| 61 | " Hex integers with and without word/doubleword separators. |
| 62 | syn match embNumber display '\v\C<0[xX]\x+>' |
| 63 | syn match embNumber display '\v\C<0[xX]\x{1,4}(_\x{4})*>' |
| 64 | syn match embNumber display '\v\C<0[xX]\x{1,8}(_\x{8})*>' |
| 65 | |
| 66 | " Binary integers with and without byte/nibble separators. |
| 67 | syn match embNumber display '\v\C<0[bB][01]+>' |
| 68 | syn match embNumber display '\v\C<0[bB][01]{1,4}(_[01]{4})*>' |
| 69 | syn match embNumber display '\v\C<0[bB][01]{1,8}(_[01]{8})*>' |
| 70 | |
| 71 | " Strings |
| 72 | syn match embString display '\v\C"([^"\n\\]|\\[n\\"])*"' |
| 73 | |
| 74 | " Comments and documentation. |
| 75 | syn match embComment display contains=embTodo '\v\C\#.*$' |
| 76 | syn match embDocumentation display contains=embTodo '\v\C\-\- .*$' |
| 77 | syn match embDocumentation display '\v\C\-\-$' |
| 78 | syn match embBadDocumentation display '\v\C\-\-[^ ].*$' |
| 79 | |
| 80 | |
| 81 | " Most Emboss constructs map neatly onto the standard Vim syntax types. |
| 82 | hi def link embComment Comment |
| 83 | hi def link embConstant Constant |
| 84 | hi def link embIdentifier Identifier |
| 85 | hi def link embNumber Number |
| 86 | hi def link embOperator Operator |
| 87 | hi def link embString String |
| 88 | hi def link embStructure Structure |
| 89 | hi def link embTodo Todo |
| 90 | hi def link embType Type |
| 91 | |
| 92 | " SpecialComment seems to be the best match for embDocumentation, as it is used |
| 93 | " for things like javadoc. |
| 94 | hi def link embDocumentation SpecialComment |
| 95 | hi def link embBadDocumentation Error |
| 96 | hi def link embBadWord Error |
| 97 | hi def link embBadNumber Error |
| 98 | |
| 99 | let b:current_syntax = 'emboss' |