blob: a50790841e28e311a443c2610258aeb77918c93f [file] [log] [blame]
Bram Moolenaar75ab5902022-04-18 15:36:40 +01001" Vim syntax file
2" Language: Kuka Robot Language
3" Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de>
4" Version: 3.0.0
5" Last Change: 18. Apr 2022
6" Credits: Thanks for contributions to this to Michael Jagusch
7" Thanks for beta testing to Thomas Baginski
8"
9" Note to self:
10" for testing perfomance
11" open a 1000 lines file.
12" :syntime on
13" G
14" hold down CTRL-U until reaching top
15" :syntime report
16
17" Init {{{
18if exists("b:current_syntax")
19 finish
20endif
21
22let s:keepcpo = &cpo
23set cpo&vim
24
25" if colorscheme is tortus(less)? krlGroupName defaults to 1
26if get(g:, 'colors_name', " ") =~ '\<tortus'
27 \&& !exists("g:krlGroupName")
28 let g:krlGroupName=1
29endif
30" krlGroupName defaults to 0 if it's not initialized yet or 0
31if !get(g:, "krlGroupName", 0)
32 let g:krlGroupName = 0
33endif
34
35" krl does ignore case
36syn case ignore
37" take #, $ and & into keyword (syntax only)
38syn iskeyword @,48-57,_,192-255,#,$,&
39" spell checking
40syn spell notoplevel
41" }}} init
42
43" Comment and Folding {{{
44
45" Special Comment
46
47" TODO Comment
48syn keyword krlTodo contained TODO FIXME XXX
49highlight default link krlTodo Todo
50
51" Debug Comment
52syn keyword krlDebug contained DEBUG
53highlight default link krlDebug Debug
54
55" Comment
56" none move fold comment until second ;
57syn match krlFoldComment /\c\v^\s*;\s*%(end)?fold>[^;]*/ containedin=krlFold contains=krlSingleQuoteString,krlInteger,krlFloat,krlMovement,krlDelimiter,krlBoolean
58highlight default link krlFoldComment Comment
59
60" move fold comment until second ;
61syn match krlMoveFoldComment /\c\v^\s*;\s*fold>[^;]*<s?%(ptp|lin|circ|spl)(_rel)?>[^;]*/ containedin=krlFold contains=krlInteger,krlFloat,krlMovement,krlDelimiter
62highlight default link krlMoveFoldComment Comment
63
64" things to highlight in a fold line
65syn keyword krlFoldHighlights CONT IN SYN OUT containedin=krlFoldComment
66syn match krlFoldHighlights /\c\v<(M|F|E|A|t|i|bin|binin|UP|SPSMAKRO)\d+>/ containedin=krlFoldComment
67if g:krlGroupName
68 highlight default link krlFoldHighlights Sysvars
69else
70 " default color for Fold Highlights
71endif
72syn keyword krlVkrcFoldConstants EIN AUS containedin=krlFoldComment
73highlight default link krlVkrcFoldConstants Boolean
74
75" Comment without Fold, also includes endfold lines and fold line part after second ;
76syn match krlComment /\c\v;\s*%(<%(end)?fold>)@!.*$/ containedin=krlFold contains=krlTodo,krlDebug,@Spell
77" Commented out Fold line: "; ;FOLD PTP..."
78syn match krlComment /\c\v^\s*;\s*;.*$/ contains=krlTodo,krlDebug
79highlight default link krlComment Comment
80
81if has("conceal") && get(g:, 'krlConcealFoldTail', 1)
82 syn match krlConcealFoldTail /\c\v(^\s*;\s*fold[^;]*)@250<=;%(--|\s*<fold>|\s*<endfold>)@!.*$/ transparent containedin=krlComment conceal cchar=*
83endif
84" }}} Comment and Folding
85
86" Header {{{
87syn match krlHeader /&\a\w*/
88highlight default link krlHeader PreProc
89" }}} Header
90
91" Operator {{{
92" Boolean operator
93syn keyword krlBoolOperator and or exor not b_and b_or b_exor b_not
94highlight default link krlBoolOperator Operator
95" Arithmetic operator
96syn match krlArithOperator /[+-]/ containedin=krlFloat
97syn match krlArithOperator /[*/]/
98highlight default link krlArithOperator Operator
99" Compare operator
100syn match krlCompOperator /[<>=]/
101highlight default link krlCompOperator Operator
102" Geometric operator
103" Do not move the : operator
104" Must be present befor krlParamdef
105syn match krlGeomOperator /[:]/
106" syn match krlGeomOperator /[:]/ containedin=krlLabel,krlParamdef
107highlight default link krlGeomOperator Operator
108" }}} Operator
109
110" Type, StorageClass and Typedef {{{
111" Simple data types
112syn keyword krlType bool char real int containedin=krlAnyType
113" External program and function
114syn keyword krlType ext extfct extfctp extp containedin=krlAnyType
115" Communication
116syn keyword krlType signal channel containedin=krlAnyType
117highlight default link krlType Type
118" StorageClass
119syn keyword krlStorageClass decl global const struc enum
120highlight default link krlStorageClass StorageClass
121" .dat file public
122syn keyword krlDatStorageClass public
123highlight default link krlDatStorageClass StorageClass
124" Parameter StorageClass
125" Do not move the :in/:out
126" Must be present after krlGeomOperator
127syn match krlParamdef /[:]\s*in\>/
128syn match krlParamdef /[:]\s*out\>/
129highlight default link krlParamdef StorageClass
130" Not a typedef but I like to have those highlighted
131" different then types, structures or strorage classes
132syn keyword krlTypedef DEF DEFFCT ENDFCT DEFDAT ENDDAT
133syn match krlTypedef /^\s*END\>/
134highlight default link krlTypedef Typedef
135" }}} Type, StorageClass and Typedef
136
137" Delimiter {{{
138syn match krlDelimiter /[\[\](),\\]/
139highlight default link krlDelimiter Delimiter
140" }}} Delimiter
141
142" Constant values {{{
143" Boolean
144syn keyword krlBoolean true false containedin=krlStructVal
145highlight default link krlBoolean Boolean
146" Binary integer
147syn match krlBinaryInt /'b[01]\+'/ containedin=krlStructVal
148highlight default link krlBinaryInt Number
149" Hexadecimal integer
150syn match krlHexInt /'h[0-9a-fA-F]\+'/ containedin=krlStructVal
151highlight default link krlHexInt Number
152" Integer
153syn match krlInteger /\W\@1<=[+-]\?\d\+/ containedin=krlStructVal,krlFloat contains=krlArithOperator
154highlight default link krlInteger Number
155" Float
156syn match krlFloat /\v\W@1<=[+-]?\d+\.?\d*%(\s*[eE][+-]?\d+)?/ containedin=krlStructVal
157highlight default link krlFloat Float
158" String
159syn region krlString start=/"/ end=/"/ oneline containedin=krlStructVal contains=@Spell
160highlight default link krlString String
161syn match krlSpecialChar /[|]/ containedin=krlString
162highlight default link krlSpecialChar SpecialChar
163" String within a fold line
164syn region krlSingleQuoteString start=/'/ end=/'/ oneline contained contains=@Spell
165highlight default link krlSingleQuoteString String
166" Enum
167syn match krlEnumVal /#\s*\a\w*/ containedin=krlStructVal
168highlight default link krlEnumVal Constant
169" }}} Constant values
170
171" Predefined Structure and Enum {{{
172" Predefined structures and enums found in
173" /r1/mada/$*.dat, /r1/steu/$*.dat and
174" /r1/system/$config.dat as well as
175" basisTech, gripperTech and spotTech
176"
177" Predefined data types found in krc1
178syn keyword krlStructure servopara keymove powermodul trace techangle tech techfct techcps techfctctrl axis_inc axis_cal date display_var pro_ip con bus
179syn keyword krlEnum ident_state sig_state move_state async_state emt_mode boxmode msg_prm_typ msg_typ cmd_stat asys trace_state trace_mode direction techsys techgeoref techclass techmode hpu_key_val pro_state eax transsys mode_move cosys device rotsys emstop cause_t
180"
181" Predefined data types found in kss functions
182syn keyword krlEnum ediagstate rdc_fs_state ret_c_psync_e var_type cancel_psync_e sys_vars
183syn keyword krlStructure siginf rw_rdc_file rw_mam_file diagpar_t error_t stopmess case_sense_t msgbuf_t e3pos e3axis diagopt_t
184"
185" Predefined structures for movement
186syn keyword krlStructure frame e6pos pos e6axis axis
187syn keyword krlStructure fdat ldat pdat
188syn keyword krlStructure load inertia
189"
190" Predefined structures for shapes
191syn keyword krlStructure axbox cylinder box
192"
193" Predefined structures and enums found in /r1/mada/$machine.dat
194syn keyword krlStructure cp fra acc_car jerk_struc dhart spin trpspin ex_kin et_ax maxtool
195syn keyword krlEnum individual_mames supply_voltage kinclass main_axis wrist_axis sw_onoff
196"
197" Predefined structures and enums found in /r1/mada/$robcor.dat
198" syn keyword krlStructure
199syn keyword krlEnum adap_acc model_type control_parameter eko_mode
200"
201" Predefined structures and enums found in /steu/mada/$custom.dat
202syn keyword krlStructure pro_io_t ser ext_mod_t coop_krc ws_config bin_type coop_update_t ldc_reaction
203syn keyword krlEnum axis_of_coordinates spline_para_variant target_status cp_vel_type cp_statmon
204"
205" Predefined structures and enums found in /steu/mada/$machine.dat
206syn keyword krlStructure emstop_path boxstatesafein boxstatesafeout
207syn keyword krlEnum digincode
208"
209" Predefined structures and enums found in /steu/mada/$option.dat
210syn keyword krlStructure msg_t
211" syn keyword krlEnum
212"
213" Predefined structures and enums found in /r1/system/$config.dat
214" BasisTech
215syn keyword krlStructure dig_out_type ctrl_in_t ctrl_out_t fct_out_t fct_in_t odat basis_sugg_t out_sugg_t md_state machine_def_t machine_tool_t machine_frame_t trigger_para constvel_para condstop_para adat tm_sugg_t tqm_tqdat_t sps_prog_type
216syn keyword krlEnum bas_command out_modetype ipo_m_t apo_mode_t funct_type p00_command timer_actiontype
217"
218" GripperTech
219syn keyword krlStructure grp_typ grp_types grp_sugg_t
220syn keyword krlEnum on_off_typ apo_typ
221"
222" SpotTech
223syn keyword krlStructure spot_type spot_sugg_t
224syn keyword krlEnum s_command s_pair_slct command_retr
225"
226" VW
227syn keyword krlStructure vw_mpara_typ zangentyp zangenbedingung ibszangentyp last_ibs_typ verr_typ verrcheck_t t_fb_state kollisionsdaten state_t modus_t
228syn keyword krlEnum synctype dir_typ subtype ari_typ bool_typ vw_command ibgn_command vw_user_cmd move_types adv_t_type bas_type ibs_mode_typ vw_user_cmd pro_mode mode_op
229"
230" ProgCoop
231syn keyword krlStructure ydat
232" syn keyword krlEnum
233"
234" bas.src
235syn keyword krlStructure cont
236syn keyword krlEnum esys ipo_mode circ_mode circ_type ori_type var_state
237"
238" MsgLib.src
239syn keyword krlStructure KrlMsg_T KrlMsgParType_T KrlMsgPar_T KrlMsgOpt_T KrlMsgDlgSK_T
240syn keyword krlEnum EKrlMsgType
241"
242highlight default link krlStructure Structure
243highlight default link krlEnum Structure
244" }}} Predefined Structure and Enum
245
246" System variable {{{
247syn match krlSysvars /\<\$\a[a-zA-Z0-9_.]*/
248if g:krlGroupName
249 highlight default link krlSysvars Sysvars
250else
251 " default color for Sysvars
252endif
253" }}} System variable
254
255" Statements, keywords et al {{{
256" continue
257syn keyword krlContinue continue
258if g:krlGroupName
259 highlight default link krlContinue Continue
260else
261 highlight default link krlContinue Statement
262endif
263" interrupt
264syn match krlStatement /\v\c%(<global>\s+)?<INTERRUPT>%(\s+<decl>)?/ contains=krlStorageClass
265" keywords
266syn keyword krlStatement wait on off enable disable stop trigger with when distance onstart delay do prio import is minimum maximum confirm on_error_proceed
267syn match krlStatement /\v\c%(<wait\s+)@7<=<sec>/
268syn match krlStatement /\v\c%(<when\s+)@7<=<path>/
269highlight default link krlStatement Statement
270" Conditional
271syn keyword krlConditional if then else endif switch case default endswitch skip endskip
272highlight default link krlConditional Conditional
273" Repeat
274syn keyword krlRepeat for to step endfor while endwhile repeat until loop endloop exit
275highlight default link krlRepeat Repeat
276" Label
277syn keyword krlLabel goto
278syn match krlLabel /^\s*\w\+:\ze\s*\%(;.*\)\?$/
279highlight default link krlLabel Label
280" Keyword
281syn keyword krlKeyword anin anout digin
282highlight default link krlKeyword Keyword
283" Exception
284syn keyword krlException return resume halt
285highlight default link krlException Exception
286" }}} Statements, keywords et al
287
288" special keywords for movement commands {{{
289syn keyword krlMovement PTP PTP_REL LIN LIN_REL CIRC CIRC_REL SPL SPL_REL SPTP SPTP_REL SLIN SLIN_REL SCIRC SCIRC_REL
290syn keyword krlMovement ASYPTP ASYCONT ASYSTOP ASYCANCEL MOVE_EMI
291syn match krlMovement /\v\c^\s*<BRAKE(\s+F)?>/
292if g:krlGroupName
293 highlight default link krlMovement Movement
294else
295 highlight default link krlMovement Special
296endif
297" movement modifiers
298syn match krlMoveBlockInst /\c\v^\s*TIME_BLOCK\s+(START|PART|END)/
299syn match krlMoveBlockInst /\c\v^\s*CONST_VEL\s+(START|END)/
300syn keyword krlMoveBlockInst ptp_spline spline endspline
301highlight default link krlMoveBlockInst Statement
302syn keyword krlMoveMod ca c_ptp c_dis c_vel c_ori c_spl
303if g:krlGroupName
304 highlight default link krlMoveMod Movement
305else
306 highlight default link krlMoveMod Special
307endif
308" }}} special keywords for movement commands
309
310" Structure value {{{
311" avoid coloring structure component names
312syn match krlNames /\.[a-zA-Z_][.a-zA-Z0-9_$]*/
313syn match krlNames contained /[a-zA-Z_][.a-zA-Z0-9_$]*/
314" highlight default link krlNames None
315" Structure value
316syn region krlStructVal start=/{/ end=/}/ oneline containedin=krlStructVal contains=krlNames
317highlight default link krlStructVal Delimiter
318" }}} Structure value
319
320" BuildInFunction {{{
321syn keyword krlBuildInFunction contained Pulse
322syn keyword krlBuildInFunction contained m_comment
323syn keyword krlBuildInFunction contained is_key_pressed
324syn keyword krlBuildInFunction contained set_opt_filter
325syn keyword krlBuildInFunction contained timer_limit
326syn keyword krlBuildInFunction contained tool_adj
327syn keyword krlBuildInFunction contained FRand
328syn keyword krlBuildInFunction contained ExecFunc eb_test EB EK EO LK mbx_rec
329" safe robot
330syn keyword krlbuildinfunction contained get_AxesMask get_BrakeTest_Time
331" math
332syn keyword krlBuildInFunction contained Abs Sin Cos Acos Tan Atan Atan2 Sqrt
333syn keyword krlBuildInFunction contained Forward Inverse inv_pos
334" cFoo sFoo
335syn keyword krlBuildInFunction contained cClose cOpen cRead cWrite sRead sWrite
336" string
337syn keyword krlBuildInFunction contained StrToBool StrToInt StrToReal StrToString StrToFrame StrToPos StrToE3Pos StrToE6Pos StrToAxis StrToE3Axis StrToE6Axis
338syn keyword krlBuildInFunction contained StrAdd StrClear StrCopy StrComp StrFind StrLen StrDeclLen StrToBool StrToInt StrToReal StrToString
339" diag
340syn keyword krlBuildInFunction contained diag_start diag_stop get_DiagState
341" rdc mam pid
342syn keyword krlBuildInFunction contained CheckPidOnRdc check_mam_on_rdc get_rdc_fs_state
343syn keyword krlBuildInFunction contained set_mam_on_hd copy_mam_hd_to_rdc copy_mam_rdc_to_hd
344syn keyword krlBuildInFunction contained PidToHd PidToRdc
345syn keyword krlBuildInFunction contained cal_to_rdc rdc_file_to_hd
346syn keyword krlBuildInFunction contained delete_pid_on_rdc delete_rdc_content
347syn keyword krlBuildInFunction contained create_rdc_archive restore_rdc_archive
348" ioctl
349syn keyword krlBuildInFunction contained IOCtl cIOCtl
350syn keyword krlBuildInFunction contained WSpaceGive WSpaceTake
351" sync
352syn keyword krlBuildInFunction contained Sync SyncCmd CancelProgSync
353" remote
354syn keyword krlBuildInFunction contained RemoteCmd RemoteRead
355" msg/dlg
356syn keyword krlBuildInFunction contained IsMessageSet clear_KrlMsg get_MsgBuffer exists_KrlDlg exists_KrlMsg set_KrlDlg set_KrlDlgAnswer set_KrlMsg
357" robvers
358syn keyword krlBuildInFunction contained maximize_UsedxRobvers set_UsedxRobvers
359" md_foo
360syn keyword krlBuildInFunction contained md_Cmd md_GetState md_SetState md_Asgn
361" emi
362syn keyword krlBuildInFunction contained emi_ActPos emi_EndPos emi_StartPos emi_RecState emi_RecName
363" var
364syn keyword krlBuildInFunction contained cast_from cast_to
365syn keyword krlBuildInFunction contained GetVarsize GetCycDef get_sig_inf get_decl_place VarType VarState
366" sys
367syn keyword krlBuildInFunction contained GetSysState get_system_data set_system_data set_system_data_delayed
368" err
369syn keyword krlBuildInFunction contained err_clear err_raise
370" motion
371syn keyword krlBuildInFunction contained delete_backward_buffer rob_stop rob_stop_release set_brake_delay suppress_repositioning VectorMoveOn VectorMoveOff
372" torque
373syn keyword krlBuildInFunction contained set_torque_limits reset_torque_limits
374" krc1
375syn keyword krlBuildInFunction contained cLcopy cCurpos cNew cClear cRelease cKey
376if g:krlGroupName
377 highlight default link krlBuildInFunction BuildInFunction
378else
379 highlight default link krlBuildInFunction Function
380endif
381" }}} BuildInFunction
382
383" Function {{{
384syn match krlFunction /[a-zA-Z_]\w* *(/me=e-1 contains=krlBuildInFunction
385highlight default link krlFunction Function
386" }}} Function
387
388" Error {{{
389if get(g:, 'krlShowError', 1)
390 " some more or less common typos
391 "
392 " vars or funcs >24 chars are not possible in krl. a234567890123456789012345
393 syn match krlError0 /\w\{25,}/ containedin=krlFunction,krlNames,krlLabel,krlAnyType,krlEnumVal,krlSysvars
394 "
395 " should be interrupt (on|off) \w+
396 syn match krlError1 /\vinterrupt[ \t(]+[_$a-zA-Z0-9]+[_$a-zA-Z0-9.\[\]()+\-*/]*[ \t)]+o%(n|ff)>/
397 "
398 " for bla==5 to 7...
399 " ||
400 syn match krlError3 /\v%(^\s*for%(\(|\s)+[_$a-zA-Z]+[_$a-zA-Z0-9.\[\]()+\-*/ ]*\s*)@<=[:=]\=/
401 "
402 " TODO optimize performance
403 " wait for a=b
404 " |
405 syn match krlError4 /\v%(^\s*%(return|wait\s+for|if|while|until|%(global\s+)?interrupt\s+decl)>[^;]+[^;<>=])@<=\=[^=]/
406 "
407 " wait for a><b
408 " ||
409 syn match krlError5 /\v%(^\s*%(return|wait\s+for|if|while|until|%(global\s+)?interrupt\s+decl)>[^;]+)@<=\>\s*\</
410 "
411 " if (a==5) (b==6) ...
412 " |||
413 syn match krlError6 /\v%(^\s*%(return|wait\s+for|if|while|until|%(global\s+)?interrupt\s+decl)>[^;]+[^;])@<=\)\s*\(/
414 "
415 " TODO optimize performance
416 " a == b + 1
417 " a := b + 1
418 " ||
419 syn match krlError7 /\v%(^\s*%(return|wait\s+for|if|while|until|%(global\s+)?interrupt\s+decl)>[^;]+[^;])@1<!%(^\s*[_$a-zA-Z]+[_$a-zA-Z0-9.\[\],+\-*/]*\s*)@<=[:=]\=/
420 syn match krlError7 /\v\c%(^\s*%(decl\s+)%(global\s+)?%(const\s+)?\w+\s+\w+\s*)@<=[:=]\=/
421 syn match krlError7 /\v\c%(^\s*%(decl\s+)?%(global\s+)?%(const\s+)?%(bool\s+|int\s+|real\s+|char\s+)\w+\s*)@<=[:=]\=/
422 "
423 " this one is tricky. Make sure this does not match trigger instructions; OK, next try, now search for false positives
424 " TODO optimize performance
425 " a = b and c or (int1=int2)
426 " |
427 syn match krlError8 /\v(^\s*[_$a-zA-Z]+[_$a-zA-Z0-9.\[\]()+\-*/]*\s*\=[^;]*[^;<>=])@<=\=\ze[^=]/
428 "
429 " <(distance|delay|prio)> :=
430 " <(distance|delay|prio)> ==
431 " ||
432 syn match krlError9 /\v(^[^;]*<(distance|delay|prio|minimum|maximum)\s*)@<=[:=]\=/
433 "
434 " 'for', 'while' or 'repeat' followed by 'do'
435 syn match krlError10 /\c\v^\s*(until|while|for)>[^;]*<do>/
436 "
437 highlight default link krlError0 Error
438 highlight default link krlError1 Error
439 highlight default link krlError2 Error
440 highlight default link krlError3 Error
441 highlight default link krlError4 Error
442 highlight default link krlError5 Error
443 highlight default link krlError6 Error
444 highlight default link krlError7 Error
445 highlight default link krlError8 Error
446 highlight default link krlError9 Error
447 highlight default link krlError10 Error
448endif
449" }}} Error
450
451" Finish {{{
452let &cpo = s:keepcpo
453unlet s:keepcpo
454
455let b:current_syntax = "krl"
456" }}} Finish
457
458" vim:sw=2 sts=2 et fdm=marker