st.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define(["require", "exports"], function (require, exports) {
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.conf = {
  9. comments: {
  10. lineComment: '//',
  11. blockComment: ['(*', '*)'],
  12. },
  13. brackets: [
  14. ['{', '}'],
  15. ['[', ']'],
  16. ['(', ')'],
  17. ['var', 'end_var'],
  18. ['var_input', 'end_var'],
  19. ['var_output', 'end_var'],
  20. ['var_in_out', 'end_var'],
  21. ['var_temp', 'end_var'],
  22. ['var_global', 'end_var'],
  23. ['var_access', 'end_var'],
  24. ['var_external', 'end_var'],
  25. ['type', 'end_type'],
  26. ['struct', 'end_struct'],
  27. ['program', 'end_program'],
  28. ['function', 'end_function'],
  29. ['function_block', 'end_function_block'],
  30. ['action', 'end_action'],
  31. ['step', 'end_step'],
  32. ['initial_step', 'end_step'],
  33. ['transaction', 'end_transaction'],
  34. ['configuration', 'end_configuration'],
  35. ['tcp', 'end_tcp'],
  36. ['recource', 'end_recource'],
  37. ['channel', 'end_channel'],
  38. ['library', 'end_library'],
  39. ['folder', 'end_folder'],
  40. ['binaries', 'end_binaries'],
  41. ['includes', 'end_includes'],
  42. ['sources', 'end_sources']
  43. ],
  44. autoClosingPairs: [
  45. { open: '[', close: ']' },
  46. { open: '{', close: '}' },
  47. { open: '(', close: ')' },
  48. { open: '/*', close: '*/' },
  49. { open: '\'', close: '\'', notIn: ['string_sq'] },
  50. { open: '"', close: '"', notIn: ['string_dq'] },
  51. { open: 'var_input', close: 'end_var' },
  52. { open: 'var_output', close: 'end_var' },
  53. { open: 'var_in_out', close: 'end_var' },
  54. { open: 'var_temp', close: 'end_var' },
  55. { open: 'var_global', close: 'end_var' },
  56. { open: 'var_access', close: 'end_var' },
  57. { open: 'var_external', close: 'end_var' },
  58. { open: 'type', close: 'end_type' },
  59. { open: 'struct', close: 'end_struct' },
  60. { open: 'program', close: 'end_program' },
  61. { open: 'function', close: 'end_function' },
  62. { open: 'function_block', close: 'end_function_block' },
  63. { open: 'action', close: 'end_action' },
  64. { open: 'step', close: 'end_step' },
  65. { open: 'initial_step', close: 'end_step' },
  66. { open: 'transaction', close: 'end_transaction' },
  67. { open: 'configuration', close: 'end_configuration' },
  68. { open: 'tcp', close: 'end_tcp' },
  69. { open: 'recource', close: 'end_recource' },
  70. { open: 'channel', close: 'end_channel' },
  71. { open: 'library', close: 'end_library' },
  72. { open: 'folder', close: 'end_folder' },
  73. { open: 'binaries', close: 'end_binaries' },
  74. { open: 'includes', close: 'end_includes' },
  75. { open: 'sources', close: 'end_sources' }
  76. ],
  77. surroundingPairs: [
  78. { open: '{', close: '}' },
  79. { open: '[', close: ']' },
  80. { open: '(', close: ')' },
  81. { open: '"', close: '"' },
  82. { open: '\'', close: '\'' },
  83. { open: 'var', close: 'end_var' },
  84. { open: 'var_input', close: 'end_var' },
  85. { open: 'var_output', close: 'end_var' },
  86. { open: 'var_in_out', close: 'end_var' },
  87. { open: 'var_temp', close: 'end_var' },
  88. { open: 'var_global', close: 'end_var' },
  89. { open: 'var_access', close: 'end_var' },
  90. { open: 'var_external', close: 'end_var' },
  91. { open: 'type', close: 'end_type' },
  92. { open: 'struct', close: 'end_struct' },
  93. { open: 'program', close: 'end_program' },
  94. { open: 'function', close: 'end_function' },
  95. { open: 'function_block', close: 'end_function_block' },
  96. { open: 'action', close: 'end_action' },
  97. { open: 'step', close: 'end_step' },
  98. { open: 'initial_step', close: 'end_step' },
  99. { open: 'transaction', close: 'end_transaction' },
  100. { open: 'configuration', close: 'end_configuration' },
  101. { open: 'tcp', close: 'end_tcp' },
  102. { open: 'recource', close: 'end_recource' },
  103. { open: 'channel', close: 'end_channel' },
  104. { open: 'library', close: 'end_library' },
  105. { open: 'folder', close: 'end_folder' },
  106. { open: 'binaries', close: 'end_binaries' },
  107. { open: 'includes', close: 'end_includes' },
  108. { open: 'sources', close: 'end_sources' }
  109. ],
  110. folding: {
  111. markers: {
  112. start: new RegExp("^\\s*#pragma\\s+region\\b"),
  113. end: new RegExp("^\\s*#pragma\\s+endregion\\b")
  114. }
  115. }
  116. };
  117. exports.language = {
  118. defaultToken: '',
  119. tokenPostfix: '.st',
  120. ignoreCase: true,
  121. brackets: [
  122. { token: 'delimiter.curly', open: '{', close: '}' },
  123. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  124. { token: 'delimiter.square', open: '[', close: ']' }
  125. ],
  126. keywords: ['if', 'end_if', 'elsif', 'else', 'case', 'of', 'to', '__try', '__catch', '__finally',
  127. 'do', 'with', 'by', 'while', 'repeat', 'end_while', 'end_repeat', 'end_case',
  128. 'for', 'end_for', 'task', 'retain', 'non_retain', 'constant', 'with', 'at',
  129. 'exit', 'return', 'interval', 'priority', 'address', 'port', 'on_channel',
  130. 'then', 'iec', 'file', 'uses', 'version', 'packagetype', 'displayname',
  131. 'copyright', 'summary', 'vendor', 'common_source', 'from', 'extends'],
  132. constant: ['false', 'true', 'null'],
  133. defineKeywords: [
  134. 'var', 'var_input', 'var_output', 'var_in_out', 'var_temp', 'var_global',
  135. 'var_access', 'var_external', 'end_var',
  136. 'type', 'end_type', 'struct', 'end_struct', 'program', 'end_program',
  137. 'function', 'end_function', 'function_block', 'end_function_block',
  138. 'interface', 'end_interface', 'method', 'end_method',
  139. 'property', 'end_property', 'namespace', 'end_namespace',
  140. 'configuration', 'end_configuration', 'tcp', 'end_tcp', 'resource',
  141. 'end_resource', 'channel', 'end_channel', 'library', 'end_library',
  142. 'folder', 'end_folder', 'binaries', 'end_binaries', 'includes',
  143. 'end_includes', 'sources', 'end_sources',
  144. 'action', 'end_action', 'step', 'initial_step', 'end_step', 'transaction', 'end_transaction'
  145. ],
  146. typeKeywords: ['int', 'sint', 'dint', 'lint', 'usint', 'uint', 'udint', 'ulint',
  147. 'real', 'lreal', 'time', 'date', 'time_of_day', 'date_and_time', 'string',
  148. 'bool', 'byte', 'word', 'dword', 'array', 'pointer', 'lword'],
  149. operators: ['=', '>', '<', ':', ':=', '<=', '>=', '<>', '&', '+', '-', '*', '**',
  150. 'MOD', '^', 'or', 'and', 'not', 'xor', 'abs', 'acos', 'asin', 'atan', 'cos',
  151. 'exp', 'expt', 'ln', 'log', 'sin', 'sqrt', 'tan', 'sel', 'max', 'min', 'limit',
  152. 'mux', 'shl', 'shr', 'rol', 'ror', 'indexof', 'sizeof', 'adr', 'adrinst',
  153. 'bitadr', 'is_valid', 'ref', 'ref_to'],
  154. builtinVariables: [],
  155. builtinFunctions: ['sr', 'rs', 'tp', 'ton', 'tof', 'eq', 'ge', 'le', 'lt',
  156. 'ne', 'round', 'trunc', 'ctd', 'сtu', 'ctud', 'r_trig', 'f_trig',
  157. 'move', 'concat', 'delete', 'find', 'insert', 'left', 'len', 'replace',
  158. 'right', 'rtc'],
  159. // we include these common regular expressions
  160. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  161. // C# style strings
  162. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  163. // The main tokenizer for our languages
  164. tokenizer: {
  165. root: [
  166. [/(\.\.)/, 'delimiter'],
  167. [/\b(16#[0-9A-Fa-f\_]*)+\b/, 'number.hex'],
  168. [/\b(2#[01\_]+)+\b/, 'number.binary'],
  169. [/\b(8#[0-9\_]*)+\b/, 'number.octal'],
  170. [/\b\d*\.\d+([eE][\-+]?\d+)?\b/, 'number.float'],
  171. [/\b(L?REAL)#[0-9\_\.e]+\b/, 'number.float'],
  172. [/\b(BYTE|(?:D|L)?WORD|U?(?:S|D|L)?INT)#[0-9\_]+\b/, 'number'],
  173. [/\d+/, 'number'],
  174. [/\b(T|DT|TOD)#[0-9:-_shmyd]+\b/, 'tag'],
  175. [/\%(I|Q|M)(X|B|W|D|L)[0-9\.]+/, 'tag'],
  176. [/\%(I|Q|M)[0-9\.]*/, 'tag'],
  177. [/\b[A-Za-z]{1,6}#[0-9]+\b/, 'tag'],
  178. [/\b(TO_|CTU_|CTD_|CTUD_|MUX_|SEL_)[A_Za-z]+\b/, 'predefined'],
  179. [/\b[A_Za-z]+(_TO_)[A_Za-z]+\b/, 'predefined'],
  180. [/[;]/, 'delimiter'],
  181. [/[.]/, { token: 'delimiter', next: '@params' }],
  182. // identifiers and keywords
  183. [/[a-zA-Z_]\w*/, {
  184. cases: {
  185. '@operators': 'operators',
  186. '@keywords': 'keyword',
  187. '@typeKeywords': 'type',
  188. '@defineKeywords': 'variable',
  189. '@constant': 'constant',
  190. '@builtinVariables': 'predefined',
  191. '@builtinFunctions': 'predefined',
  192. '@default': 'identifier'
  193. }
  194. }],
  195. { include: '@whitespace' },
  196. [/[{}()\[\]]/, '@brackets'],
  197. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  198. [/"/, { token: 'string.quote', bracket: '@open', next: '@string_dq' }],
  199. [/'/, { token: 'string.quote', bracket: '@open', next: '@string_sq' }],
  200. [/'[^\\']'/, 'string'],
  201. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  202. [/'/, 'string.invalid']
  203. ],
  204. params: [
  205. [/\b[A-Za-z0-9_]+\b(?=\()/, { token: 'identifier', next: '@pop' }],
  206. [/\b[A-Za-z0-9_]+\b/, 'variable.name', '@pop']
  207. ],
  208. comment: [
  209. [/[^\/*]+/, 'comment'],
  210. [/\/\*/, 'comment', '@push'],
  211. ["\\*/", 'comment', '@pop'],
  212. [/[\/*]/, 'comment']
  213. ],
  214. comment2: [
  215. [/[^\(*]+/, 'comment'],
  216. [/\(\*/, 'comment', '@push'],
  217. ["\\*\\)", 'comment', '@pop'],
  218. [/[\(*]/, 'comment']
  219. ],
  220. whitespace: [
  221. [/[ \t\r\n]+/, 'white'],
  222. [/\/\/.*$/, 'comment'],
  223. [/\/\*/, 'comment', '@comment'],
  224. [/\(\*/, 'comment', '@comment2'],
  225. ],
  226. string_dq: [
  227. [/[^\\"]+/, 'string'],
  228. [/@escapes/, 'string.escape'],
  229. [/\\./, 'string.escape.invalid'],
  230. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  231. ],
  232. string_sq: [
  233. [/[^\\']+/, 'string'],
  234. [/@escapes/, 'string.escape'],
  235. [/\\./, 'string.escape.invalid'],
  236. [/'/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  237. ]
  238. }
  239. };
  240. });