tp.js (2508B)
1 /* 2 Language: TP 3 Author: Jay Strybis <jay.strybis@gmail.com> 4 Description: FANUC TP programming language (TPP). 5 */ 6 7 8 function tp(hljs) { 9 var TPID = { 10 className: 'number', 11 begin: '[1-9][0-9]*', /* no leading zeros */ 12 relevance: 0 13 }; 14 var TPLABEL = { 15 className: 'symbol', 16 begin: ':[^\\]]+' 17 }; 18 var TPDATA = { 19 className: 'built_in', 20 begin: '(AR|P|PAYLOAD|PR|R|SR|RSR|LBL|VR|UALM|MESSAGE|UTOOL|UFRAME|TIMER|' + 21 'TIMER_OVERFLOW|JOINT_MAX_SPEED|RESUME_PROG|DIAG_REC)\\[', end: '\\]', 22 contains: [ 23 'self', 24 TPID, 25 TPLABEL 26 ] 27 }; 28 var TPIO = { 29 className: 'built_in', 30 begin: '(AI|AO|DI|DO|F|RI|RO|UI|UO|GI|GO|SI|SO)\\[', end: '\\]', 31 contains: [ 32 'self', 33 TPID, 34 hljs.QUOTE_STRING_MODE, /* for pos section at bottom */ 35 TPLABEL 36 ] 37 }; 38 39 return { 40 name: 'TP', 41 keywords: { 42 keyword: 43 'ABORT ACC ADJUST AND AP_LD BREAK CALL CNT COL CONDITION CONFIG DA DB ' + 44 'DIV DETECT ELSE END ENDFOR ERR_NUM ERROR_PROG FINE FOR GP GUARD INC ' + 45 'IF JMP LINEAR_MAX_SPEED LOCK MOD MONITOR OFFSET Offset OR OVERRIDE ' + 46 'PAUSE PREG PTH RT_LD RUN SELECT SKIP Skip TA TB TO TOOL_OFFSET ' + 47 'Tool_Offset UF UT UFRAME_NUM UTOOL_NUM UNLOCK WAIT X Y Z W P R STRLEN ' + 48 'SUBSTR FINDSTR VOFFSET PROG ATTR MN POS', 49 literal: 50 'ON OFF max_speed LPOS JPOS ENABLE DISABLE START STOP RESET' 51 }, 52 contains: [ 53 TPDATA, 54 TPIO, 55 { 56 className: 'keyword', 57 begin: '/(PROG|ATTR|MN|POS|END)\\b' 58 }, 59 { 60 /* this is for cases like ,CALL */ 61 className: 'keyword', 62 begin: '(CALL|RUN|POINT_LOGIC|LBL)\\b' 63 }, 64 { 65 /* this is for cases like CNT100 where the default lexemes do not 66 * separate the keyword and the number */ 67 className: 'keyword', 68 begin: '\\b(ACC|CNT|Skip|Offset|PSPD|RT_LD|AP_LD|Tool_Offset)' 69 }, 70 { 71 /* to catch numbers that do not have a word boundary on the left */ 72 className: 'number', 73 begin: '\\d+(sec|msec|mm/sec|cm/min|inch/min|deg/sec|mm|in|cm)?\\b', 74 relevance: 0 75 }, 76 hljs.COMMENT('//', '[;$]'), 77 hljs.COMMENT('!', '[;$]'), 78 hljs.COMMENT('--eg:', '$'), 79 hljs.QUOTE_STRING_MODE, 80 { 81 className: 'string', 82 begin: '\'', end: '\'' 83 }, 84 hljs.C_NUMBER_MODE, 85 { 86 className: 'variable', 87 begin: '\\$[A-Za-z0-9_]+' 88 } 89 ] 90 }; 91 } 92 93 module.exports = tp;