nqc.vim 14 KB

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