Also have vim syntax-highlight type=network.
[asterisk/asterisk.git] / contrib / editors / asterisk.vim
1 " Vim syntax file
2 " Language:     Asterisk config file
3 " Maintainer:   tilghman
4 " Last Change:  2009 Mar 04 
5 " version 0.5
6 "
7 if version < 600
8   syntax clear
9 elseif exists("b:current_syntax")
10   finish
11 endif
12
13 syn sync clear
14 syn sync fromstart
15
16 syn keyword     asteriskTodo            TODO contained
17 syn match       asteriskComment         ";.*" contains=asteriskTodo
18 syn match       asteriskContext         "\[.\{-}\]"
19 syn match       asteriskExten           "^\s*exten\s*=>\?\s*[^,]\+" contains=asteriskPattern
20 syn match       asteriskExten           "^\s*\(register\|channel\|ignorepat\|include\|\(no\)\?load\)\s*=>\?"
21 syn match       asteriskPattern         "_\(\[[[:alnum:]#*\-]\+\]\|[[:alnum:]#*]\)*\.\?" contained
22 syn match       asteriskPattern         "[^A-Za-z0-9,]\zs[[:alnum:]#*]\+\ze" contained
23 syn match       asteriskApp             ",\zs[a-zA-Z]\+\ze$"
24 syn match       asteriskApp             ",\zs[a-zA-Z]\+\ze("
25 " Digits plus oldlabel (newlabel)
26 syn match       asteriskPriority        ",\zs[[:digit:]]\+\(+[[:alpha:]][[:alnum:]_]*\)\?\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
27 " oldlabel plus digits (newlabel)
28 syn match       asteriskPriority        ",\zs[[:alpha:]][[:alnum:]_]*+[[:digit:]]\+\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
29 " s or n plus digits (newlabel)
30 syn match       asteriskPriority        ",\zs[sn]\(+[[:digit:]]\+\)\?\(([[:alpha:]][[:alnum:]_]*)\)\?\ze," contains=asteriskLabel
31 syn match       asteriskLabel           "(\zs[[:alpha:]][[:alnum:]]*\ze)" contained
32 syn match       asteriskError           "^\s*#\s*[[:alnum:]]*"
33 syn match       asteriskInclude         "^\s*#\s*\(include\|exec\)\s.*"
34 syn region      asteriskVar             matchgroup=asteriskVarStart start="\${" end="}" contains=asteriskVar,asteriskFunction,asteriskExp
35 syn match       asteriskVar             "\zs[[:alpha:]][[:alnum:]_]*\ze=" contains=asteriskVar,asteriskFunction,asteriskExp
36 syn match       asteriskFunction        "\${_\{0,2}[[:alpha:]][[:alnum:]_]*(.*)}" contains=asteriskVar,asteriskFunction,asteriskExp
37 syn match       asteriskFunction        "(\zs[[:alpha:]][[:alnum:]_]*(.\{-})\ze=" contains=asteriskVar,asteriskFunction,asteriskExp
38 syn region      asteriskExp             matchgroup=asteriskExpStart start="\$\[" end="]" contains=asteriskVar,asteriskFunction,asteriskExp
39 syn match       asteriskCodecsPermit    "^\s*\(allow\|disallow\)\s*=\s*.*$" contains=asteriskCodecs
40 syn match       asteriskCodecs          "\(g723\|gsm\|ulaw\|alaw\|g726\|adpcm\|slin\|lpc10\|g729\|speex\|speex16\|ilbc\|all\s*$\)"
41 syn match       asteriskError           "^\(type\|auth\|permit\|deny\|bindaddr\|host\)\s*=.*$"
42 syn match       asteriskType            "^\zstype=\ze\<\(peer\|user\|friend\|phone\|line\|application\|network\)\>$" contains=asteriskTypeType
43 syn match       asteriskTypeType        "\<\(peer\|user\|friend\|phone\|line\|application\|network\)\>" contained
44 syn match       asteriskAuth            "^\zsauth\s*=\ze\s*\<\(md5\|rsa\|plaintext\)\>$" contains=asteriskAuthType
45 syn match       asteriskAuthType        "\<\(md5\|rsa\|plaintext\)\>" contained
46 syn match       asteriskAuth            "^\zs\(secret\|inkeys\|outkey\)\s*=\ze.*$"
47 syn match       asteriskAuth            "^\(permit\|deny\)\s*=\s*\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/\d\{1,3}\(\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\)\?\s*$" contains=asteriskIPRange
48 syn match       asteriskIPRange         "\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}" contained
49 syn match       asteriskIP              "\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}" contained
50 syn match       asteriskHostname        "\([[:alnum:]\-]*\.\)\+[[:alpha:]]\{2,10}" contained
51 syn match       asteriskPort            "\d\{1,5}" contained
52 syn match       asteriskSetting         "^\(tcp\|tls\)\?bindaddr\s*=\s*\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}$" contains=asteriskIP
53 syn match       asteriskError           "port\s*=.*$"
54 syn match       asteriskSetting         "^\(bind\)\?port\s*=\s*\d\{1,5}\s*$" contains=asteriskPort
55 syn match       asteriskSetting         "^host\s*=\s*\(dynamic\|\(\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\)\|\([[:alnum:]\-]*\.\)\+[[:alpha:]]\{2,10}\)" contains=asteriskIP,asteriskHostname
56 syn match               asteriskError                   "[[:space:]]$"
57
58 " Define the default highlighting.
59 " For version 5.7 and earlier: only when not done already
60 " For version 5.8 and later: only when an item doesn't have highlighting yet
61 if version >= 508 || !exists("did_conf_syntax_inits")
62   if version < 508
63     let did_conf_syntax_inits = 1
64     command -nargs=+ HiLink hi link <args>
65   else
66     command -nargs=+ HiLink hi def link <args>
67   endif
68
69   HiLink        asteriskComment         Comment
70   HiLink        asteriskExten           String
71   HiLink        asteriskContext         Preproc
72   HiLink        asteriskPattern         Type
73   HiLink        asteriskApp             Statement
74   HiLink        asteriskInclude         Preproc
75   HiLink        asteriskPriority        Preproc
76   HiLink        asteriskLabel           Type
77   HiLink        asteriskVar             String
78   HiLink        asteriskVarStart        String
79   HiLink        asteriskFunction        Function
80   HiLink        asteriskExp             Type
81   HiLink        asteriskExpStart        Type
82   HiLink        asteriskCodecsPermit    Preproc
83   HiLink        asteriskCodecs          String
84   HiLink        asteriskType            Statement
85   HiLink        asteriskTypeType        Type
86   HiLink        asteriskAuth            String
87   HiLink        asteriskAuthType        Type
88   HiLink        asteriskIPRange         Identifier
89   HiLink        asteriskIP              Identifier
90   HiLink        asteriskPort            Identifier
91   HiLink        asteriskHostname        Identifier
92   HiLink        asteriskSetting         Statement
93   HiLink        asteriskError           Error
94  delcommand HiLink
95 endif
96 let b:current_syntax = "asterisk" 
97 " vim: ts=8 sw=2
98