st.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. export var conf = {
  6. comments: {
  7. lineComment: '//',
  8. blockComment: ['(*', '*)']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')'],
  14. ['var', 'end_var'],
  15. ['var_input', 'end_var'],
  16. ['var_output', 'end_var'],
  17. ['var_in_out', 'end_var'],
  18. ['var_temp', 'end_var'],
  19. ['var_global', 'end_var'],
  20. ['var_access', 'end_var'],
  21. ['var_external', 'end_var'],
  22. ['type', 'end_type'],
  23. ['struct', 'end_struct'],
  24. ['program', 'end_program'],
  25. ['function', 'end_function'],
  26. ['function_block', 'end_function_block'],
  27. ['action', 'end_action'],
  28. ['step', 'end_step'],
  29. ['initial_step', 'end_step'],
  30. ['transaction', 'end_transaction'],
  31. ['configuration', 'end_configuration'],
  32. ['tcp', 'end_tcp'],
  33. ['recource', 'end_recource'],
  34. ['channel', 'end_channel'],
  35. ['library', 'end_library'],
  36. ['folder', 'end_folder'],
  37. ['binaries', 'end_binaries'],
  38. ['includes', 'end_includes'],
  39. ['sources', 'end_sources']
  40. ],
  41. autoClosingPairs: [
  42. { open: '[', close: ']' },
  43. { open: '{', close: '}' },
  44. { open: '(', close: ')' },
  45. { open: '/*', close: '*/' },
  46. { open: "'", close: "'", notIn: ['string_sq'] },
  47. { open: '"', close: '"', notIn: ['string_dq'] },
  48. { open: 'var_input', close: 'end_var' },
  49. { open: 'var_output', close: 'end_var' },
  50. { open: 'var_in_out', close: 'end_var' },
  51. { open: 'var_temp', close: 'end_var' },
  52. { open: 'var_global', close: 'end_var' },
  53. { open: 'var_access', close: 'end_var' },
  54. { open: 'var_external', close: 'end_var' },
  55. { open: 'type', close: 'end_type' },
  56. { open: 'struct', close: 'end_struct' },
  57. { open: 'program', close: 'end_program' },
  58. { open: 'function', close: 'end_function' },
  59. { open: 'function_block', close: 'end_function_block' },
  60. { open: 'action', close: 'end_action' },
  61. { open: 'step', close: 'end_step' },
  62. { open: 'initial_step', close: 'end_step' },
  63. { open: 'transaction', close: 'end_transaction' },
  64. { open: 'configuration', close: 'end_configuration' },
  65. { open: 'tcp', close: 'end_tcp' },
  66. { open: 'recource', close: 'end_recource' },
  67. { open: 'channel', close: 'end_channel' },
  68. { open: 'library', close: 'end_library' },
  69. { open: 'folder', close: 'end_folder' },
  70. { open: 'binaries', close: 'end_binaries' },
  71. { open: 'includes', close: 'end_includes' },
  72. { open: 'sources', close: 'end_sources' }
  73. ],
  74. surroundingPairs: [
  75. { open: '{', close: '}' },
  76. { open: '[', close: ']' },
  77. { open: '(', close: ')' },
  78. { open: '"', close: '"' },
  79. { open: "'", close: "'" },
  80. { open: 'var', close: 'end_var' },
  81. { open: 'var_input', close: 'end_var' },
  82. { open: 'var_output', close: 'end_var' },
  83. { open: 'var_in_out', close: 'end_var' },
  84. { open: 'var_temp', close: 'end_var' },
  85. { open: 'var_global', close: 'end_var' },
  86. { open: 'var_access', close: 'end_var' },
  87. { open: 'var_external', close: 'end_var' },
  88. { open: 'type', close: 'end_type' },
  89. { open: 'struct', close: 'end_struct' },
  90. { open: 'program', close: 'end_program' },
  91. { open: 'function', close: 'end_function' },
  92. { open: 'function_block', close: 'end_function_block' },
  93. { open: 'action', close: 'end_action' },
  94. { open: 'step', close: 'end_step' },
  95. { open: 'initial_step', close: 'end_step' },
  96. { open: 'transaction', close: 'end_transaction' },
  97. { open: 'configuration', close: 'end_configuration' },
  98. { open: 'tcp', close: 'end_tcp' },
  99. { open: 'recource', close: 'end_recource' },
  100. { open: 'channel', close: 'end_channel' },
  101. { open: 'library', close: 'end_library' },
  102. { open: 'folder', close: 'end_folder' },
  103. { open: 'binaries', close: 'end_binaries' },
  104. { open: 'includes', close: 'end_includes' },
  105. { open: 'sources', close: 'end_sources' }
  106. ],
  107. folding: {
  108. markers: {
  109. start: new RegExp('^\\s*#pragma\\s+region\\b'),
  110. end: new RegExp('^\\s*#pragma\\s+endregion\\b')
  111. }
  112. }
  113. };
  114. export var language = {
  115. defaultToken: '',
  116. tokenPostfix: '.st',
  117. ignoreCase: true,
  118. brackets: [
  119. { token: 'delimiter.curly', open: '{', close: '}' },
  120. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  121. { token: 'delimiter.square', open: '[', close: ']' }
  122. ],
  123. keywords: [
  124. 'if',
  125. 'end_if',
  126. 'elsif',
  127. 'else',
  128. 'case',
  129. 'of',
  130. 'to',
  131. '__try',
  132. '__catch',
  133. '__finally',
  134. 'do',
  135. 'with',
  136. 'by',
  137. 'while',
  138. 'repeat',
  139. 'end_while',
  140. 'end_repeat',
  141. 'end_case',
  142. 'for',
  143. 'end_for',
  144. 'task',
  145. 'retain',
  146. 'non_retain',
  147. 'constant',
  148. 'with',
  149. 'at',
  150. 'exit',
  151. 'return',
  152. 'interval',
  153. 'priority',
  154. 'address',
  155. 'port',
  156. 'on_channel',
  157. 'then',
  158. 'iec',
  159. 'file',
  160. 'uses',
  161. 'version',
  162. 'packagetype',
  163. 'displayname',
  164. 'copyright',
  165. 'summary',
  166. 'vendor',
  167. 'common_source',
  168. 'from',
  169. 'extends'
  170. ],
  171. constant: ['false', 'true', 'null'],
  172. defineKeywords: [
  173. 'var',
  174. 'var_input',
  175. 'var_output',
  176. 'var_in_out',
  177. 'var_temp',
  178. 'var_global',
  179. 'var_access',
  180. 'var_external',
  181. 'end_var',
  182. 'type',
  183. 'end_type',
  184. 'struct',
  185. 'end_struct',
  186. 'program',
  187. 'end_program',
  188. 'function',
  189. 'end_function',
  190. 'function_block',
  191. 'end_function_block',
  192. 'interface',
  193. 'end_interface',
  194. 'method',
  195. 'end_method',
  196. 'property',
  197. 'end_property',
  198. 'namespace',
  199. 'end_namespace',
  200. 'configuration',
  201. 'end_configuration',
  202. 'tcp',
  203. 'end_tcp',
  204. 'resource',
  205. 'end_resource',
  206. 'channel',
  207. 'end_channel',
  208. 'library',
  209. 'end_library',
  210. 'folder',
  211. 'end_folder',
  212. 'binaries',
  213. 'end_binaries',
  214. 'includes',
  215. 'end_includes',
  216. 'sources',
  217. 'end_sources',
  218. 'action',
  219. 'end_action',
  220. 'step',
  221. 'initial_step',
  222. 'end_step',
  223. 'transaction',
  224. 'end_transaction'
  225. ],
  226. typeKeywords: [
  227. 'int',
  228. 'sint',
  229. 'dint',
  230. 'lint',
  231. 'usint',
  232. 'uint',
  233. 'udint',
  234. 'ulint',
  235. 'real',
  236. 'lreal',
  237. 'time',
  238. 'date',
  239. 'time_of_day',
  240. 'date_and_time',
  241. 'string',
  242. 'bool',
  243. 'byte',
  244. 'word',
  245. 'dword',
  246. 'array',
  247. 'pointer',
  248. 'lword'
  249. ],
  250. operators: [
  251. '=',
  252. '>',
  253. '<',
  254. ':',
  255. ':=',
  256. '<=',
  257. '>=',
  258. '<>',
  259. '&',
  260. '+',
  261. '-',
  262. '*',
  263. '**',
  264. 'MOD',
  265. '^',
  266. 'or',
  267. 'and',
  268. 'not',
  269. 'xor',
  270. 'abs',
  271. 'acos',
  272. 'asin',
  273. 'atan',
  274. 'cos',
  275. 'exp',
  276. 'expt',
  277. 'ln',
  278. 'log',
  279. 'sin',
  280. 'sqrt',
  281. 'tan',
  282. 'sel',
  283. 'max',
  284. 'min',
  285. 'limit',
  286. 'mux',
  287. 'shl',
  288. 'shr',
  289. 'rol',
  290. 'ror',
  291. 'indexof',
  292. 'sizeof',
  293. 'adr',
  294. 'adrinst',
  295. 'bitadr',
  296. 'is_valid',
  297. 'ref',
  298. 'ref_to'
  299. ],
  300. builtinVariables: [],
  301. builtinFunctions: [
  302. 'sr',
  303. 'rs',
  304. 'tp',
  305. 'ton',
  306. 'tof',
  307. 'eq',
  308. 'ge',
  309. 'le',
  310. 'lt',
  311. 'ne',
  312. 'round',
  313. 'trunc',
  314. 'ctd',
  315. 'сtu',
  316. 'ctud',
  317. 'r_trig',
  318. 'f_trig',
  319. 'move',
  320. 'concat',
  321. 'delete',
  322. 'find',
  323. 'insert',
  324. 'left',
  325. 'len',
  326. 'replace',
  327. 'right',
  328. 'rtc'
  329. ],
  330. // we include these common regular expressions
  331. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  332. // C# style strings
  333. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  334. // The main tokenizer for our languages
  335. tokenizer: {
  336. root: [
  337. [/(\.\.)/, 'delimiter'],
  338. [/\b(16#[0-9A-Fa-f\_]*)+\b/, 'number.hex'],
  339. [/\b(2#[01\_]+)+\b/, 'number.binary'],
  340. [/\b(8#[0-9\_]*)+\b/, 'number.octal'],
  341. [/\b\d*\.\d+([eE][\-+]?\d+)?\b/, 'number.float'],
  342. [/\b(L?REAL)#[0-9\_\.e]+\b/, 'number.float'],
  343. [/\b(BYTE|(?:D|L)?WORD|U?(?:S|D|L)?INT)#[0-9\_]+\b/, 'number'],
  344. [/\d+/, 'number'],
  345. [/\b(T|DT|TOD)#[0-9:-_shmyd]+\b/, 'tag'],
  346. [/\%(I|Q|M)(X|B|W|D|L)[0-9\.]+/, 'tag'],
  347. [/\%(I|Q|M)[0-9\.]*/, 'tag'],
  348. [/\b[A-Za-z]{1,6}#[0-9]+\b/, 'tag'],
  349. [/\b(TO_|CTU_|CTD_|CTUD_|MUX_|SEL_)[A_Za-z]+\b/, 'predefined'],
  350. [/\b[A_Za-z]+(_TO_)[A_Za-z]+\b/, 'predefined'],
  351. [/[;]/, 'delimiter'],
  352. [/[.]/, { token: 'delimiter', next: '@params' }],
  353. // identifiers and keywords
  354. [
  355. /[a-zA-Z_]\w*/,
  356. {
  357. cases: {
  358. '@operators': 'operators',
  359. '@keywords': 'keyword',
  360. '@typeKeywords': 'type',
  361. '@defineKeywords': 'variable',
  362. '@constant': 'constant',
  363. '@builtinVariables': 'predefined',
  364. '@builtinFunctions': 'predefined',
  365. '@default': 'identifier'
  366. }
  367. }
  368. ],
  369. { include: '@whitespace' },
  370. [/[{}()\[\]]/, '@brackets'],
  371. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  372. [/"/, { token: 'string.quote', bracket: '@open', next: '@string_dq' }],
  373. [/'/, { token: 'string.quote', bracket: '@open', next: '@string_sq' }],
  374. [/'[^\\']'/, 'string'],
  375. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  376. [/'/, 'string.invalid']
  377. ],
  378. params: [
  379. [/\b[A-Za-z0-9_]+\b(?=\()/, { token: 'identifier', next: '@pop' }],
  380. [/\b[A-Za-z0-9_]+\b/, 'variable.name', '@pop']
  381. ],
  382. comment: [
  383. [/[^\/*]+/, 'comment'],
  384. [/\/\*/, 'comment', '@push'],
  385. ['\\*/', 'comment', '@pop'],
  386. [/[\/*]/, 'comment']
  387. ],
  388. comment2: [
  389. [/[^\(*]+/, 'comment'],
  390. [/\(\*/, 'comment', '@push'],
  391. ['\\*\\)', 'comment', '@pop'],
  392. [/[\(*]/, 'comment']
  393. ],
  394. whitespace: [
  395. [/[ \t\r\n]+/, 'white'],
  396. [/\/\/.*$/, 'comment'],
  397. [/\/\*/, 'comment', '@comment'],
  398. [/\(\*/, 'comment', '@comment2']
  399. ],
  400. string_dq: [
  401. [/[^\\"]+/, 'string'],
  402. [/@escapes/, 'string.escape'],
  403. [/\\./, 'string.escape.invalid'],
  404. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  405. ],
  406. string_sq: [
  407. [/[^\\']+/, 'string'],
  408. [/@escapes/, 'string.escape'],
  409. [/\\./, 'string.escape.invalid'],
  410. [/'/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
  411. ]
  412. }
  413. };