Ragel VIM syntax files should be specialized by host language.
[external/ragel.git] / ragel.vim
1 " Vim syntax file
2 "
3 " Language: Ragel
4 " Author: Adrian Thurston
5
6 syntax clear
7
8 "
9 " Outside code
10 "
11
12 " Comments
13 syntax region ocComment start="\/\*" end="\*\/"
14 syntax match ocComment "\/\/.*$"
15
16 " Anything preprocessor
17 syntax match ocPreproc "#.*$"
18
19 " Strings
20 syntax match ocLiteral "'\(\\.\|[^'\\]\)*'"
21 syntax match ocLiteral "\"\(\\.\|[^\"\\]\)*\""
22
23 " C/C++ Keywords
24 syntax keyword ocType unsigned signed void char short int long float double bool
25 syntax keyword ocType inline static extern register const volatile auto
26 syntax keyword ocType union enum struct class typedef
27 syntax keyword ocType namespace template typename mutable
28 syntax keyword ocKeyword break continue default do else for
29 syntax keyword ocKeyword goto if return switch while
30 syntax keyword ocKeyword new delete this using friend public private protected sizeof
31 syntax keyword ocKeyword throw try catch operator typeid
32 syntax keyword ocKeyword and bitor xor compl bitand and_eq or_eq xor_eq not not_eq
33 syntax keyword ocKeyword static_cast dynamic_cast
34
35 " Numbers
36 syntax match ocNumber "[0-9][0-9]*"
37 syntax match ocNumber "0x[0-9a-fA-F][0-9a-fA-F]*"
38
39 " Booleans
40 syntax keyword ocBoolean true false
41
42 " Identifiers
43 syntax match anyId "[a-zA-Z_][a-zA-Z_0-9]*"
44
45 " Inline code only
46 syntax keyword fsmType fpc fc fcurs fbuf fblen ftargs fstack
47 syntax keyword fsmKeyword fhold fgoto fcall fret fentry fnext fexec fbreak
48
49 syntax cluster rlItems contains=rlComment,rlLiteral,rlAugmentOps,rlOtherOps,rlKeywords,rlWrite,rlCodeCurly,rlCodeSemi,rlNumber,anyId,rlLabelColon,rlExprKeywords
50
51 syntax region machineSpec1 matchgroup=beginRL start="%%{" end="}%%" contains=@rlItems
52 syntax region machineSpec2 matchgroup=beginRL start="%%[^{]"rs=e-1 end="$" keepend contains=@rlItems
53 syntax region machineSpec2 matchgroup=beginRL start="%%$" end="$" keepend contains=@rlItems
54
55 " Comments
56 syntax match rlComment "#.*$" contained
57
58 " Literals
59 syntax match rlLiteral "'\(\\.\|[^'\\]\)*'[i]*" contained
60 syntax match rlLiteral "\"\(\\.\|[^\"\\]\)*\"[i]*" contained
61 syntax match rlLiteral /\/\(\\.\|[^\/\\]\)*\/[i]*/ contained
62 syntax match rlLiteral "\[\(\\.\|[^\]\\]\)*\]" contained
63
64 " Numbers
65 syntax match rlNumber "[0-9][0-9]*" contained
66 syntax match rlNumber "0x[0-9a-fA-F][0-9a-fA-F]*" contained
67
68 " Operators
69 syntax match rlAugmentOps "[>$%@]" contained
70 syntax match rlAugmentOps "<>\|<" contained
71 syntax match rlAugmentOps "[>\<$%@][!\^/*~]" contained
72 syntax match rlAugmentOps "[>$%]?" contained
73 syntax match rlAugmentOps "<>[!\^/*~]" contained
74 syntax match rlAugmentOps "=>" contained
75 syntax match rlOtherOps "->" contained
76
77 syntax match rlOtherOps ":>" contained
78 syntax match rlOtherOps ":>>" contained
79 syntax match rlOtherOps "<:" contained
80
81 " Keywords
82 " FIXME: Enable the range keyword post 5.17.
83 " syntax keyword rlKeywords machine action context include range contained
84 syntax keyword rlKeywords machine action context include import export prepush postpop contained
85 syntax keyword rlExprKeywords when inwhen outwhen err lerr eof from to contained
86
87 " Case Labels
88 syntax keyword caseLabelKeyword case contained
89 syntax cluster caseLabelItems contains=ocComment,ocPreproc,ocLiteral,ocType,ocKeyword,caseLabelKeyword,ocNumber,ocBoolean,anyId,fsmType,fsmKeyword
90 syntax match caseLabelColon "case" contains=@caseLabelItems
91 syntax match caseLabelColon "case[\t ]\+.*:$" contains=@caseLabelItems
92 syntax match caseLabelColon "case[\t ]\+.*:[^=:]"me=e-1 contains=@caseLabelItems
93
94 " Labels
95 syntax match ocLabelColon "^[\t ]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:$" contains=anyLabel
96 syntax match ocLabelColon "^[\t ]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:[^=:]"me=e-1 contains=anyLabel
97
98 syntax match rlLabelColon "[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:$" contained contains=anyLabel
99 syntax match rlLabelColon "[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:[^=:>]"me=e-1 contained contains=anyLabel
100 syntax match anyLabel "[a-zA-Z_][a-zA-Z_0-9]*" contained
101
102 " All items that can go in a code block.
103
104 syntax cluster inlineItems contains=rlCodeCurly,ocComment,ocPreproc,ocLiteral,ocType,ocKeyword,ocNumber,ocBoolean,ocLabelColon,anyId,fsmType,fsmKeyword,caseLabelColon
105
106 " Blocks of code. rlCodeCurly is recursive.
107 syntax region rlCodeCurly matchgroup=NONE start="{" end="}" contained contains=@inlineItems
108 syntax region rlCodeSemi matchgroup=Type start="\<alphtype\>" start="\<getkey\>" start="\<access\>" start="\<variable\>" matchgroup=NONE end=";" contained contains=@inlineItems
109
110 syntax region rlWrite matchgroup=Type start="\<write\>" matchgroup=NONE end="[;)]" contained contains=rlWriteKeywords,rlWriteOptions
111
112 syntax keyword rlWriteKeywords init data exec exports start error first_final contained
113 syntax keyword rlWriteOptions noerror nofinal noprefix noend nocs contained
114
115 "
116 " Sync at the start of machine specs.
117 "
118 " Match The ragel delimiters only if there quotes no ahead on the same line.
119 " On the open marker, use & to consume the leader.
120 syntax sync match ragelSyncPat grouphere NONE "^[^\'\"%]*%%{&^[^\'\"%]*"
121 syntax sync match ragelSyncPat grouphere NONE "^[^\'\"%]*%%[^{]&^[^\'\"%]*"
122 syntax sync match ragelSyncPat grouphere NONE "^[^\'\"]*}%%"
123
124 "
125 " Specifying Groups
126 "
127 hi link ocComment Comment
128 hi link ocPreproc Macro
129 hi link ocLiteral String
130 hi link ocType Type
131 hi link ocKeyword Keyword
132 hi link ocNumber Number
133 hi link ocBoolean Boolean
134 hi link rlComment Comment
135 hi link rlNumber Number
136 hi link rlLiteral String
137 hi link rlAugmentOps Keyword
138 hi link rlExprKeywords Keyword
139 hi link rlWriteKeywords Keyword
140 hi link rlWriteOptions Keyword
141 hi link rlKeywords Type
142 hi link fsmType Type
143 hi link fsmKeyword Keyword
144 hi link anyLabel Label
145 hi link caseLabelKeyword Keyword
146 hi link beginRL Type
147  
148 let b:current_syntax = "ragel"