-
Notifications
You must be signed in to change notification settings - Fork 10
/
gams.vim
371 lines (299 loc) · 12.2 KB
/
gams.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
" Vim syntax file
" Language: gams
" Filenames: *.gms
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
" gams is not case sensitive
syn case ignore
" KEYWORDS
" for model definition and solve
" gams statements defined as regions below: set, parameter, model, equation, variable, Table
syn keyword gamsStatement Solve using
syn keyword gamsStatement display
syn keyword gamsStatement option
syn keyword gamsStatement Alias
syn keyword gamsStatement Scalar
syn keyword gamsStatement sameas abort
syn keyword gamsStatement free semicont semiint sos1 sos2 binary integer
syn keyword gamsStatement positive negative
syn keyword gamsStatement xxpto
" model types
syn keyword gamsStatement lp mip nlp mcp mpec cns dnlp minlp qcp
syn keyword gamsStatement miqcp rmip rminlp rmiqcp
" external utilities
syn keyword gamsStatement put file putclose putpage puttl puthd
" control structures and logical operators
syn keyword gamsConditional if else Elseif ifi exist IFE
syn keyword gamsConditional ne ge le eq gt lt
syn keyword gamsRepeat loop while repeat until
syn keyword gamsRepeat for to Downto By
" logical and math operators
syn match gamsMathsOperator "-\|=\|[:+^/\\]"
syn match gamsMathsOperator "\A\(AND\|OR\|XOR\|NOT\)\A"hs=s+1,he=e-1
" math and statistical functions
syntax keyword gamsFunction ABS ASC sigmoid sum prod
syntax keyword gamsFunction acos acosh asin asinh atan atan2
syntax keyword gamsFunction atanh ceil ctime cos cosh exp floor log log10
syntax keyword gamsFunction max min precision round sin sinh sqrt tan tanh sqrt
syntax keyword gamsFunction smax smin
syntax keyword gamsFunction time trunc div
syntax keyword gamsFunction beta betareg binomial edist entropy errorf fact
syntax keyword gamsFunction gamma gammareg logbeta loggamma normal
syntax keyword gamsFunction mapval mod ncpcm ncpf pi poly power
syntax keyword gamsFunction sign trunc uniform uniformint
" execution time gdx commands
syn keyword gamsSpecial execute_load execute_unload
" usually dollar commands are put to the first position within the line
" but if there is an $if[ie] command before...
syn match gamsSpecial "\$option"
syn match gamsSpecial "\$call"
syn match gamsSpecial "\$eval"
syn match gamsSpecial "\$evalglobal"
syn match gamsSpecial "\$evallocal"
syn match gamsSpecial "\$if"
syn match gamsSpecial "\$ifi"
syn match gamsSpecial "\$endif"
syn match gamsSpecial "\$endifi"
syn match gamsSpecial "\$iftheni"
syn match gamsSpecial "\$ifthene"
syn match gamsSpecial "\$gdxin"
syn match gamsSpecial "\$gdxout"
syn match gamsSpecial "\$load"
syn match gamsSpecial "\$unload"
syn match gamsSpecial "\$include"
syn match gamsSpecial "\$batinclude"
syn match gamsSpecial "\$libinclude"
syn match gamsSpecial "\$sysinclude"
syn match gamsSpecial "\$goto"
syn match gamsSpecial "\$label"
syn match gamsSpecial "\$exit"
syn match gamsSpecial "\$kill"
syn match gamsSpecial "\$offlisting"
syn match gamsSpecial "\$onlisting"
syn match gamsSpecial "\$oneolcom"
syn match gamsSpecial "\$offeolcom"
syn match gamsSpecial "\$stars"
syn match gamsSpecial "\$setglobal"
syn match gamsSpecial "\$dropglobal"
syn match gamsSpecial "\$setlocal"
syn match gamsSpecial "\$droplocal"
syn match gamsSpecial "\$setenv"
syn match gamsSpecial "\$setnames"
syn match gamsSpecial "\$onglobal"
syn match gamsSpecial "\$offglobal"
syn match gamsSpecial "\$setargs"
syn match gamsSpecial "\$onmulti"
syn match gamsSpecial "\$offmulti"
syn match gamsSpecial "\$onempty"
syn match gamsSpecial "\$offempty"
syn match gamsSpecial "\$comment"
syn match gamsSpecial "\$dollar"
syn match gamsSpecial "\$double"
syn match gamsSpecial "\$single"
syn match gamsSpecial "\$echo"
syn match gamsSpecial "\$echon"
syn match gamsSpecial "\$eject"
syn match gamsSpecial "\$error"
syn match gamsSpecial "\$escape"
syn match gamsSpecial "\$expose"
syn match gamsSpecial "\$hidden"
syn match gamsSpecial "\$hide"
syn match gamsSpecial "\$inlinecom"
syn match gamsSpecial "\$lines"
syn match gamsSpecial "\$log"
syn match gamsSpecial "\$maxcol"
syn match gamsSpecial "\$mincol"
syn match gamsSpecial "\$offdigit"
syn match gamsSpecial "\$ondigit"
syn match gamsSpecial "\$offend"
syn match gamsSpecial "\$onend"
syn match gamsSpecial "\$offeps"
syn match gamsSpecial "\$oneps"
syn match gamsSpecial "\$offinline"
syn match gamsSpecial "\$oninline"
syn match gamsSpecial "\$offmargin"
syn match gamsSpecial "\$onmargin"
syn match gamsSpecial "\$offnestcom"
syn match gamsSpecial "\$onnestcom"
syn match gamsSpecial "\$onput"
syn match gamsSpecial "\$onputs"
syn match gamsSpecial "\$onputv"
syn match gamsSpecial "\$offput"
syn match gamsSpecial "\$onsymlist"
syn match gamsSpecial "\$offsymlist"
syn match gamsSpecial "\$onsymxref"
syn match gamsSpecial "\$offsymxref"
syn match gamsSpecial "\$onuellist"
syn match gamsSpecial "\$offuellist"
syn match gamsSpecial "\$onuelxref"
syn match gamsSpecial "\$offuelxref"
syn match gamsSpecial "\$onundf"
syn match gamsSpecial "\$offundf"
syn match gamsSpecial "\$onupper"
syn match gamsSpecial "\$offupper"
syn match gamsSpecial "\$onwarning"
syn match gamsSpecial "\$offwarning"
syn match gamsSpecial "\$phantom"
syn match gamsSpecial "\$prefixpath"
syn match gamsSpecial "\$protect"
syn match gamsSpecial "\$purge"
syn match gamsSpecial "\$remark"
syn match gamsSpecial "\$setcomps"
syn match gamsSpecial "\$setddlist"
syn match gamsSpecial "\$shift"
syn match gamsSpecial "\$show"
syn match gamsSpecial "\$use205"
syn match gamsSpecial "\$use225"
syn match gamsSpecial "\$use999"
syn match gamsSpecial "\$title"
syn match gamsSpecial "\$stitle"
syn match gamsSpecial "\$abort"
syn match gamsSpecial "\$terminate"
syn match gamsSpecial "\$stop"
syn match gamsSpecial "\$("he=e-1
" uncomment to hihglight every word starting with a dollar sign in the beggining of the line
"syn match gamsSpecial "^\$\<[^ ]\+\>"
"integer number, or floating point number without a dot.
"use the special boundary symbols \< and \>
syn match gamsNumber "\<\d\+\>"
syn match gamsNumber "\<[-+]\d\+\>"
"floating point number, with dot
syn match gamsNumber "\<\d\+\.\d*\>"
syn match gamsNumber "\<[-+]\d\+\.\d*\>"
"floating point number, starting with a dot
syn match gamsNumber "\<\.\d\+\>"
syn match gamsNumber "\<[-+]\.\d\+\>"
" scientific notation (with exponent)?
" Floating point like number with E and decimal point (+,-)
syn match gamsNumber '\<[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+\>'
syn match gamsNumber '\<\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+\>'
" special numbers
syn keyword gamsNumber eps na undf
syn match gamsNumber "[-+]inf"
" suffixes -- all from Henry
syn match gamsSuffix /\.pc/
syn match gamsSuffix /\.ps/
syn match gamsSuffix /\.pw/
syn match gamsSuffix /\.tm/
syn match gamsSuffix /\.bm/
syn match gamsSuffix /\.case/
syn match gamsSuffix /\.data/
syn match gamsSuffix /\.ifile/
syn match gamsSuffix /\.ofile/
syn match gamsSuffix /\.page/
syn match gamsSuffix /\.rdate/
syn match gamsSuffix /\.rfile/
syn match gamsSuffix /\.rtime/
syn match gamsSuffix /\.sfile/
syn match gamsSuffix /\.time/
syn match gamsSuffix /\.title/
syn match gamsSuffix /\.ts/
syn match gamsSuffix /\.tl/
syn match gamsSuffix /\.te/
syn match gamsSuffix /\.tf/
syn match gamsSuffix /\.l/
syn match gamsSuffix /\.lo/
syn match gamsSuffix /\.m/
syn match gamsSuffix /\.fx/
syn match gamsSuffix /\.prior/
syn match gamsSuffix /\.scale/
syn match gamsSuffix /\.up/
syn match gamsSuffix /\.lj/
syn match gamsSuffix /\.nj/
syn match gamsSuffix /\.sj/
syn match gamsSuffix /\.tj/
syn match gamsSuffix /\.lw/
syn match gamsSuffix /\.nw/
syn match gamsSuffix /\.sw/
syn match gamsSuffix /\.tw/
syn match gamsSuffix /\.nd/
syn match gamsSuffix /\.nr/
syn match gamsSuffix /\.nz/
syn match gamsSuffix /\.cc/
syn match gamsSuffix /\.hdcc/
syn match gamsSuffix /\.tlcc/
syn match gamsSuffix /\.cr/
syn match gamsSuffix /\.hdcr/
syn match gamsSuffix /\.tlcr/
syn match gamsSuffix /\.ll/
syn match gamsSuffix /\.hdll/
syn match gamsSuffix /\.tlll/
syn match gamsSuffix /\.lp/
syn match gamsSuffix /\.ws/
syn match gamsSuffix /\.errors/
" String and Character contstants
syn region gamsString start=+"+ skip=+\\\\\|\\"+ end=+"+
" with single quotes as well
syn region gamsString start=+'+ skip=+\\\\\|\\"+ end=+'+
" ?? =e=, =g=, =l=
" to include .csv files
syn region gamsInclude start="^\$ondelim" end="^\$offdelim"
" GAMS global variables e.g. %myglobal%
syn region gamsInclude start="%" end="%\|\$"
" when a command line parameter is passed to the gams code the %1 notation can be used
syn match gamsInclude "%\d\+"
" GAMS comments (see REGIONS section as well)
" switch on for end of line comments
" syn match gamsComment "#.*$"
" TODO and FIXME are special keywords in comments
syntax keyword gamsTodo contained TODO FIXME
syntax match gamsComment "^\*.*" contains=gamsTodo
" GAMS comment regions
syntax region gamsComment start="^\$ontext" end="^\$offtext"
" equation declaration and definition regions
syn region gamsEqn matchgroup=Delimiter start=/\.\.\s/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsComment,gamsNumber,gamsConditional,gamsRepeat,gamsFunction,gamsMathsOperator,gamsSuffix
syn region gamsEqDecl matchgroup=Delimiter start=/^[ \t\.]*equation[ s\n]/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsComment,gamsString
syn match gamsEqDeclComment /^[ \t]*[^ \t]*\zs[^;$\/]*/ contained
" variable declaration region
syn region gamsVar matchgroup=Delimiter start=/^[ \t\.]*variable[ s\n]/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsVarComment,gamsComment,gamsString
syn match gamsVarComment /^[ \t]*[^ \t]*\zs[^;$\/]*/ contained
" set region
syn region gamsSet matchgroup=Delimiter start=/^[ \t\.]*set[ s\n]/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsSetComment,gamsComment,gamsSetValues,gamsString
syn match gamsSetComment /^[ \t]*[^ \t]*\zs[^;$\/]*/ contained
syn region gamsSetValues matchgroup=Delimiter start=/\// matchgroup=Delimiter end=/\// transparent contains=gamsComment,gamsString contained
" parameter region
syn region gamsParam matchgroup=Delimiter start=/^[ \t\.]*parameter[ s\n]/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsParamValues,gamsComment,gamsString
" syn match gamsParamComment /^[ \t]*[^ \t]*\zs[^;$\/]*/ contained
syn region gamsParamValues matchgroup=Delimiter start=/\// matchgroup=Delimiter end=/\// transparent contains=gamsNumber contained
" table region
syn region gamsTable matchgroup=Delimiter start=/^[ \t\.]*table[ s\n]/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsNumber,gamsComment,gamsString
" model definition region
syn region gamsModel matchgroup=Delimiter start=/^[ \t\.]*model[ \n]/ matchgroup=Delimiter end=/;/ fold transparent contains=gamsModelValues,gamsComment,gamsString
syn region gamsModelValues matchgroup=Delimiter start=/\// matchgroup=Delimiter end=/\// transparent contained
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have
" highlighting yet
if version >= 508 || !exists("did_gams_syntax_inits")
if version < 508
let did_gams_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink gamsLabel Label
HiLink gamsConditional Conditional
HiLink gamsRepeat Repeat
HiLink gamsLineNumber Comment
HiLink gamsNumber Number
HiLink gamsError Error
HiLink gamsStatement Statement
HiLink gamsString String
HiLink gamsComment Comment
HiLink gamsSpecial Special
HiLink gamsTodo Todo
HiLink gamsFunction Identifier
HiLink gamsTypeSpecifier Type
HiLink gamsFilenumber gamsTypeSpecifier
HiLink gamsInclude Special
HiLink gamsSuffix Statement
hi gamsMathsOperator term=bold cterm=bold gui=bold
delcommand HiLink
endif
let b:current_syntax = "gams"
" vim: ts=8