robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:86b4816766d9 (#21314)3576776903

master
5.5 KiB120 linesraw
1" Vim syntax file
2" Language: rego policy language
3" Maintainer: Matt Dunford (zenmatic@gmail.com)
4" URL:        https://github.com/zenmatic/vim-syntax-rego
5" Last Change: 2022 Dec 4
6
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
17syn keyword regoKeywords as default else every false if import package not null true with some in print
18
19syn keyword regoFuncAggregates count sum product max min sort all any
20syn match regoFuncArrays "\<array\.\(concat\|slice\|reverse\)\>"
21syn keyword regoFuncSets intersection union
22
23syn 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\)\>"
25syn match regoFuncStrings3 "\<contains\>"
26
27syn keyword regoFuncRegex re_match
28syn match regoFuncRegex2 "\<regex\.\(is_valid\|split\|globs_match\|template_match\|find_n\|find_all_string_submatch_n\|replace\)\>"
29
30syn 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\)\>"
33syn match regoFuncGlob "\<glob\.\(match\|quote_meta\)\>"
34syn match regoFuncUnits "\<units\.parse\(_bytes\)\=\>"
35syn keyword regoFuncTypes is_number is_string is_boolean is_array is_set is_object is_null type_name
36syn 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\)\>"
41syn match regoFuncTokenSigning "\<io\.jwt\.\(encode_sign_raw\|encode_sign\)\>"
42syn 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\)"
48syn keyword regoFuncGraphs walk
49syn match regoFuncGraphs2 "\<graph\.reachable\(_paths\)\=\>"
50syn match regoFuncGraphQl "\<graphql\.\(\(schema_\)\=is_valid\|parse\(_\(and_verify\|query\|schema\)\)\=\)\>"
51syn match regoFuncHttp "\<http\.send\>"
52syn 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\)\)\>"
54syn match regoFuncOpa "\<opa\.runtime\>"
55syn keyword regoFuncDebugging trace
56syn match regoFuncRand "\<rand\.intn\>"
57
58syn 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
67hi 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
83hi def link regoFuncEncoding4 Statement
84hi def link regoFuncEncoding5 Statement
85hi def link regoFuncTokenSigning Statement
86hi def link regoFuncTokenVerification1 Statement
87hi def link regoFuncTokenVerification2 Statement
88hi def link regoFuncTime Statement
89hi def link regoFuncCryptography Statement
90hi def link regoFuncGraphs Statement
91hi def link regoFuncGraphQl Statement
92hi def link regoFuncGraphs2 Statement
93hi def link regoFuncHttp Statement
94hi def link regoFuncNet Statement
95hi def link regoFuncRego Statement
96hi def link regoFuncOpa Statement
97hi def link regoFuncDebugging Statement
98hi 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
104
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'