blob: a53567e5859759a4f4e7b202bb0ec81f7f5fd939 [file] [log] [blame]
Bram Moolenaar6ee8d892012-01-10 14:55:01 +01001" ninja build file syntax.
2" Language: ninja build file as described at
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +02003" http://ninja-build.org/manual.html
4" Version: 1.5
5" Last Change: 2018/04/05
Bram Moolenaar6ee8d892012-01-10 14:55:01 +01006" Maintainer: Nicolas Weber <nicolasweber@gmx.de>
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +02007" Version 1.5 of this script is in the upstream vim repository and will be
Bram Moolenaarff034192013-04-24 18:51:19 +02008" included in the next vim release. If you change this, please send your change
9" upstream.
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010010
11" ninja lexer and parser are at
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +020012" 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
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010014
15if exists("b:current_syntax")
16 finish
17endif
18
Bram Moolenaarff034192013-04-24 18:51:19 +020019let s:cpo_save = &cpo
20set cpo&vim
21
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010022syn case match
23
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +020024" 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
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020028
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010029" Toplevel statements are the ones listed here and
30" toplevel variable assignments (ident '=' value).
Bram Moolenaar0187ca02013-04-12 15:09:51 +020031" lexer.in.cc, ReadToken() and manifest_parser.cc, Parse()
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010032syn match ninjaKeyword "^build\>"
33syn match ninjaKeyword "^rule\>"
Bram Moolenaar0187ca02013-04-12 15:09:51 +020034syn match ninjaKeyword "^pool\>"
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010035syn 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.
Bram Moolenaar0187ca02013-04-12 15:09:51 +020043" manifest_parser.cc, ParseRule()
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +020044syn region ninjaRule start="^rule" end="^\ze\S" contains=TOP transparent
45syn keyword ninjaRuleCommand contained containedin=ninjaRule command
46 \ deps depfile description generator
Bram Moolenaarff034192013-04-24 18:51:19 +020047 \ pool restat rspfile rspfile_content
Bram Moolenaar0187ca02013-04-12 15:09:51 +020048
Bram Moolenaar51ad4ea2018-04-06 11:14:11 +020049syn region ninjaPool start="^pool" end="^\ze\S" contains=TOP transparent
50syn keyword ninjaPoolCommand contained containedin=ninjaPool depth
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010051
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
Bram Moolenaar822ff862014-06-12 21:46:14 +020062syn match ninjaDollar "\$\$"
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010063syn 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
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020074hi def link ninjaComment Comment
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010075hi def link ninjaKeyword Keyword
76hi def link ninjaRuleCommand Statement
Bram Moolenaar0187ca02013-04-12 15:09:51 +020077hi def link ninjaPoolCommand Statement
Bram Moolenaar822ff862014-06-12 21:46:14 +020078hi def link ninjaDollar ninjaOperator
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010079hi 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"
Bram Moolenaarff034192013-04-24 18:51:19 +020085
86let &cpo = s:cpo_save
87unlet s:cpo_save