Bram Moolenaar | 96f45c0 | 2019-10-26 19:53:45 +0200 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Meson |
| 3 | " License: VIM License |
| 4 | " Maintainer: Nirbheek Chauhan <nirbheek.chauhan@gmail.com> |
| 5 | " Last Change: 2019 Oct 18 |
| 6 | " Credits: Zvezdan Petkovic <zpetkovic@acm.org> |
| 7 | " Neil Schemenauer <nas@meson.ca> |
| 8 | " Dmitry Vasiliev |
| 9 | " |
| 10 | " This version is copied and edited from python.vim |
| 11 | " It's very basic, and doesn't do many things I'd like it to |
| 12 | " For instance, it should show errors for syntax that is valid in |
| 13 | " Python but not in Meson. |
| 14 | " |
| 15 | " Optional highlighting can be controlled using these variables. |
| 16 | " |
| 17 | " let meson_space_error_highlight = 1 |
| 18 | " |
| 19 | |
| 20 | " For version 5.x: Clear all syntax items. |
| 21 | " For version 6.x: Quit when a syntax file was already loaded. |
| 22 | if version < 600 |
| 23 | syntax clear |
| 24 | elseif exists("b:current_syntax") |
| 25 | finish |
| 26 | endif |
| 27 | |
| 28 | " We need nocompatible mode in order to continue lines with backslashes. |
| 29 | " Original setting will be restored. |
| 30 | let s:cpo_save = &cpo |
| 31 | set cpo&vim |
| 32 | |
| 33 | " http://mesonbuild.com/Syntax.html |
| 34 | syn keyword mesonConditional elif else if endif |
| 35 | syn keyword mesonRepeat foreach endforeach |
| 36 | syn keyword mesonOperator and not or |
| 37 | |
| 38 | syn match mesonComment "#.*$" contains=mesonTodo,@Spell |
| 39 | syn keyword mesonTodo FIXME NOTE NOTES TODO XXX contained |
| 40 | |
| 41 | " Strings can either be single quoted or triple counted across multiple lines, |
| 42 | " but always with a ' |
| 43 | syn region mesonString |
| 44 | \ start="\z('\)" end="\z1" skip="\\\\\|\\\z1" |
| 45 | \ contains=mesonEscape,@Spell |
| 46 | syn region mesonString |
| 47 | \ start="\z('''\)" end="\z1" keepend |
| 48 | \ contains=mesonEscape,mesonSpaceError,@Spell |
| 49 | |
| 50 | syn match mesonEscape "\\[abfnrtv'\\]" contained |
| 51 | syn match mesonEscape "\\\o\{1,3}" contained |
| 52 | syn match mesonEscape "\\x\x\{2}" contained |
| 53 | syn match mesonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained |
| 54 | " Meson allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ |
| 55 | syn match mesonEscape "\\N{\a\+\%(\s\a\+\)*}" contained |
| 56 | syn match mesonEscape "\\$" |
| 57 | |
| 58 | " Meson only supports integer numbers |
| 59 | " http://mesonbuild.com/Syntax.html#numbers |
| 60 | syn match mesonNumber "\<\d\+\>" |
| 61 | |
| 62 | " booleans |
| 63 | syn keyword mesonConstant false true |
| 64 | |
| 65 | " Built-in functions |
| 66 | syn keyword mesonBuiltin |
| 67 | \ add_global_arguments |
| 68 | \ add_global_link_arguments |
| 69 | \ add_languages |
| 70 | \ add_project_arguments |
| 71 | \ add_project_link_arguments |
| 72 | \ add_test_setup |
| 73 | \ alias_target |
| 74 | \ assert |
| 75 | \ benchmark |
| 76 | \ both_libraries |
| 77 | \ build_machine |
| 78 | \ build_target |
| 79 | \ configuration_data |
| 80 | \ configure_file |
| 81 | \ custom_target |
| 82 | \ declare_dependency |
| 83 | \ dependency |
| 84 | \ disabler |
| 85 | \ environment |
| 86 | \ error |
| 87 | \ executable |
| 88 | \ files |
| 89 | \ find_library |
| 90 | \ find_program |
| 91 | \ generator |
| 92 | \ get_option |
| 93 | \ get_variable |
| 94 | \ gettext |
| 95 | \ host_machine |
| 96 | \ import |
| 97 | \ include_directories |
| 98 | \ install_data |
| 99 | \ install_headers |
| 100 | \ install_man |
| 101 | \ install_subdir |
| 102 | \ is_disabler |
| 103 | \ is_variable |
| 104 | \ jar |
| 105 | \ join_paths |
| 106 | \ library |
| 107 | \ meson |
| 108 | \ message |
| 109 | \ option |
| 110 | \ project |
| 111 | \ run_command |
| 112 | \ run_target |
| 113 | \ set_variable |
| 114 | \ shared_library |
| 115 | \ shared_module |
| 116 | \ static_library |
| 117 | \ subdir |
| 118 | \ subdir_done |
| 119 | \ subproject |
| 120 | \ target_machine |
| 121 | \ test |
| 122 | \ vcs_tag |
| 123 | \ warning |
| 124 | |
| 125 | if exists("meson_space_error_highlight") |
| 126 | " trailing whitespace |
| 127 | syn match mesonSpaceError display excludenl "\s\+$" |
| 128 | " mixed tabs and spaces |
| 129 | syn match mesonSpaceError display " \+\t" |
| 130 | syn match mesonSpaceError display "\t\+ " |
| 131 | endif |
| 132 | |
| 133 | if version >= 508 || !exists("did_meson_syn_inits") |
| 134 | if version <= 508 |
| 135 | let did_meson_syn_inits = 1 |
| 136 | command -nargs=+ HiLink hi link <args> |
| 137 | else |
| 138 | command -nargs=+ HiLink hi def link <args> |
| 139 | endif |
| 140 | |
| 141 | " The default highlight links. Can be overridden later. |
| 142 | HiLink mesonStatement Statement |
| 143 | HiLink mesonConditional Conditional |
| 144 | HiLink mesonRepeat Repeat |
| 145 | HiLink mesonOperator Operator |
| 146 | HiLink mesonComment Comment |
| 147 | HiLink mesonTodo Todo |
| 148 | HiLink mesonString String |
| 149 | HiLink mesonEscape Special |
| 150 | HiLink mesonNumber Number |
| 151 | HiLink mesonBuiltin Function |
| 152 | HiLink mesonConstant Number |
| 153 | if exists("meson_space_error_highlight") |
| 154 | HiLink mesonSpaceError Error |
| 155 | endif |
| 156 | |
| 157 | delcommand HiLink |
| 158 | endif |
| 159 | |
| 160 | let b:current_syntax = "meson" |
| 161 | |
| 162 | let &cpo = s:cpo_save |
| 163 | unlet s:cpo_save |
| 164 | |
| 165 | " vim:set sw=2 sts=2 ts=8 noet: |