1 " ninja build file syntax.
2 " Language: ninja build file as described at
3 " http://ninja-build.org/manual.html
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
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
15 if exists("b:current_syntax")
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 $
27 syn match ninjaComment /\(\$\n\)\@<!\_^\s*#.*$/ contains=@Spell
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\>"
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
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
49 syn region ninjaPool start="^pool" end="^\ze\S" contains=TOP transparent
50 syn keyword ninjaPoolCommand contained containedin=ninjaPool depth
52 " Strings are parsed as follows:
53 " lexer.in.cc, ReadEvalString()
54 " simple_varname = [a-zA-Z0-9_-]+;
55 " varname = [a-zA-Z0-9_.-]+;
57 " $\n -> line continuation
58 " '$ ' -> escaped space
59 " $simple_varname -> variable
60 " ${varname} -> variable
62 syn match ninjaDollar "\$\$"
63 syn match ninjaWrapLineOperator "\$$"
64 syn match ninjaSimpleVar "\$[a-zA-Z0-9_-]\+"
65 syn match ninjaVar "\${[a-zA-Z0-9_.-]\+}"
68 " variable assignment =
70 " implicit dependency |
71 " order-only dependency ||
72 syn match ninjaOperator "\(=\|:\||\|||\)\ze\s"
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
84 let b:current_syntax = "ninja"