tp.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. Language: TP
  3. Author: Jay Strybis <jay.strybis@gmail.com>
  4. Description: FANUC TP programming language (TPP).
  5. Category: hardware
  6. */
  7. function tp(hljs) {
  8. const TPID = {
  9. className: 'number',
  10. begin: '[1-9][0-9]*', /* no leading zeros */
  11. relevance: 0
  12. };
  13. const TPLABEL = {
  14. className: 'symbol',
  15. begin: ':[^\\]]+'
  16. };
  17. const TPDATA = {
  18. className: 'built_in',
  19. begin: '(AR|P|PAYLOAD|PR|R|SR|RSR|LBL|VR|UALM|MESSAGE|UTOOL|UFRAME|TIMER|'
  20. + 'TIMER_OVERFLOW|JOINT_MAX_SPEED|RESUME_PROG|DIAG_REC)\\[',
  21. end: '\\]',
  22. contains: [
  23. 'self',
  24. TPID,
  25. TPLABEL
  26. ]
  27. };
  28. const TPIO = {
  29. className: 'built_in',
  30. begin: '(AI|AO|DI|DO|F|RI|RO|UI|UO|GI|GO|SI|SO)\\[',
  31. end: '\\]',
  32. contains: [
  33. 'self',
  34. TPID,
  35. hljs.QUOTE_STRING_MODE, /* for pos section at bottom */
  36. TPLABEL
  37. ]
  38. };
  39. const KEYWORDS = [
  40. "ABORT",
  41. "ACC",
  42. "ADJUST",
  43. "AND",
  44. "AP_LD",
  45. "BREAK",
  46. "CALL",
  47. "CNT",
  48. "COL",
  49. "CONDITION",
  50. "CONFIG",
  51. "DA",
  52. "DB",
  53. "DIV",
  54. "DETECT",
  55. "ELSE",
  56. "END",
  57. "ENDFOR",
  58. "ERR_NUM",
  59. "ERROR_PROG",
  60. "FINE",
  61. "FOR",
  62. "GP",
  63. "GUARD",
  64. "INC",
  65. "IF",
  66. "JMP",
  67. "LINEAR_MAX_SPEED",
  68. "LOCK",
  69. "MOD",
  70. "MONITOR",
  71. "OFFSET",
  72. "Offset",
  73. "OR",
  74. "OVERRIDE",
  75. "PAUSE",
  76. "PREG",
  77. "PTH",
  78. "RT_LD",
  79. "RUN",
  80. "SELECT",
  81. "SKIP",
  82. "Skip",
  83. "TA",
  84. "TB",
  85. "TO",
  86. "TOOL_OFFSET",
  87. "Tool_Offset",
  88. "UF",
  89. "UT",
  90. "UFRAME_NUM",
  91. "UTOOL_NUM",
  92. "UNLOCK",
  93. "WAIT",
  94. "X",
  95. "Y",
  96. "Z",
  97. "W",
  98. "P",
  99. "R",
  100. "STRLEN",
  101. "SUBSTR",
  102. "FINDSTR",
  103. "VOFFSET",
  104. "PROG",
  105. "ATTR",
  106. "MN",
  107. "POS"
  108. ];
  109. const LITERALS = [
  110. "ON",
  111. "OFF",
  112. "max_speed",
  113. "LPOS",
  114. "JPOS",
  115. "ENABLE",
  116. "DISABLE",
  117. "START",
  118. "STOP",
  119. "RESET"
  120. ];
  121. return {
  122. name: 'TP',
  123. keywords: {
  124. keyword: KEYWORDS,
  125. literal: LITERALS
  126. },
  127. contains: [
  128. TPDATA,
  129. TPIO,
  130. {
  131. className: 'keyword',
  132. begin: '/(PROG|ATTR|MN|POS|END)\\b'
  133. },
  134. {
  135. /* this is for cases like ,CALL */
  136. className: 'keyword',
  137. begin: '(CALL|RUN|POINT_LOGIC|LBL)\\b'
  138. },
  139. {
  140. /* this is for cases like CNT100 where the default lexemes do not
  141. * separate the keyword and the number */
  142. className: 'keyword',
  143. begin: '\\b(ACC|CNT|Skip|Offset|PSPD|RT_LD|AP_LD|Tool_Offset)'
  144. },
  145. {
  146. /* to catch numbers that do not have a word boundary on the left */
  147. className: 'number',
  148. begin: '\\d+(sec|msec|mm/sec|cm/min|inch/min|deg/sec|mm|in|cm)?\\b',
  149. relevance: 0
  150. },
  151. hljs.COMMENT('//', '[;$]'),
  152. hljs.COMMENT('!', '[;$]'),
  153. hljs.COMMENT('--eg:', '$'),
  154. hljs.QUOTE_STRING_MODE,
  155. {
  156. className: 'string',
  157. begin: '\'',
  158. end: '\''
  159. },
  160. hljs.C_NUMBER_MODE,
  161. {
  162. className: 'variable',
  163. begin: '\\$[A-Za-z0-9_]+'
  164. }
  165. ]
  166. };
  167. }
  168. export { tp as default };