1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
" Vim syntax file
" Language: CNP 0.4
" Maintainer: <clsr@clsr.net>
" Last Change: 2017-08-29
" Version: 0.2.0
if !exists('g:main_syntax')
if exists('b:current_syntax')
finish
endif
let g:main_syntax = 'cnp'
syn sync minlines=50
endif
function! s:generateParamKey(kname, vname, key)
exe 'syn match cnpKey' . a:kname . ' "' . a:key . '=" contained contains=cnpParameterEquals nextgroup=cnpVal' . a:vname . ',cnpError'
exe 'syn cluster cnpDefinedParams add=cnpKey' . a:kname
exe 'hi def link cnpKey' . a:kname . ' cnpParameterKey'
endfunction
function! s:generateParamVal(vname, value)
exe 'syn match cnpVal' . a:vname . ' "' . a:value . '" contained contains=cnpEscape nextgroup=cnpError'
exe 'hi def link cnpVal' . a:vname . ' cnpParameterValue'
endfunction
syn match cnpError ".*"
syn match cnpCR "\r$"
if g:main_syntax ==# 'cnp'
syn match cnpVersion "^cnp/\(0\|[1-9][0-9]*\)\.\(0\|[1-9][0-9]*\)" contains=cnpSupported,cnpUnsupported nextgroup=cnpIntent
else " allow embedding in e.g. markdown or cnm with indent
syn match cnpVersion "^\s*cnp/\(0\|[1-9][0-9]*\)\.\(0\|[1-9][0-9]*\)" contains=cnpSupported,cnpUnsupported nextgroup=cnpIntent
endif
syn match cnpUnsupported "cnp/\d\+\.\d\+" contained
syn match cnpSupported "cnp/0\.3" contained
syn match cnpSupported "cnp/0\.4" contained
syn match cnpIntent " \([^\n=\\ ]\|\\[n_0\\-]\)\+\n\?" contained contains=cnpError,cnpIntentMisc,cnpIntentResponse,cnpIntentRequest keepend nextgroup=cnpParameters,cnpBody
syn match cnpIntentMisc " \([^/\n=\\ ]\|\\[n_0\\-]\)\+" contained contains=cnpEscape
syn match cnpIntentResponse " ok\>" contained
syn match cnpIntentResponse " not_modified\>" contained
syn match cnpIntentResponse " redirect\>" contained
syn match cnpIntentResponse " error\>" contained
syn match cnpIntentRequest " \([^/\n=\\ ]\|\\[n_0\\-]\)*/" contained nextgroup=cnpIntentFilename contains=cnpIntentSlash,cnpEscape
syn match cnpIntentFilename "\([^/\n=\\ ]\|\\[n_0\\-]\)\+" contained nextgroup=cnpIntentSlash contains=cnpEscape
syn match cnpIntentSlash "/\+" contained nextgroup=cnpIntentFilename
syn region cnpParameters start=" " end="\n\+" contains=cnpError,cnpParameter contained nextgroup=cnpBody
syn match cnpParameter " \([^\n=\\ ]\|\\[n_0\\-]\)*=\([^\n=\\ ]\|\\[n_0\\-]\)*" contained contains=cnpParameterKey,@cnpDefinedParams keepend nextgroup=cnpParameter
syn match cnpParameterKey "\([^\n=\\ ]\|\\[n_0\\-]\)*" contained nextgroup=cnpParameterEquals contains=cnpEscape
syn match cnpParameterEquals "=" contained nextgroup=cnpParameterValue
syn match cnpParameterValue "\([^\n=\\ ]\|\\[n_0\\-]\)*" contained contains=cnpEscape,cnpCR
syn region cnpBody start="^" end="\%$" contained
"syn match cnpBody "\_.*" contained
syn match cnpEscape "\\[n_0\\-]" contained
call s:generateParamKey('Length', 'Number', 'length')
call s:generateParamVal('Number', '0\|[1-9][0-9]*')
call s:generateParamKey('Type', 'MIME', 'type')
call s:generateParamVal('MIME', '\(x-\)\?[a-z]\+/\([a-zA-Z0-9+._-]\+\|\*\)')
call s:generateParamKey('Name', 'Filename', 'name')
call s:generateParamVal('Filename', '\([^\n=\\/ ]\|\\[n_\\-]\)*')
call s:generateParamKey('Time', 'RFC3339', 'time')
call s:generateParamKey('Modified', 'RFC3339', 'modified')
call s:generateParamKey('IfModified', 'RFC3339', 'if_modified')
call s:generateParamVal('RFC3339', '\d\{4}-\d\{2}-\d\{2}T\d\{2}:\d\{2}:\d\{2}Z')
call s:generateParamKey('Location', 'ReqIntent', 'location')
call s:generateParamVal('ReqIntent', '\([^/\n=\\ ]\|\\[n_\\-]\)*\(/\([^/\n=\\ ]\|\\[n_\\-]\)*\)\+')
call s:generateParamKey('Reason', 'Reason', 'reason')
call s:generateParamVal('Reason', '\<\(syntax\|version\|invalid\|not_supported\|too_large\|not_found\|denied\|rejected\|server_error\)\>')
call s:generateParamKey('Select', 'Selector', 'select')
call s:generateParamVal('Selector', 'byte:\(0\|[1-9][0-9]*\)\?-\(0\|[1-9][0-9]*\)\?')
call s:generateParamVal('Selector', 'info:')
call s:generateParamVal('Selector', 'cnm:!\?')
call s:generateParamVal('Selector', 'cnm:!\?/\(\([^ /]\+\)\(/[^ /]\+\)*\)\?')
call s:generateParamVal('Selector', 'cnm:!\?#[^ /]*')
call s:generateParamVal('Selector', 'cnm:!\?\$\(\([1-9][0-9]*\)\(\.[1-9][0-9]*\)*\)\?')
hi def link cnpError Error
hi def link cnpUnsupported TODO
hi def link cnpSupported Keyword
hi def link cnpIntentRequest Identifier
hi def link cnpIntentSlash String
hi def link cnpIntentFilename String
hi def link cnpIntentResponse Special
hi def link cnpIntentMisc TODO
hi def link cnpParameterKey Identifier
hi def link cnpParameterEquals Special
hi def link cnpParameterValue String
hi def link cnpEscape Special
hi def link cnpBody Comment
hi def link cnpCR TODO
let b:current_syntax = 'cnp'
if g:main_syntax ==# 'cnp'
unlet g:main_syntax
endif
" vim: set noet:
|