1" Vim syntax file
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
7" Filenames:	.nqc
8
9" quit when a syntax file was already loaded
10if exists("b:current_syntax")
11  finish
12endif
13
14" Statements
15syn keyword	nqcStatement	break return continue start stop abs sign
16syn keyword     nqcStatement	sub task
17syn keyword     nqcLabel	case default
18syn keyword	nqcConditional	if else switch
19syn keyword	nqcRepeat	while for do until repeat
20
21" Scout and RCX2
22syn keyword	nqcEvents	acquire catch monitor
23
24" types and classes
25syn keyword	nqcType		int true false void
26syn keyword	nqcStorageClass	asm const inline
27
28
29
30" Sensors --------------------------------------------
31" Input Sensors
32syn keyword     nqcConstant	SENSOR_1 SENSOR_2 SENSOR_3
33
34" Types for SetSensorType()
35syn keyword     nqcConstant	SENSOR_TYPE_TOUCH SENSOR_TYPE_TEMPERATURE
36syn keyword     nqcConstant	SENSOR_TYPE_LIGHT SENSOR_TYPE_ROTATION
37syn keyword     nqcConstant	SENSOR_LIGHT SENSOR_TOUCH
38
39" Modes for SetSensorMode()
40syn keyword     nqcConstant	SENSOR_MODE_RAW SENSOR_MODE_BOOL
41syn keyword     nqcConstant	SENSOR_MODE_EDGE SENSOR_MODE_PULSE
42syn keyword     nqcConstant	SENSOR_MODE_PERCENT SENSOR_MODE_CELSIUS
43syn keyword     nqcConstant	SENSOR_MODE_FAHRENHEIT SENSOR_MODE_ROTATION
44
45" Sensor configurations for SetSensor()
46syn keyword     nqcConstant	SENSOR_TOUCH SENSOR_LIGHT SENSOR_ROTATION
47syn keyword     nqcConstant	SENSOR_CELSIUS SENSOR_FAHRENHEIT SENSOR_PULSE
48syn keyword     nqcConstant	SENSOR_EDGE
49
50" Functions - All
51syn keyword	nqcFunction	ClearSensor
52syn keyword	nqcFunction	SensorValue SensorType
53
54" Functions - RCX
55syn keyword	nqcFunction	SetSensor SetSensorType
56syn keyword	nqcFunction	SensorValueBool
57
58" Functions - RCX, CyberMaster
59syn keyword	nqcFunction	SetSensorMode SensorMode
60
61" Functions - RCX, Scout
62syn keyword	nqcFunction	SensorValueRaw
63
64" Functions - Scout
65syn keyword	nqcFunction	SetSensorLowerLimit SetSensorUpperLimit
66syn keyword	nqcFunction	SetSensorHysteresis CalibrateSensor
67
68
69" Outputs --------------------------------------------
70" Outputs for On(), Off(), etc.
71syn keyword     nqcConstant	OUT_A OUT_B OUT_C
72
73" Modes for SetOutput()
74syn keyword     nqcConstant	OUT_ON OUT_OFF OUT_FLOAT
75
76" Directions for SetDirection()
77syn keyword     nqcConstant	OUT_FWD OUT_REV OUT_TOGGLE
78
79" Output power for SetPower()
80syn keyword     nqcConstant	OUT_LOW OUT_HALF OUT_FULL
81
82" Functions - All
83syn keyword	nqcFunction	SetOutput SetDirection SetPower OutputStatus
84syn keyword	nqcFunction	On Off Float Fwd Rev Toggle
85syn keyword	nqcFunction	OnFwd OnRev OnFor
86
87" Functions - RXC2, Scout
88syn keyword	nqcFunction	SetGlobalOutput SetGlobalDirection SetMaxPower
89syn keyword	nqcFunction	GlobalOutputStatus
90
91
92" Sound ----------------------------------------------
93" Sounds for PlaySound()
94syn keyword     nqcConstant	SOUND_CLICK SOUND_DOUBLE_BEEP SOUND_DOWN
95syn keyword     nqcConstant	SOUND_UP SOUND_LOW_BEEP SOUND_FAST_UP
96
97" Functions - All
98syn keyword	nqcFunction	PlaySound PlayTone
99
100" Functions - RCX2, Scout
101syn keyword	nqcFunction	MuteSound UnmuteSound ClearSound
102syn keyword	nqcFunction	SelectSounds
103
104
105" LCD ------------------------------------------------
106" Modes for SelectDisplay()
107syn keyword     nqcConstant	DISPLAY_WATCH DISPLAY_SENSOR_1 DISPLAY_SENSOR_2
108syn keyword     nqcConstant	DISPLAY_SENSOR_3 DISPLAY_OUT_A DISPLAY_OUT_B
109syn keyword     nqcConstant	DISPLAY_OUT_C
110" RCX2
111syn keyword     nqcConstant	DISPLAY_USER
112
113" Functions - RCX
114syn keyword	nqcFunction	SelectDisplay
115" Functions - RCX2
116syn keyword	nqcFunction	SetUserDisplay
117
118
119" Communication --------------------------------------
120" Messages - RCX, Scout ------------------------------
121" Tx power level for SetTxPower()
122syn keyword     nqcConstant	TX_POWER_LO TX_POWER_HI
123
124" Functions - RCX, Scout
125syn keyword	nqcFunction	Message ClearMessage SendMessage SetTxPower
126
127" Serial - RCX2 --------------------------------------
128" for SetSerialComm()
129syn keyword     nqcConstant	SERIAL_COMM_DEFAULT SERIAL_COMM_4800
130syn keyword     nqcConstant	SERIAL_COMM_DUTY25 SERIAL_COMM_76KHZ
131
132" for SetSerialPacket()
133syn keyword     nqcConstant	SERIAL_PACKET_DEFAULT SERIAL_PACKET_PREAMBLE
134syn keyword     nqcConstant	SERIAL_PACKET_NEGATED SERIAL_PACKET_CHECKSUM
135syn keyword     nqcConstant	SERIAL_PACKET_RCX
136
137" Functions - RCX2
138syn keyword	nqcFunction	SetSerialComm SetSerialPacket SetSerialData
139syn keyword	nqcFunction	SerialData SendSerial
140
141" VLL - Scout ----------------------------------------
142" Functions - Scout
143syn keyword	nqcFunction	SendVLL
144
145
146" Timers ---------------------------------------------
147" Functions - All
148syn keyword	nqcFunction	ClearTimer Timer
149
150" Functions - RCX2
151syn keyword	nqcFunction	SetTimer FastTimer
152
153
154" Counters -------------------------------------------
155" Functions - RCX2, Scout
156syn keyword	nqcFunction	ClearCounter IncCounter DecCounter Counter
157
158
159" Access Control -------------------------------------
160syn keyword     nqcConstant	ACQUIRE_OUT_A ACQUIRE_OUT_B ACQUIRE_OUT_C
161syn keyword     nqcConstant	ACQUIRE_SOUND
162" RCX2 only
163syn keyword     nqcConstant	ACQUIRE_USER_1 ACQUIRE_USER_2 ACQUIRE_USER_3
164syn keyword     nqcConstant	ACQUIRE_USER_4
165
166" Functions - RCX2, Scout
167syn keyword	nqcFunction	SetPriority
168
169
170" Events ---------------------------------------------
171" RCX2 Events
172syn keyword     nqcConstant	EVENT_TYPE_PRESSED EVENT_TYPE_RELEASED
173syn keyword     nqcConstant	EVENT_TYPE_PULSE EVENT_TYPE_EDGE
174syn keyword     nqcConstant	EVENT_TYPE_FAST_CHANGE EVENT_TYPE_LOW
175syn keyword     nqcConstant	EVENT_TYPE_NORMAL EVENT_TYPE_HIGH
176syn keyword     nqcConstant	EVENT_TYPE_CLICK EVENT_TYPE_DOUBLECLICK
177syn keyword     nqcConstant	EVENT_TYPE_MESSAGE
178
179" Scout Events
180syn keyword     nqcConstant	EVENT_1_PRESSED EVENT_1_RELEASED
181syn keyword     nqcConstant	EVENT_2_PRESSED EVENT_2_RELEASED
182syn keyword     nqcConstant	EVENT_LIGHT_HIGH EVENT_LIGHT_NORMAL
183syn keyword     nqcConstant	EVENT_LIGHT_LOW EVENT_LIGHT_CLICK
184syn keyword     nqcConstant	EVENT_LIGHT_DOUBLECLICK EVENT_COUNTER_0
185syn keyword     nqcConstant	EVENT_COUNTER_1 EVENT_TIMER_0 EVENT_TIMER_1
186syn keyword     nqcConstant	EVENT_TIMER_2 EVENT_MESSAGE
187
188" Functions - RCX2, Scout
189syn keyword	nqcFunction	ActiveEvents Event
190
191" Functions - RCX2
192syn keyword	nqcFunction	CurrentEvents
193syn keyword	nqcFunction	SetEvent ClearEvent ClearAllEvents EventState
194syn keyword	nqcFunction	CalibrateEvent SetUpperLimit UpperLimit
195syn keyword	nqcFunction	SetLowerLimit LowerLimit SetHysteresis
196syn keyword	nqcFunction	Hysteresis
197syn keyword	nqcFunction	SetClickTime ClickTime SetClickCounter
198syn keyword	nqcFunction	ClickCounter
199
200" Functions - Scout
201syn keyword	nqcFunction	SetSensorClickTime SetCounterLimit
202syn keyword	nqcFunction	SetTimerLimit
203
204
205" Data Logging ---------------------------------------
206" Functions - RCX
207syn keyword	nqcFunction	CreateDatalog AddToDatalog
208syn keyword	nqcFunction	UploadDatalog
209
210
211" General Features -----------------------------------
212" Functions - All
213syn keyword	nqcFunction	Wait StopAllTasks Random
214syn keyword	nqcFunction	SetSleepTime SleepNow
215
216" Functions - RCX
217syn keyword	nqcFunction	Program Watch SetWatch
218
219" Functions - RCX2
220syn keyword	nqcFunction	SetRandomSeed SelectProgram
221syn keyword	nqcFunction	BatteryLevel FirmwareVersion
222
223" Functions - Scout
224" Parameters for SetLight()
225syn keyword     nqcConstant	LIGHT_ON LIGHT_OFF
226syn keyword	nqcFunction	SetScoutRules ScoutRules SetScoutMode
227syn keyword	nqcFunction	SetEventFeedback EventFeedback SetLight
228
229" additional CyberMaster defines
230syn keyword     nqcConstant	OUT_L OUT_R OUT_X
231syn keyword     nqcConstant	SENSOR_L SENSOR_M SENSOR_R
232" Functions - CyberMaster
233syn keyword	nqcFunction	Drive OnWait OnWaitDifferent
234syn keyword	nqcFunction	ClearTachoCounter TachoCount TachoSpeed
235syn keyword	nqcFunction	ExternalMotorRunning AGC
236
237
238
239" nqcCommentGroup allows adding matches for special things in comments
240syn keyword	nqcTodo		contained TODO FIXME XXX
241syn cluster	nqcCommentGroup	contains=nqcTodo
242
243"when wanted, highlight trailing white space
244if exists("nqc_space_errors")
245  if !exists("nqc_no_trail_space_error")
246    syn match	nqcSpaceError	display excludenl "\s\+$"
247  endif
248  if !exists("nqc_no_tab_space_error")
249    syn match	nqcSpaceError	display " \+\t"me=e-1
250  endif
251endif
252
253"catch errors caused by wrong parenthesis and brackets
254syn cluster	nqcParenGroup	contains=nqcParenError,nqcIncluded,nqcCommentSkip,@nqcCommentGroup,nqcCommentStartError,nqcCommentSkip,nqcCppOut,nqcCppOut2,nqcCppSkip,nqcNumber,nqcFloat,nqcNumbers
255if exists("nqc_no_bracket_error")
256  syn region	nqcParen	transparent start='(' end=')' contains=ALLBUT,@nqcParenGroup,nqcCppParen
257  " nqcCppParen: same as nqcParen but ends at end-of-line; used in nqcDefine
258  syn region	nqcCppParen	transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@nqcParenGroup,nqcParen
259  syn match	nqcParenError	display ")"
260  syn match	nqcErrInParen	display contained "[{}]"
261else
262  syn region	nqcParen		transparent start='(' end=')' contains=ALLBUT,@nqcParenGroup,nqcCppParen,nqcErrInBracket,nqcCppBracket
263  " nqcCppParen: same as nqcParen but ends at end-of-line; used in nqcDefine
264  syn region	nqcCppParen	transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@nqcParenGroup,nqcErrInBracket,nqcParen,nqcBracket
265  syn match	nqcParenError	display "[\])]"
266  syn match	nqcErrInParen	display contained "[\]{}]"
267  syn region	nqcBracket	transparent start='\[' end=']' contains=ALLBUT,@nqcParenGroup,nqcErrInParen,nqcCppParen,nqcCppBracket
268  " nqcCppBracket: same as nqcParen but ends at end-of-line; used in nqcDefine
269  syn region	nqcCppBracket	transparent start='\[' skip='\\$' excludenl end=']' end='$' contained contains=ALLBUT,@nqcParenGroup,nqcErrInParen,nqcParen,nqcBracket
270  syn match	nqcErrInBracket	display contained "[);{}]"
271endif
272
273"integer number, or floating point number without a dot and with "f".
274syn case ignore
275syn match	nqcNumbers	display transparent "\<\d\|\.\d" contains=nqcNumber,nqcFloat
276" Same, but without octal error (for comments)
277syn match	nqcNumber	display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
278"hex number
279syn match	nqcNumber	display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
280" Flag the first zero of an octal number as something special
281syn match	nqcFloat	display contained "\d\+f"
282"floating point number, with dot, optional exponent
283syn match	nqcFloat	display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
284"floating point number, starting with a dot, optional exponent
285syn match	nqcFloat	display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
286"floating point number, without dot, with exponent
287syn match	nqcFloat	display contained "\d\+e[-+]\=\d\+[fl]\=\>"
288" flag an octal number with wrong digits
289syn case match
290
291syn region	nqcCommentL	start="//" skip="\\$" end="$" keepend contains=@nqcCommentGroup,nqcSpaceError
292syn region	nqcComment	matchgroup=nqcCommentStart start="/\*" matchgroup=NONE end="\*/" contains=@nqcCommentGroup,nqcCommentStartError,nqcSpaceError
293
294" keep a // comment separately, it terminates a preproc. conditional
295syntax match	nqcCommentError	display "\*/"
296syntax match	nqcCommentStartError display "/\*" contained
297
298
299
300
301
302syn region	nqcPreCondit	start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=nqcComment,nqcCharacter,nqcCppParen,nqcParenError,nqcNumbers,nqcCommentError,nqcSpaceError
303syn match	nqcPreCondit	display "^\s*#\s*\(else\|endif\)\>"
304if !exists("nqc_no_if0")
305  syn region	nqcCppOut		start="^\s*#\s*if\s\+0\>" end=".\|$" contains=nqcCppOut2
306  syn region	nqcCppOut2	contained start="0" end="^\s*#\s*\(endif\>\|else\>\|elif\>\)" contains=nqcSpaceError,nqcCppSkip
307  syn region	nqcCppSkip	contained start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*#\s*endif\>" contains=nqcSpaceError,nqcCppSkip
308endif
309syn region	nqcIncluded	display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
310syn match	nqcInclude	display "^\s*#\s*include\>\s*["]" contains=nqcIncluded
311"syn match nqcLineSkip	"\\$"
312syn cluster	nqcPreProcGroup	contains=nqcPreCondit,nqcIncluded,nqcInclude,nqcDefine,nqcErrInParen,nqcErrInBracket,nqcCppOut,nqcCppOut2,nqcCppSkip,nqcNumber,nqcFloat,nqcNumbers,nqcCommentSkip,@nqcCommentGroup,nqcCommentStartError,nqcParen,nqcBracket
313syn region	nqcDefine	start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" contains=ALLBUT,@nqcPreProcGroup
314syn region	nqcPreProc	start="^\s*#\s*\(pragma\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@nqcPreProcGroup
315
316if !exists("nqc_minlines")
317  if !exists("nqc_no_if0")
318    let nqc_minlines = 50	    " #if 0 constructs can be long
319  else
320    let nqc_minlines = 15	    " mostly for () constructs
321  endif
322endif
323exec "syn sync ccomment nqcComment minlines=" . nqc_minlines
324
325" Define the default highlighting.
326" Only when an item doesn't have highlighting yet
327
328" The default methods for highlighting.  Can be overridden later
329hi def link nqcLabel		Label
330hi def link nqcConditional		Conditional
331hi def link nqcRepeat		Repeat
332hi def link nqcCharacter		Character
333hi def link nqcNumber		Number
334hi def link nqcFloat		Float
335hi def link nqcFunction		Function
336hi def link nqcParenError		nqcError
337hi def link nqcErrInParen		nqcError
338hi def link nqcErrInBracket	nqcError
339hi def link nqcCommentL		nqcComment
340hi def link nqcCommentStart	nqcComment
341hi def link nqcCommentError	nqcError
342hi def link nqcCommentStartError	nqcError
343hi def link nqcSpaceError		nqcError
344hi def link nqcStorageClass	StorageClass
345hi def link nqcInclude		Include
346hi def link nqcPreProc		PreProc
347hi def link nqcDefine		Macro
348hi def link nqcIncluded		String
349hi def link nqcError		Error
350hi def link nqcStatement		Statement
351hi def link nqcEvents		Statement
352hi def link nqcPreCondit		PreCondit
353hi def link nqcType		Type
354hi def link nqcConstant		Constant
355hi def link nqcCommentSkip		nqcComment
356hi def link nqcComment		Comment
357hi def link nqcTodo		Todo
358hi def link nqcCppSkip		nqcCppOut
359hi def link nqcCppOut2		nqcCppOut
360hi def link nqcCppOut		Comment
361
362
363let b:current_syntax = "nqc"
364
365" vim: ts=8
366