Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | " For version 5.x: Clear all syntax items |
| 10 | " For version 6.x: Quit when a syntax file was already loaded |
| 11 | if version < 600 |
| 12 | syntax clear |
| 13 | elseif exists("b:current_syntax") |
| 14 | finish |
| 15 | endif |
| 16 | |
| 17 | " Statements |
| 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 |
| 23 | |
| 24 | " Scout and RCX2 |
| 25 | syn keyword nqcEvents acquire catch monitor |
| 26 | |
| 27 | " types and classes |
| 28 | syn keyword nqcType int true false void |
| 29 | syn keyword nqcStorageClass asm const inline |
| 30 | |
| 31 | |
| 32 | |
| 33 | " Sensors -------------------------------------------- |
| 34 | " Input Sensors |
| 35 | syn keyword nqcConstant SENSOR_1 SENSOR_2 SENSOR_3 |
| 36 | |
| 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 |
| 41 | |
| 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 |
| 47 | |
| 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 |
| 52 | |
| 53 | " Functions - All |
| 54 | syn keyword nqcFunction ClearSensor |
| 55 | syn keyword nqcFunction SensorValue SensorType |
| 56 | |
| 57 | " Functions - RCX |
| 58 | syn keyword nqcFunction SetSensor SetSensorType |
| 59 | syn keyword nqcFunction SensorValueBool |
| 60 | |
| 61 | " Functions - RCX, CyberMaster |
| 62 | syn keyword nqcFunction SetSensorMode SensorMode |
| 63 | |
| 64 | " Functions - RCX, Scout |
| 65 | syn keyword nqcFunction SensorValueRaw |
| 66 | |
| 67 | " Functions - Scout |
| 68 | syn keyword nqcFunction SetSensorLowerLimit SetSensorUpperLimit |
| 69 | syn keyword nqcFunction SetSensorHysteresis CalibrateSensor |
| 70 | |
| 71 | |
| 72 | " Outputs -------------------------------------------- |
| 73 | " Outputs for On(), Off(), etc. |
| 74 | syn keyword nqcConstant OUT_A OUT_B OUT_C |
| 75 | |
| 76 | " Modes for SetOutput() |
| 77 | syn keyword nqcConstant OUT_ON OUT_OFF OUT_FLOAT |
| 78 | |
| 79 | " Directions for SetDirection() |
| 80 | syn keyword nqcConstant OUT_FWD OUT_REV OUT_TOGGLE |
| 81 | |
| 82 | " Output power for SetPower() |
| 83 | syn keyword nqcConstant OUT_LOW OUT_HALF OUT_FULL |
| 84 | |
| 85 | " Functions - All |
| 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 |
| 89 | |
| 90 | " Functions - RXC2, Scout |
| 91 | syn keyword nqcFunction SetGlobalOutput SetGlobalDirection SetMaxPower |
| 92 | syn keyword nqcFunction GlobalOutputStatus |
| 93 | |
| 94 | |
| 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 |
| 99 | |
| 100 | " Functions - All |
| 101 | syn keyword nqcFunction PlaySound PlayTone |
| 102 | |
| 103 | " Functions - RCX2, Scout |
| 104 | syn keyword nqcFunction MuteSound UnmuteSound ClearSound |
| 105 | syn keyword nqcFunction SelectSounds |
| 106 | |
| 107 | |
| 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 |
| 113 | " RCX2 |
| 114 | syn keyword nqcConstant DISPLAY_USER |
| 115 | |
| 116 | " Functions - RCX |
| 117 | syn keyword nqcFunction SelectDisplay |
| 118 | " Functions - RCX2 |
| 119 | syn keyword nqcFunction SetUserDisplay |
| 120 | |
| 121 | |
| 122 | " Communication -------------------------------------- |
| 123 | " Messages - RCX, Scout ------------------------------ |
| 124 | " Tx power level for SetTxPower() |
| 125 | syn keyword nqcConstant TX_POWER_LO TX_POWER_HI |
| 126 | |
| 127 | " Functions - RCX, Scout |
| 128 | syn keyword nqcFunction Message ClearMessage SendMessage SetTxPower |
| 129 | |
| 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 |
| 134 | |
| 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 |
| 139 | |
| 140 | " Functions - RCX2 |
| 141 | syn keyword nqcFunction SetSerialComm SetSerialPacket SetSerialData |
| 142 | syn keyword nqcFunction SerialData SendSerial |
| 143 | |
| 144 | " VLL - Scout ---------------------------------------- |
| 145 | " Functions - Scout |
| 146 | syn keyword nqcFunction SendVLL |
| 147 | |
| 148 | |
| 149 | " Timers --------------------------------------------- |
| 150 | " Functions - All |
| 151 | syn keyword nqcFunction ClearTimer Timer |
| 152 | |
| 153 | " Functions - RCX2 |
| 154 | syn keyword nqcFunction SetTimer FastTimer |
| 155 | |
| 156 | |
| 157 | " Counters ------------------------------------------- |
| 158 | " Functions - RCX2, Scout |
| 159 | syn keyword nqcFunction ClearCounter IncCounter DecCounter Counter |
| 160 | |
| 161 | |
| 162 | " Access Control ------------------------------------- |
| 163 | syn keyword nqcConstant ACQUIRE_OUT_A ACQUIRE_OUT_B ACQUIRE_OUT_C |
| 164 | syn keyword nqcConstant ACQUIRE_SOUND |
| 165 | " RCX2 only |
| 166 | syn keyword nqcConstant ACQUIRE_USER_1 ACQUIRE_USER_2 ACQUIRE_USER_3 |
| 167 | syn keyword nqcConstant ACQUIRE_USER_4 |
| 168 | |
| 169 | " Functions - RCX2, Scout |
| 170 | syn keyword nqcFunction SetPriority |
| 171 | |
| 172 | |
| 173 | " Events --------------------------------------------- |
| 174 | " RCX2 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 |
| 181 | |
| 182 | " Scout Events |
| 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 |
| 190 | |
| 191 | " Functions - RCX2, Scout |
| 192 | syn keyword nqcFunction ActiveEvents Event |
| 193 | |
| 194 | " Functions - RCX2 |
| 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 |
| 202 | |
| 203 | " Functions - Scout |
| 204 | syn keyword nqcFunction SetSensorClickTime SetCounterLimit |
| 205 | syn keyword nqcFunction SetTimerLimit |
| 206 | |
| 207 | |
| 208 | " Data Logging --------------------------------------- |
| 209 | " Functions - RCX |
| 210 | syn keyword nqcFunction CreateDatalog AddToDatalog |
| 211 | syn keyword nqcFunction UploadDatalog |
| 212 | |
| 213 | |
| 214 | " General Features ----------------------------------- |
| 215 | " Functions - All |
| 216 | syn keyword nqcFunction Wait StopAllTasks Random |
| 217 | syn keyword nqcFunction SetSleepTime SleepNow |
| 218 | |
| 219 | " Functions - RCX |
| 220 | syn keyword nqcFunction Program Watch SetWatch |
| 221 | |
| 222 | " Functions - RCX2 |
| 223 | syn keyword nqcFunction SetRandomSeed SelectProgram |
| 224 | syn keyword nqcFunction BatteryLevel FirmwareVersion |
| 225 | |
| 226 | " Functions - Scout |
| 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 |
| 231 | |
| 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 |
| 239 | |
| 240 | |
| 241 | |
| 242 | " nqcCommentGroup allows adding matches for special things in comments |
| 243 | syn keyword nqcTodo contained TODO FIXME XXX |
| 244 | syn cluster nqcCommentGroup contains=nqcTodo |
| 245 | |
| 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\+$" |
| 250 | endif |
| 251 | if !exists("nqc_no_tab_space_error") |
| 252 | syn match nqcSpaceError display " \+\t"me=e-1 |
| 253 | endif |
| 254 | endif |
| 255 | |
| 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 "[{}]" |
| 264 | else |
| 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 "[);{}]" |
| 274 | endif |
| 275 | |
| 276 | "integer number, or floating point number without a dot and with "f". |
| 277 | syn case ignore |
| 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\)\>" |
| 281 | "hex number |
| 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 |
| 292 | syn case match |
| 293 | |
| 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 |
| 296 | |
| 297 | " keep a // comment separately, it terminates a preproc. conditional |
| 298 | syntax match nqcCommentError display "\*/" |
| 299 | syntax match nqcCommentStartError display "/\*" contained |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 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 |
| 311 | endif |
| 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 |
| 318 | |
| 319 | if !exists("nqc_minlines") |
| 320 | if !exists("nqc_no_if0") |
| 321 | let nqc_minlines = 50 " #if 0 constructs can be long |
| 322 | else |
| 323 | let nqc_minlines = 15 " mostly for () constructs |
| 324 | endif |
| 325 | endif |
| 326 | exec "syn sync ccomment nqcComment minlines=" . nqc_minlines |
| 327 | |
| 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") |
| 332 | if version < 508 |
| 333 | let did_nqc_syn_inits = 1 |
| 334 | command -nargs=+ HiLink hi link <args> |
| 335 | else |
| 336 | command -nargs=+ HiLink hi def link <args> |
| 337 | endif |
| 338 | |
| 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 |
| 364 | HiLink nqcType Type |
| 365 | HiLink nqcConstant Constant |
| 366 | HiLink nqcCommentSkip nqcComment |
| 367 | HiLink nqcComment Comment |
| 368 | HiLink nqcTodo Todo |
| 369 | HiLink nqcCppSkip nqcCppOut |
| 370 | HiLink nqcCppOut2 nqcCppOut |
| 371 | HiLink nqcCppOut Comment |
| 372 | |
| 373 | delcommand HiLink |
| 374 | endif |
| 375 | |
| 376 | let b:current_syntax = "nqc" |
| 377 | |
| 378 | " vim: ts=8 |