• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15if exists("b:current_syntax")
16  finish
17endif
18
19let s:cpo_save = &cpo
20set cpo&vim
21
22syn 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.
27syn 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()
32syn match ninjaKeyword "^build\>"
33syn match ninjaKeyword "^rule\>"
34syn match ninjaKeyword "^pool\>"
35syn match ninjaKeyword "^default\>"
36syn match ninjaKeyword "^include\>"
37syn 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()
44syn region ninjaRule start="^rule" end="^\ze\S" contains=TOP transparent
45syn keyword ninjaRuleCommand contained containedin=ninjaRule command
46                                     \ deps depfile description generator
47                                     \ pool restat rspfile rspfile_content
48
49syn region ninjaPool start="^pool" end="^\ze\S" contains=TOP transparent
50syn 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
62syn match   ninjaDollar "\$\$"
63syn match   ninjaWrapLineOperator "\$$"
64syn match   ninjaSimpleVar "\$[a-zA-Z0-9_-]\+"
65syn match   ninjaVar       "\${[a-zA-Z0-9_.-]\+}"
66
67" operators are:
68" variable assignment =
69" rule definition :
70" implicit dependency |
71" order-only dependency ||
72syn match ninjaOperator "\(=\|:\||\|||\)\ze\s"
73
74hi def link ninjaComment Comment
75hi def link ninjaKeyword Keyword
76hi def link ninjaRuleCommand Statement
77hi def link ninjaPoolCommand Statement
78hi def link ninjaDollar ninjaOperator
79hi def link ninjaWrapLineOperator ninjaOperator
80hi def link ninjaOperator Operator
81hi def link ninjaSimpleVar ninjaVar
82hi def link ninjaVar Identifier
83
84let b:current_syntax = "ninja"
85
86let &cpo = s:cpo_save
87unlet s:cpo_save
88