summaryrefslogtreecommitdiffstats
path: root/syntax/cnp.vim
diff options
context:
space:
mode:
Diffstat (limited to 'syntax/cnp.vim')
-rw-r--r--syntax/cnp.vim113
1 files changed, 113 insertions, 0 deletions
diff --git a/syntax/cnp.vim b/syntax/cnp.vim
new file mode 100644
index 0000000..da9f4ba
--- /dev/null
+++ b/syntax/cnp.vim
@@ -0,0 +1,113 @@
+" Vim syntax file
+" Language: CNP 0.3rc1
+" Maintainer: <clsr@clsr.net>
+" Last Change: 2017-08-05
+" Version: 0.1.0-dev
+
+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', 'bytes:\(0\|[1-9][0-9]*\)\?-\(0\|[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: