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