Imported Upstream version 1.9.0
[platform/upstream/ninja.git] / misc / ninja.vim
1 " ninja build file syntax.
2 " Language: ninja build file as described at
3 "           http://ninja-build.org/manual.html
4 " Version: 1.5
5 " Last Change: 2018/04/05
6 " Maintainer: Nicolas Weber <nicolasweber@gmx.de>
7 " Version 1.4 of this script is in the upstream vim repository and will be
8 " included in the next vim release. If you change this, please send your change
9 " upstream.
10
11 " ninja lexer and parser are at
12 " https://github.com/ninja-build/ninja/blob/master/src/lexer.in.cc
13 " https://github.com/ninja-build/ninja/blob/master/src/manifest_parser.cc
14
15 if exists("b:current_syntax")
16   finish
17 endif
18
19 let s:cpo_save = &cpo
20 set cpo&vim
21
22 syn case match
23
24 " Comments are only matched when the # is at the beginning of the line (with
25 " optional whitespace), as long as the prior line didn't end with a $
26 " continuation.
27 syn match ninjaComment /\(\$\n\)\@<!\_^\s*#.*$/  contains=@Spell
28
29 " Toplevel statements are the ones listed here and
30 " toplevel variable assignments (ident '=' value).
31 " lexer.in.cc, ReadToken() and manifest_parser.cc, Parse()
32 syn match ninjaKeyword "^build\>"
33 syn match ninjaKeyword "^rule\>"
34 syn match ninjaKeyword "^pool\>"
35 syn match ninjaKeyword "^default\>"
36 syn match ninjaKeyword "^include\>"
37 syn match ninjaKeyword "^subninja\>"
38
39 " Both 'build' and 'rule' begin a variable scope that ends
40 " on the first line without indent. 'rule' allows only a
41 " limited set of magic variables, 'build' allows general
42 " let assignments.
43 " manifest_parser.cc, ParseRule()
44 syn region ninjaRule start="^rule" end="^\ze\S" contains=TOP transparent
45 syn keyword ninjaRuleCommand contained containedin=ninjaRule command
46                                      \ deps depfile description generator
47                                      \ pool restat rspfile rspfile_content
48
49 syn region ninjaPool start="^pool" end="^\ze\S" contains=TOP transparent
50 syn keyword ninjaPoolCommand contained containedin=ninjaPool  depth
51
52 " Strings are parsed as follows:
53 " lexer.in.cc, ReadEvalString()
54 " simple_varname = [a-zA-Z0-9_-]+;
55 " varname = [a-zA-Z0-9_.-]+;
56 " $$ -> $
57 " $\n -> line continuation
58 " '$ ' -> escaped space
59 " $simple_varname -> variable
60 " ${varname} -> variable
61
62 syn match   ninjaDollar "\$\$"
63 syn match   ninjaWrapLineOperator "\$$"
64 syn match   ninjaSimpleVar "\$[a-zA-Z0-9_-]\+"
65 syn match   ninjaVar       "\${[a-zA-Z0-9_.-]\+}"
66
67 " operators are:
68 " variable assignment =
69 " rule definition :
70 " implicit dependency |
71 " order-only dependency ||
72 syn match ninjaOperator "\(=\|:\||\|||\)\ze\s"
73
74 hi def link ninjaComment Comment
75 hi def link ninjaKeyword Keyword
76 hi def link ninjaRuleCommand Statement
77 hi def link ninjaPoolCommand Statement
78 hi def link ninjaDollar ninjaOperator
79 hi def link ninjaWrapLineOperator ninjaOperator
80 hi def link ninjaOperator Operator
81 hi def link ninjaSimpleVar ninjaVar
82 hi def link ninjaVar Identifier
83
84 let b:current_syntax = "ninja"
85
86 let &cpo = s:cpo_save
87 unlet s:cpo_save