st.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/st/st.ts
  8. var 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. var 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: [
  127. "if",
  128. "end_if",
  129. "elsif",
  130. "else",
  131. "case",
  132. "of",
  133. "to",
  134. "__try",
  135. "__catch",
  136. "__finally",
  137. "do",
  138. "with",
  139. "by",
  140. "while",
  141. "repeat",
  142. "end_while",
  143. "end_repeat",
  144. "end_case",
  145. "for",
  146. "end_for",
  147. "task",
  148. "retain",
  149. "non_retain",
  150. "constant",
  151. "with",
  152. "at",
  153. "exit",
  154. "return",
  155. "interval",
  156. "priority",
  157. "address",
  158. "port",
  159. "on_channel",
  160. "then",
  161. "iec",
  162. "file",
  163. "uses",
  164. "version",
  165. "packagetype",
  166. "displayname",
  167. "copyright",
  168. "summary",
  169. "vendor",
  170. "common_source",
  171. "from",
  172. "extends"
  173. ],
  174. constant: ["false", "true", "null"],
  175. defineKeywords: [
  176. "var",
  177. "var_input",
  178. "var_output",
  179. "var_in_out",
  180. "var_temp",
  181. "var_global",
  182. "var_access",
  183. "var_external",
  184. "end_var",
  185. "type",
  186. "end_type",
  187. "struct",
  188. "end_struct",
  189. "program",
  190. "end_program",
  191. "function",
  192. "end_function",
  193. "function_block",
  194. "end_function_block",
  195. "interface",
  196. "end_interface",
  197. "method",
  198. "end_method",
  199. "property",
  200. "end_property",
  201. "namespace",
  202. "end_namespace",
  203. "configuration",
  204. "end_configuration",
  205. "tcp",
  206. "end_tcp",
  207. "resource",
  208. "end_resource",
  209. "channel",
  210. "end_channel",
  211. "library",
  212. "end_library",
  213. "folder",
  214. "end_folder",
  215. "binaries",
  216. "end_binaries",
  217. "includes",
  218. "end_includes",
  219. "sources",
  220. "end_sources",
  221. "action",
  222. "end_action",
  223. "step",
  224. "initial_step",
  225. "end_step",
  226. "transaction",
  227. "end_transaction"
  228. ],
  229. typeKeywords: [
  230. "int",
  231. "sint",
  232. "dint",
  233. "lint",
  234. "usint",
  235. "uint",
  236. "udint",
  237. "ulint",
  238. "real",
  239. "lreal",
  240. "time",
  241. "date",
  242. "time_of_day",
  243. "date_and_time",
  244. "string",
  245. "bool",
  246. "byte",
  247. "word",
  248. "dword",
  249. "array",
  250. "pointer",
  251. "lword"
  252. ],
  253. operators: [
  254. "=",
  255. ">",
  256. "<",
  257. ":",
  258. ":=",
  259. "<=",
  260. ">=",
  261. "<>",
  262. "&",
  263. "+",
  264. "-",
  265. "*",
  266. "**",
  267. "MOD",
  268. "^",
  269. "or",
  270. "and",
  271. "not",
  272. "xor",
  273. "abs",
  274. "acos",
  275. "asin",
  276. "atan",
  277. "cos",
  278. "exp",
  279. "expt",
  280. "ln",
  281. "log",
  282. "sin",
  283. "sqrt",
  284. "tan",
  285. "sel",
  286. "max",
  287. "min",
  288. "limit",
  289. "mux",
  290. "shl",
  291. "shr",
  292. "rol",
  293. "ror",
  294. "indexof",
  295. "sizeof",
  296. "adr",
  297. "adrinst",
  298. "bitadr",
  299. "is_valid",
  300. "ref",
  301. "ref_to"
  302. ],
  303. builtinVariables: [],
  304. builtinFunctions: [
  305. "sr",
  306. "rs",
  307. "tp",
  308. "ton",
  309. "tof",
  310. "eq",
  311. "ge",
  312. "le",
  313. "lt",
  314. "ne",
  315. "round",
  316. "trunc",
  317. "ctd",
  318. "\u0441tu",
  319. "ctud",
  320. "r_trig",
  321. "f_trig",
  322. "move",
  323. "concat",
  324. "delete",
  325. "find",
  326. "insert",
  327. "left",
  328. "len",
  329. "replace",
  330. "right",
  331. "rtc"
  332. ],
  333. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  334. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  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. [
  354. /[a-zA-Z_]\w*/,
  355. {
  356. cases: {
  357. "@operators": "operators",
  358. "@keywords": "keyword",
  359. "@typeKeywords": "type",
  360. "@defineKeywords": "variable",
  361. "@constant": "constant",
  362. "@builtinVariables": "predefined",
  363. "@builtinFunctions": "predefined",
  364. "@default": "identifier"
  365. }
  366. }
  367. ],
  368. { include: "@whitespace" },
  369. [/[{}()\[\]]/, "@brackets"],
  370. [/"([^"\\]|\\.)*$/, "string.invalid"],
  371. [/"/, { token: "string.quote", bracket: "@open", next: "@string_dq" }],
  372. [/'/, { token: "string.quote", bracket: "@open", next: "@string_sq" }],
  373. [/'[^\\']'/, "string"],
  374. [/(')(@escapes)(')/, ["string", "string.escape", "string"]],
  375. [/'/, "string.invalid"]
  376. ],
  377. params: [
  378. [/\b[A-Za-z0-9_]+\b(?=\()/, { token: "identifier", next: "@pop" }],
  379. [/\b[A-Za-z0-9_]+\b/, "variable.name", "@pop"]
  380. ],
  381. comment: [
  382. [/[^\/*]+/, "comment"],
  383. [/\/\*/, "comment", "@push"],
  384. ["\\*/", "comment", "@pop"],
  385. [/[\/*]/, "comment"]
  386. ],
  387. comment2: [
  388. [/[^\(*]+/, "comment"],
  389. [/\(\*/, "comment", "@push"],
  390. ["\\*\\)", "comment", "@pop"],
  391. [/[\(*]/, "comment"]
  392. ],
  393. whitespace: [
  394. [/[ \t\r\n]+/, "white"],
  395. [/\/\/.*$/, "comment"],
  396. [/\/\*/, "comment", "@comment"],
  397. [/\(\*/, "comment", "@comment2"]
  398. ],
  399. string_dq: [
  400. [/[^\\"]+/, "string"],
  401. [/@escapes/, "string.escape"],
  402. [/\\./, "string.escape.invalid"],
  403. [/"/, { token: "string.quote", bracket: "@close", next: "@pop" }]
  404. ],
  405. string_sq: [
  406. [/[^\\']+/, "string"],
  407. [/@escapes/, "string.escape"],
  408. [/\\./, "string.escape.invalid"],
  409. [/'/, { token: "string.quote", bracket: "@close", next: "@pop" }]
  410. ]
  411. }
  412. };
  413. export {
  414. conf,
  415. language
  416. };