tp.js 2.5 KB

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