2 " Language: NQC - Not Quite C, for LEGO mindstorms
3 " NQC homepage: http://www.enteract.com/~dbaum/nqc/
4 " Maintainer: Stefan Scherer <stefan@enotes.de>
5 " Last Change: 2001 May 10
6 " URL: http://www.enotes.de/twiki/pub/Home/LegoMindstorms/nqc.vim
9 " For version 5.x: Clear all syntax items
10 " For version 6.x: Quit when a syntax file was already loaded
13 elseif exists("b:current_syntax")
18 syn keyword nqcStatement break return continue start stop abs sign
19 syn keyword nqcStatement sub task
20 syn keyword nqcLabel case default
21 syn keyword nqcConditional if else switch
22 syn keyword nqcRepeat while for do until repeat
25 syn keyword nqcEvents acquire catch monitor
28 syn keyword nqcType int true false void
29 syn keyword nqcStorageClass asm const inline
33 " Sensors --------------------------------------------
35 syn keyword nqcConstant SENSOR_1 SENSOR_2 SENSOR_3
37 " Types for SetSensorType()
38 syn keyword nqcConstant SENSOR_TYPE_TOUCH SENSOR_TYPE_TEMPERATURE
39 syn keyword nqcConstant SENSOR_TYPE_LIGHT SENSOR_TYPE_ROTATION
40 syn keyword nqcConstant SENSOR_LIGHT SENSOR_TOUCH
42 " Modes for SetSensorMode()
43 syn keyword nqcConstant SENSOR_MODE_RAW SENSOR_MODE_BOOL
44 syn keyword nqcConstant SENSOR_MODE_EDGE SENSOR_MODE_PULSE
45 syn keyword nqcConstant SENSOR_MODE_PERCENT SENSOR_MODE_CELSIUS
46 syn keyword nqcConstant SENSOR_MODE_FAHRENHEIT SENSOR_MODE_ROTATION
48 " Sensor configurations for SetSensor()
49 syn keyword nqcConstant SENSOR_TOUCH SENSOR_LIGHT SENSOR_ROTATION
50 syn keyword nqcConstant SENSOR_CELSIUS SENSOR_FAHRENHEIT SENSOR_PULSE
51 syn keyword nqcConstant SENSOR_EDGE
54 syn keyword nqcFunction ClearSensor
55 syn keyword nqcFunction SensorValue SensorType
58 syn keyword nqcFunction SetSensor SetSensorType
59 syn keyword nqcFunction SensorValueBool
61 " Functions - RCX, CyberMaster
62 syn keyword nqcFunction SetSensorMode SensorMode
64 " Functions - RCX, Scout
65 syn keyword nqcFunction SensorValueRaw
68 syn keyword nqcFunction SetSensorLowerLimit SetSensorUpperLimit
69 syn keyword nqcFunction SetSensorHysteresis CalibrateSensor
72 " Outputs --------------------------------------------
73 " Outputs for On(), Off(), etc.
74 syn keyword nqcConstant OUT_A OUT_B OUT_C
76 " Modes for SetOutput()
77 syn keyword nqcConstant OUT_ON OUT_OFF OUT_FLOAT
79 " Directions for SetDirection()
80 syn keyword nqcConstant OUT_FWD OUT_REV OUT_TOGGLE
82 " Output power for SetPower()
83 syn keyword nqcConstant OUT_LOW OUT_HALF OUT_FULL
86 syn keyword nqcFunction SetOutput SetDirection SetPower OutputStatus
87 syn keyword nqcFunction On Off Float Fwd Rev Toggle
88 syn keyword nqcFunction OnFwd OnRev OnFor
90 " Functions - RXC2, Scout
91 syn keyword nqcFunction SetGlobalOutput SetGlobalDirection SetMaxPower
92 syn keyword nqcFunction GlobalOutputStatus
95 " Sound ----------------------------------------------
96 " Sounds for PlaySound()
97 syn keyword nqcConstant SOUND_CLICK SOUND_DOUBLE_BEEP SOUND_DOWN
98 syn keyword nqcConstant SOUND_UP SOUND_LOW_BEEP SOUND_FAST_UP
101 syn keyword nqcFunction PlaySound PlayTone
103 " Functions - RCX2, Scout
104 syn keyword nqcFunction MuteSound UnmuteSound ClearSound
105 syn keyword nqcFunction SelectSounds
108 " LCD ------------------------------------------------
109 " Modes for SelectDisplay()
110 syn keyword nqcConstant DISPLAY_WATCH DISPLAY_SENSOR_1 DISPLAY_SENSOR_2
111 syn keyword nqcConstant DISPLAY_SENSOR_3 DISPLAY_OUT_A DISPLAY_OUT_B
112 syn keyword nqcConstant DISPLAY_OUT_C
114 syn keyword nqcConstant DISPLAY_USER
117 syn keyword nqcFunction SelectDisplay
119 syn keyword nqcFunction SetUserDisplay
122 " Communication --------------------------------------
123 " Messages - RCX, Scout ------------------------------
124 " Tx power level for SetTxPower()
125 syn keyword nqcConstant TX_POWER_LO TX_POWER_HI
127 " Functions - RCX, Scout
128 syn keyword nqcFunction Message ClearMessage SendMessage SetTxPower
130 " Serial - RCX2 --------------------------------------
131 " for SetSerialComm()
132 syn keyword nqcConstant SERIAL_COMM_DEFAULT SERIAL_COMM_4800
133 syn keyword nqcConstant SERIAL_COMM_DUTY25 SERIAL_COMM_76KHZ
135 " for SetSerialPacket()
136 syn keyword nqcConstant SERIAL_PACKET_DEFAULT SERIAL_PACKET_PREAMBLE
137 syn keyword nqcConstant SERIAL_PACKET_NEGATED SERIAL_PACKET_CHECKSUM
138 syn keyword nqcConstant SERIAL_PACKET_RCX
141 syn keyword nqcFunction SetSerialComm SetSerialPacket SetSerialData
142 syn keyword nqcFunction SerialData SendSerial
144 " VLL - Scout ----------------------------------------
146 syn keyword nqcFunction SendVLL
149 " Timers ---------------------------------------------
151 syn keyword nqcFunction ClearTimer Timer
154 syn keyword nqcFunction SetTimer FastTimer
157 " Counters -------------------------------------------
158 " Functions - RCX2, Scout
159 syn keyword nqcFunction ClearCounter IncCounter DecCounter Counter
162 " Access Control -------------------------------------
163 syn keyword nqcConstant ACQUIRE_OUT_A ACQUIRE_OUT_B ACQUIRE_OUT_C
164 syn keyword nqcConstant ACQUIRE_SOUND
166 syn keyword nqcConstant ACQUIRE_USER_1 ACQUIRE_USER_2 ACQUIRE_USER_3
167 syn keyword nqcConstant ACQUIRE_USER_4
169 " Functions - RCX2, Scout
170 syn keyword nqcFunction SetPriority
173 " Events ---------------------------------------------
175 syn keyword nqcConstant EVENT_TYPE_PRESSED EVENT_TYPE_RELEASED
176 syn keyword nqcConstant EVENT_TYPE_PULSE EVENT_TYPE_EDGE
177 syn keyword nqcConstant EVENT_TYPE_FAST_CHANGE EVENT_TYPE_LOW
178 syn keyword nqcConstant EVENT_TYPE_NORMAL EVENT_TYPE_HIGH
179 syn keyword nqcConstant EVENT_TYPE_CLICK EVENT_TYPE_DOUBLECLICK
180 syn keyword nqcConstant EVENT_TYPE_MESSAGE
183 syn keyword nqcConstant EVENT_1_PRESSED EVENT_1_RELEASED
184 syn keyword nqcConstant EVENT_2_PRESSED EVENT_2_RELEASED
185 syn keyword nqcConstant EVENT_LIGHT_HIGH EVENT_LIGHT_NORMAL
186 syn keyword nqcConstant EVENT_LIGHT_LOW EVENT_LIGHT_CLICK
187 syn keyword nqcConstant EVENT_LIGHT_DOUBLECLICK EVENT_COUNTER_0
188 syn keyword nqcConstant EVENT_COUNTER_1 EVENT_TIMER_0 EVENT_TIMER_1
189 syn keyword nqcConstant EVENT_TIMER_2 EVENT_MESSAGE
191 " Functions - RCX2, Scout
192 syn keyword nqcFunction ActiveEvents Event
195 syn keyword nqcFunction CurrentEvents
196 syn keyword nqcFunction SetEvent ClearEvent ClearAllEvents EventState
197 syn keyword nqcFunction CalibrateEvent SetUpperLimit UpperLimit
198 syn keyword nqcFunction SetLowerLimit LowerLimit SetHysteresis
199 syn keyword nqcFunction Hysteresis
200 syn keyword nqcFunction SetClickTime ClickTime SetClickCounter
201 syn keyword nqcFunction ClickCounter
204 syn keyword nqcFunction SetSensorClickTime SetCounterLimit
205 syn keyword nqcFunction SetTimerLimit
208 " Data Logging ---------------------------------------
210 syn keyword nqcFunction CreateDatalog AddToDatalog
211 syn keyword nqcFunction UploadDatalog
214 " General Features -----------------------------------
216 syn keyword nqcFunction Wait StopAllTasks Random
217 syn keyword nqcFunction SetSleepTime SleepNow
220 syn keyword nqcFunction Program Watch SetWatch
223 syn keyword nqcFunction SetRandomSeed SelectProgram
224 syn keyword nqcFunction BatteryLevel FirmwareVersion
227 " Parameters for SetLight()
228 syn keyword nqcConstant LIGHT_ON LIGHT_OFF
229 syn keyword nqcFunction SetScoutRules ScoutRules SetScoutMode
230 syn keyword nqcFunction SetEventFeedback EventFeedback SetLight
232 " additional CyberMaster defines
233 syn keyword nqcConstant OUT_L OUT_R OUT_X
234 syn keyword nqcConstant SENSOR_L SENSOR_M SENSOR_R
235 " Functions - CyberMaster
236 syn keyword nqcFunction Drive OnWait OnWaitDifferent
237 syn keyword nqcFunction ClearTachoCounter TachoCount TachoSpeed
238 syn keyword nqcFunction ExternalMotorRunning AGC
242 " nqcCommentGroup allows adding matches for special things in comments
243 syn keyword nqcTodo contained TODO FIXME XXX
244 syn cluster nqcCommentGroup contains=nqcTodo
246 "when wanted, highlight trailing white space
247 if exists("nqc_space_errors")
248 if !exists("nqc_no_trail_space_error")
249 syn match nqcSpaceError display excludenl "\s\+$"
251 if !exists("nqc_no_tab_space_error")
252 syn match nqcSpaceError display " \+\t"me=e-1
256 "catch errors caused by wrong parenthesis and brackets
257 syn cluster nqcParenGroup contains=nqcParenError,nqcIncluded,nqcCommentSkip,@nqcCommentGroup,nqcCommentStartError,nqcCommentSkip,nqcCppOut,nqcCppOut2,nqcCppSkip,nqcNumber,nqcFloat,nqcNumbers
258 if exists("nqc_no_bracket_error")
259 syn region nqcParen transparent start='(' end=')' contains=ALLBUT,@nqcParenGroup,nqcCppParen
260 " nqcCppParen: same as nqcParen but ends at end-of-line; used in nqcDefine
261 syn region nqcCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@nqcParenGroup,nqcParen
262 syn match nqcParenError display ")"
263 syn match nqcErrInParen display contained "[{}]"
265 syn region nqcParen transparent start='(' end=')' contains=ALLBUT,@nqcParenGroup,nqcCppParen,nqcErrInBracket,nqcCppBracket
266 " nqcCppParen: same as nqcParen but ends at end-of-line; used in nqcDefine
267 syn region nqcCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@nqcParenGroup,nqcErrInBracket,nqcParen,nqcBracket
268 syn match nqcParenError display "[\])]"
269 syn match nqcErrInParen display contained "[\]{}]"
270 syn region nqcBracket transparent start='\[' end=']' contains=ALLBUT,@nqcParenGroup,nqcErrInParen,nqcCppParen,nqcCppBracket
271 " nqcCppBracket: same as nqcParen but ends at end-of-line; used in nqcDefine
272 syn region nqcCppBracket transparent start='\[' skip='\\$' excludenl end=']' end='$' contained contains=ALLBUT,@nqcParenGroup,nqcErrInParen,nqcParen,nqcBracket
273 syn match nqcErrInBracket display contained "[);{}]"
276 "integer number, or floating point number without a dot and with "f".
278 syn match nqcNumbers display transparent "\<\d\|\.\d" contains=nqcNumber,nqcFloat
279 " Same, but without octal error (for comments)
280 syn match nqcNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
282 syn match nqcNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
283 " Flag the first zero of an octal number as something special
284 syn match nqcFloat display contained "\d\+f"
285 "floating point number, with dot, optional exponent
286 syn match nqcFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
287 "floating point number, starting with a dot, optional exponent
288 syn match nqcFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
289 "floating point number, without dot, with exponent
290 syn match nqcFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>"
291 " flag an octal number with wrong digits
294 syn region nqcCommentL start="//" skip="\\$" end="$" keepend contains=@nqcCommentGroup,nqcSpaceError
295 syn region nqcComment matchgroup=nqcCommentStart start="/\*" matchgroup=NONE end="\*/" contains=@nqcCommentGroup,nqcCommentStartError,nqcSpaceError
297 " keep a // comment separately, it terminates a preproc. conditional
298 syntax match nqcCommentError display "\*/"
299 syntax match nqcCommentStartError display "/\*" contained
305 syn region nqcPreCondit start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=nqcComment,nqcCharacter,nqcCppParen,nqcParenError,nqcNumbers,nqcCommentError,nqcSpaceError
306 syn match nqcPreCondit display "^\s*#\s*\(else\|endif\)\>"
307 if !exists("nqc_no_if0")
308 syn region nqcCppOut start="^\s*#\s*if\s\+0\>" end=".\|$" contains=nqcCppOut2
309 syn region nqcCppOut2 contained start="0" end="^\s*#\s*\(endif\>\|else\>\|elif\>\)" contains=nqcSpaceError,nqcCppSkip
310 syn region nqcCppSkip contained start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*#\s*endif\>" contains=nqcSpaceError,nqcCppSkip
312 syn region nqcIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
313 syn match nqcInclude display "^\s*#\s*include\>\s*["]" contains=nqcIncluded
314 "syn match nqcLineSkip "\\$"
315 syn cluster nqcPreProcGroup contains=nqcPreCondit,nqcIncluded,nqcInclude,nqcDefine,nqcErrInParen,nqcErrInBracket,nqcCppOut,nqcCppOut2,nqcCppSkip,nqcNumber,nqcFloat,nqcNumbers,nqcCommentSkip,@nqcCommentGroup,nqcCommentStartError,nqcParen,nqcBracket
316 syn region nqcDefine start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" contains=ALLBUT,@nqcPreProcGroup
317 syn region nqcPreProc start="^\s*#\s*\(pragma\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@nqcPreProcGroup
319 if !exists("nqc_minlines")
320 if !exists("nqc_no_if0")
321 let nqc_minlines = 50 " #if 0 constructs can be long
323 let nqc_minlines = 15 " mostly for () constructs
326 exec "syn sync ccomment nqcComment minlines=" . nqc_minlines
328 " Define the default highlighting.
329 " For version 5.7 and earlier: only when not done already
330 " For version 5.8 and later: only when an item doesn't have highlighting yet
331 if version >= 508 || !exists("did_nqc_syn_inits")
333 let did_nqc_syn_inits = 1
334 command -nargs=+ HiLink hi link <args>
336 command -nargs=+ HiLink hi def link <args>
339 " The default methods for highlighting. Can be overridden later
340 HiLink nqcLabel Label
341 HiLink nqcConditional Conditional
342 HiLink nqcRepeat Repeat
343 HiLink nqcCharacter Character
344 HiLink nqcNumber Number
345 HiLink nqcFloat Float
346 HiLink nqcFunction Function
347 HiLink nqcParenError nqcError
348 HiLink nqcErrInParen nqcError
349 HiLink nqcErrInBracket nqcError
350 HiLink nqcCommentL nqcComment
351 HiLink nqcCommentStart nqcComment
352 HiLink nqcCommentError nqcError
353 HiLink nqcCommentStartError nqcError
354 HiLink nqcSpaceError nqcError
355 HiLink nqcStorageClass StorageClass
356 HiLink nqcInclude Include
357 HiLink nqcPreProc PreProc
358 HiLink nqcDefine Macro
359 HiLink nqcIncluded String
360 HiLink nqcError Error
361 HiLink nqcStatement Statement
362 HiLink nqcEvents Statement
363 HiLink nqcPreCondit PreCondit
365 HiLink nqcConstant Constant
366 HiLink nqcCommentSkip nqcComment
367 HiLink nqcComment Comment
369 HiLink nqcCppSkip nqcCppOut
370 HiLink nqcCppOut2 nqcCppOut
371 HiLink nqcCppOut Comment
376 let b:current_syntax = "nqc"