[PATCH] Contrib: vim syntax, support block region

OOO othree at gmail.com
Fri Mar 10 16:43:54 UTC 2017


Hi Dounin

Do you have any idea about this implementation for ngxBlock.
If you think this approach is ok.
I will keep going in this direction.
And send more robust(maybe) patch later.



2017-03-04 19:59 GMT+08:00 othree <othree at gmail.com>:
> # HG changeset patch
> # User othree <othree at gmail.com>
> # Date 1488628696 -28800
> #      Sat Mar 04 19:58:16 2017 +0800
> # Node ID a244d5f635ebf90cd30c42f826810b9bf5d53f3c
> # Parent  7fca6f60d5cafa0127b5bc4d6b74fcd06ab532a3
> Contrib: vim syntax, support block region.
>
> diff --git a/contrib/vim/syntax/nginx.vim b/contrib/vim/syntax/nginx.vim
> --- a/contrib/vim/syntax/nginx.vim
> +++ b/contrib/vim/syntax/nginx.vim
> @@ -4,43 +4,66 @@
>  if exists("b:current_syntax")
>    finish
>  end
>
>  setlocal iskeyword+=.
>  setlocal iskeyword+=/
>  setlocal iskeyword+=:
>
> -syn match ngxVariable '\$\(\w\+\|{\w\+}\)'
> -syn match ngxVariableBlock '\$\(\w\+\|{\w\+}\)' contained
> -syn match ngxVariableString '\$\(\w\+\|{\w\+}\)' contained
> -syn region ngxBlock start=+^+ end=+{+ skip=+\${+ contains=ngxComment,ngxDirectiveBlock,ngxVariableBlock,ngxString oneline
> -syn region ngxString start=+[^:a-zA-Z>!\\@]\z(["']\)+lc=1 end=+\z1+ skip=+\\\\\|\\\z1+ contains=ngxVariableString
> -syn match ngxComment ' *#.*$'
> +syn match   ngxVariable       '\$\(\w\+\|{\w\+}\)'
> +syn match   ngxVariableString '\$\(\w\+\|{\w\+}\)' contained
> +
> +syn region  ngxString  start=+\%(^\|\s\)\zs\z(["']\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=ngxVariableString
> +syn region  ngxComment start=+\%(^\|\s\)\zs#+ end=+$+ oneline
>
>  syn keyword ngxBoolean on
>  syn keyword ngxBoolean off
>
> -syn keyword ngxDirectiveBlock http         contained
> -syn keyword ngxDirectiveBlock mail         contained
> -syn keyword ngxDirectiveBlock events       contained
> -syn keyword ngxDirectiveBlock server       contained
> -syn keyword ngxDirectiveBlock types        contained
> -syn keyword ngxDirectiveBlock location     contained
> -syn keyword ngxDirectiveBlock upstream     contained
> -syn keyword ngxDirectiveBlock charset_map  contained
> -syn keyword ngxDirectiveBlock limit_except contained
> -syn keyword ngxDirectiveBlock if           contained
> -syn keyword ngxDirectiveBlock geo          contained
> -syn keyword ngxDirectiveBlock map          contained
> -syn keyword ngxDirectiveBlock split_clients contained
> +syn match   ngxDirectiveBlockParams /\S\+/ contains=ngxVariableString contained nextgroup=ngxDirectiveBlockParams,ngxBlock skipwhite skipempty
> +syn match   ngxDirectiveBlockParam1 /\S\+/ contains=ngxVariableString contained nextgroup=ngxDirectiveBlockParam2 skipwhite skipempty
> +syn match   ngxDirectiveBlockParam2 /\S\+/ contains=ngxVariableString contained nextgroup=ngxBlock skipwhite skipempty
> +syn region  ngxDirectiveBlockParams start=+\%(^\|\s\)\zs\z(["']\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=ngxVariableString contained nextgroup=ngxDirectiveBlockParams,ngxBlock skipwhite skipempty
> +syn region  ngxDirectiveBlockParam1 start=+\%(^\|\s\)\zs\z(["']\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=ngxVariableString contained nextgroup=ngxDirectiveBlockParam2 skipwhite skipempty
> +syn region  ngxDirectiveBlockParam2 start=+\%(^\|\s\)\zs\z(["']\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=ngxVariableString contained nextgroup=ngxBlock skipwhite skipempty
> +
> +syn cluster ngxDirectives      contains=ngxDirectiveBlock,ngxDirectiveImportant,ngxDirectiveControl,ngxDirectiveError,ngxDirectiveDeprecated,ngxDirective,ngxDirectiveThirdParty
> +syn cluster ngxBlockDirectives contains=@ngxDirectives,ngxReservedMainContextDirective
> +syn cluster ngxBlockElements   contains=@ngxBlockDirectives,ngxVariable,ngxString,ngxComment,ngxBoolean
> +
> +syn region  ngxBlock         start=+{+ end=+}+ contained contains=@ngxBlockElements
> +syn region  ngxServerBlock   start=+{+ end=+}+ contained contains=@ngxBlockElements,ngxReservedServerContextDirective
> +syn region  ngxUpstreamBlock start=+{+ end=+}+ contained contains=@ngxBlockElements,ngxDirectiveServer
> +
> +syn keyword ngxDirectiveBlock http          nextgroup=ngxBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock mail          nextgroup=ngxBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock events        nextgroup=ngxBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock server        nextgroup=ngxServerBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock types         nextgroup=ngxBlock skipwhite skipempty
> +
> +syn match   ngxLocationPath     /\S\+/ contained nextgroup=ngxBlock skipwhite skipempty
> +syn region  ngxLocationPath     start=+\%(^\|\s\)\zs\z(["']\)+lc=1 end=+\z1+ skip=+\\\\\|\\\z1+ contains=ngxVariableString contained nextgroup=ngxBlock skipwhite skipempty
> +syn match   ngxLocationOperator /\(=\|\~\*\|\^\~\|\~\)/ contained nextgroup=ngxLocationPath skipwhite skipempty
> +syn match   ngxLocationNamedLoc /@\w\+/
> +syn keyword ngxDirectiveBlock location      nextgroup=ngxLocationNamedLoc,ngxLocationOperator,ngxLocationPath,ngxString skipwhite skipempty
> +
> +syn keyword ngxDirectiveBlock upstream      nextgroup=ngxUpstreamBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock charset_map   nextgroup=ngxDirectiveBlockParam1 skipwhite skipempty
> +syn keyword ngxDirectiveBlock limit_except  nextgroup=ngxDirectiveBlockParams skipwhite skipempty
> +syn keyword ngxDirectiveBlock if            nextgroup=ngxBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock geo           nextgroup=ngxBlock skipwhite skipempty
> +syn keyword ngxDirectiveBlock map           nextgroup=ngxDirectiveBlockParam1 skipwhite skipempty
> +syn keyword ngxDirectiveBlock split_clients nextgroup=ngxDirectiveBlockParam1 skipwhite skipempty
> +
> +syn keyword ngxReservedMainContextDirective   http contained
> +syn keyword ngxReservedServerContextDirective server contained
>
>  syn keyword ngxDirectiveImportant include
>  syn keyword ngxDirectiveImportant root
> -syn keyword ngxDirectiveImportant server
> +syn keyword ngxDirectiveServer    server contained
>  syn keyword ngxDirectiveImportant server_name
>  syn keyword ngxDirectiveImportant listen contained
>  syn region  ngxDirectiveImportantListen matchgroup=ngxDirectiveImportant start=+listen+ skip=+\\\\\|\\\;+ end=+;+he=e-1 contains=ngxListenOptions,ngxString
>  syn keyword ngxDirectiveImportant internal
>  syn keyword ngxDirectiveImportant proxy_pass
>  syn keyword ngxDirectiveImportant memcached_pass
>  syn keyword ngxDirectiveImportant fastcgi_pass
>  syn keyword ngxDirectiveImportant scgi_pass
> @@ -2118,24 +2141,26 @@ syn keyword ngxDirectiveThirdParty xss_i
>  " ZIP Module <https://www.nginx.com/resources/wiki/modules/zip/>
>  " ZIP archiver for nginx
>
>
>  " highlight
>
>  hi link ngxComment Comment
>  hi link ngxVariable Identifier
> -hi link ngxVariableBlock Identifier
>  hi link ngxVariableString PreProc
> -hi link ngxBlock Normal
>  hi link ngxString String
> +hi link ngxLocationOperator Operator
> +hi link ngxLocationPath String
> +hi link ngxLocationNamedLoc Identifier
>
>  hi link ngxBoolean Boolean
>  hi link ngxDirectiveBlock Statement
>  hi link ngxDirectiveImportant Type
> +hi link ngxDirectiveServer ngxDirectiveImportant
>  hi link ngxDirectiveControl Keyword
>  hi link ngxDirectiveError Constant
>  hi link ngxDirectiveDeprecated Error
>  hi link ngxDirective Identifier
>  hi link ngxDirectiveThirdParty Special
>
>  hi link ngxListenOptions Keyword
>  hi link ngxMailProtocol Keyword



-- 
OOO


More information about the nginx-devel mailing list