blob: bc82030488591789bdf65dd0c426d6bf65f86e74 [file] [log] [blame]
Bram Moolenaar95a9dd12019-12-19 22:12:03 +01001" Vim syntax file
2" Language: rego policy language
3" Maintainer: Matt Dunford (zenmatic@gmail.com)
4" URL: https://github.com/zenmatic/vim-syntax-rego
Bram Moolenaar86b48162022-12-06 18:20:10 +00005" Last Change: 2022 Dec 4
Bram Moolenaar95a9dd12019-12-19 22:12:03 +01006
7" https://www.openpolicyagent.org/docs/latest/policy-language/
8
9" quit when a (custom) syntax file was already loaded
10if exists("b:current_syntax")
11 finish
12endif
13
14syn case match
15
16syn keyword regoDirective package import allow deny
Bram Moolenaar86b48162022-12-06 18:20:10 +000017syn keyword regoKeywords as default else every false if import package not null true with some in print
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010018
19syn keyword regoFuncAggregates count sum product max min sort all any
Bram Moolenaar86b48162022-12-06 18:20:10 +000020syn match regoFuncArrays "\<array\.\(concat\|slice\|reverse\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010021syn keyword regoFuncSets intersection union
22
Bram Moolenaar86b48162022-12-06 18:20:10 +000023syn keyword regoFuncStrings concat /\<contains\>/ endswith format_int indexof indexof_n lower replace split sprintf startswith substring trim trim_left trim_prefix trim_right trim_suffix trim_space upper
24syn match regoFuncStrings2 "\<strings\.\(replace_n\|reverse\|any_prefix_match\|any_suffix_match\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010025syn match regoFuncStrings3 "\<contains\>"
26
27syn keyword regoFuncRegex re_match
Bram Moolenaar86b48162022-12-06 18:20:10 +000028syn match regoFuncRegex2 "\<regex\.\(is_valid\|split\|globs_match\|template_match\|find_n\|find_all_string_submatch_n\|replace\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010029
Bram Moolenaar86b48162022-12-06 18:20:10 +000030syn match regoFuncUuid "\<uuid.rfc4122\>"
31syn match regoFuncBits "\<bits\.\(or\|and\|negate\|xor\|lsh\|rsh\)\>"
32syn match regoFuncObject "\<object\.\(get\|remove\|subset\|union\|union_n\|filter\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010033syn match regoFuncGlob "\<glob\.\(match\|quote_meta\)\>"
Bram Moolenaar86b48162022-12-06 18:20:10 +000034syn match regoFuncUnits "\<units\.parse\(_bytes\)\=\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010035syn keyword regoFuncTypes is_number is_string is_boolean is_array is_set is_object is_null type_name
Bram Moolenaar86b48162022-12-06 18:20:10 +000036syn match regoFuncEncoding1 "\<base64\.\(encode\|decode\|is_valid\)\>"
37syn match regoFuncEncoding2 "\<base64url\.\(encode\(_no_pad\)\=\|decode\)\>"
38syn match regoFuncEncoding3 "\<urlquery\.\(encode\|decode\|\(en\|de\)code_object\)\>"
39syn match regoFuncEncoding4 "\<\(json\|yaml\)\.\(is_valid\|marshal\|unmarshal\)\>"
40syn match regoFuncEncoding5 "\<json\.\(filter\|patch\|remove\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010041syn match regoFuncTokenSigning "\<io\.jwt\.\(encode_sign_raw\|encode_sign\)\>"
Bram Moolenaar86b48162022-12-06 18:20:10 +000042syn match regoFuncTokenVerification1 "\<io\.jwt\.\(decode\|decode_verify\)\>"
43syn match regoFuncTokenVerification2 "\<io\.jwt\.verify_\(rs\|ps\|es\|hs\)\(256\|384\|512\)\>"
44syn match regoFuncTime "\<time\.\(now_ns\|parse_ns\|parse_rfc3339_ns\|parse_duration_ns\|date\|clock\|weekday\|diff\|add_date\)\>"
45syn match regoFuncCryptography "\<crypto\.x509\.\(parse_certificates\|parse_certificate_request\|parse_and_verify_certificates\|parse_rsa_private_key\)\>"
46syn match regoFuncCryptography "\<crypto\.\(md5\|sha1\|sha256\)"
47syn match regoFuncCryptography "\<crypto\.hmac\.\(md5\|sha1\|sha256\|sha512\)"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010048syn keyword regoFuncGraphs walk
Bram Moolenaar86b48162022-12-06 18:20:10 +000049syn match regoFuncGraphs2 "\<graph\.reachable\(_paths\)\=\>"
50syn match regoFuncGraphQl "\<graphql\.\(\(schema_\)\=is_valid\|parse\(_\(and_verify\|query\|schema\)\)\=\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010051syn match regoFuncHttp "\<http\.send\>"
Bram Moolenaar86b48162022-12-06 18:20:10 +000052syn match regoFuncNet "\<net\.\(cidr_merge\|cidr_contains\|cidr_contains_matches\|cidr_intersects\|cidr_expand\|lookup_ip_addr\|cidr_is_valid\)\>"
53syn match regoFuncRego "\<rego\.\(parse_module\|metadata\.\(rule\|chain\)\)\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010054syn match regoFuncOpa "\<opa\.runtime\>"
55syn keyword regoFuncDebugging trace
Bram Moolenaar86b48162022-12-06 18:20:10 +000056syn match regoFuncRand "\<rand\.intn\>"
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010057
Bram Moolenaar86b48162022-12-06 18:20:10 +000058syn match regoFuncNumbers "\<numbers\.\(range\|intn\)\>"
59syn keyword regoFuncNumbers round ceil floor abs
60
61syn match regoFuncSemver "\<semver\.\(is_valid\|compare\)\>"
62syn keyword regoFuncConversions to_number
63syn match regoFuncHex "\<hex\.\(encode\|decode\)\>"
64
65hi def link regoFuncUuid Statement
66hi def link regoFuncBits Statement
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010067hi def link regoDirective Statement
68hi def link regoKeywords Statement
69hi def link regoFuncAggregates Statement
70hi def link regoFuncArrays Statement
71hi def link regoFuncSets Statement
72hi def link regoFuncStrings Statement
73hi def link regoFuncStrings2 Statement
74hi def link regoFuncStrings3 Statement
75hi def link regoFuncRegex Statement
76hi def link regoFuncRegex2 Statement
77hi def link regoFuncGlob Statement
78hi def link regoFuncUnits Statement
79hi def link regoFuncTypes Statement
80hi def link regoFuncEncoding1 Statement
81hi def link regoFuncEncoding2 Statement
82hi def link regoFuncEncoding3 Statement
Bram Moolenaar86b48162022-12-06 18:20:10 +000083hi def link regoFuncEncoding4 Statement
84hi def link regoFuncEncoding5 Statement
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010085hi def link regoFuncTokenSigning Statement
Bram Moolenaar86b48162022-12-06 18:20:10 +000086hi def link regoFuncTokenVerification1 Statement
87hi def link regoFuncTokenVerification2 Statement
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010088hi def link regoFuncTime Statement
89hi def link regoFuncCryptography Statement
90hi def link regoFuncGraphs Statement
Bram Moolenaar86b48162022-12-06 18:20:10 +000091hi def link regoFuncGraphQl Statement
92hi def link regoFuncGraphs2 Statement
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010093hi def link regoFuncHttp Statement
94hi def link regoFuncNet Statement
95hi def link regoFuncRego Statement
96hi def link regoFuncOpa Statement
97hi def link regoFuncDebugging Statement
Bram Moolenaar86b48162022-12-06 18:20:10 +000098hi def link regoFuncObject Statement
99hi def link regoFuncNumbers Statement
100hi def link regoFuncSemver Statement
101hi def link regoFuncConversions Statement
102hi def link regoFuncHex Statement
103hi def link regoFuncRand Statement
Bram Moolenaar95a9dd12019-12-19 22:12:03 +0100104
105" https://www.openpolicyagent.org/docs/latest/policy-language/#strings
106syn region regoString start=+"+ skip=+\\\\\|\\"+ end=+"+
107syn region regoRawString start=+`+ end=+`+
108
109hi def link regoString String
110hi def link regoRawString String
111
112" Comments; their contents
113syn keyword regoTodo contained TODO FIXME XXX BUG
114syn cluster regoCommentGroup contains=regoTodo
115syn region regoComment start="#" end="$" contains=@regoCommentGroup,@Spell
116
117hi def link regoComment Comment
118hi def link regoTodo Todo
119
120let b:current_syntax = 'rego'