|
@@ -0,0 +1,178 @@
|
|
|
+/*---------------------------------------------------------------------------------------------
|
|
|
+ * Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
+ * Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
+ *--------------------------------------------------------------------------------------------*/
|
|
|
+
|
|
|
+'use strict';
|
|
|
+
|
|
|
+import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
|
|
|
+import ILanguage = monaco.languages.IMonarchLanguage;
|
|
|
+
|
|
|
+export const conf: IRichLanguageConfiguration = {
|
|
|
+ comments: {
|
|
|
+ lineComment: '//',
|
|
|
+ blockComment: ['(*', '*)'],
|
|
|
+ },
|
|
|
+ brackets: [
|
|
|
+ ['{', '}'],
|
|
|
+ ['[', ']'],
|
|
|
+ ['(', ')']
|
|
|
+ ],
|
|
|
+ autoClosingPairs: [
|
|
|
+ { open: '[', close: ']' },
|
|
|
+ { open: '{', close: '}' },
|
|
|
+ { open: '(', close: ')' },
|
|
|
+ { open: '/*', close: '*/' },
|
|
|
+ { open: '\'', close: '\'', notIn: ['string_sq'] },
|
|
|
+ { open: '"', close: '"', notIn: ['string_dq'] },
|
|
|
+ ],
|
|
|
+ surroundingPairs: [
|
|
|
+ { open: '{', close: '}' },
|
|
|
+ { open: '[', close: ']' },
|
|
|
+ { open: '(', close: ')' },
|
|
|
+ { open: '"', close: '"' },
|
|
|
+ { open: '\'', close: '\'' },
|
|
|
+ ],
|
|
|
+ folding: {
|
|
|
+ markers: {
|
|
|
+ start: new RegExp("^\\s*#pragma\\s+region\\b"),
|
|
|
+ end: new RegExp("^\\s*#pragma\\s+endregion\\b")
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+export const language = <ILanguage>{
|
|
|
+ defaultToken: '',
|
|
|
+ tokenPostfix: '.st',
|
|
|
+ ignoreCase: true,
|
|
|
+
|
|
|
+ brackets: [
|
|
|
+ { token: 'delimiter.curly', open: '{', close: '}' },
|
|
|
+ { token: 'delimiter.parenthesis', open: '(', close: ')' },
|
|
|
+ { token: 'delimiter.square', open: '[', close: ']' }
|
|
|
+ ],
|
|
|
+
|
|
|
+ keywords: ['if', 'end_if', 'elsif', 'else', 'case', 'of', 'to',
|
|
|
+ 'do', 'with', 'by', 'while', 'repeat', 'end_while', 'end_repeat', 'end_case',
|
|
|
+ 'for', 'end_for', 'task', 'retain', 'non_retain', 'constant', 'with', 'at',
|
|
|
+ 'exit', 'return', 'interval', 'priority', 'address', 'port', 'on_channel',
|
|
|
+ 'then', 'iec', 'file', 'uses', 'version', 'packagetype', 'displayname',
|
|
|
+ 'copyright', 'summary', 'vendor', 'common_source', 'from'],
|
|
|
+
|
|
|
+ constant: ['false', 'true', 'null'],
|
|
|
+
|
|
|
+ defineKeywords: [
|
|
|
+ 'var', 'var_input', 'var_output', 'var_in_out', 'var_temp', 'var_global',
|
|
|
+ 'var_access', 'var_external', 'end_var',
|
|
|
+
|
|
|
+ 'type', 'end_type', 'struct', 'end_struct', 'program', 'end_program',
|
|
|
+ 'function', 'end_function', 'function_block', 'end_function_block',
|
|
|
+
|
|
|
+ 'configuration', 'end_configuration', 'tcp', 'end_tcp', 'recource',
|
|
|
+ 'end_recource', 'channel', 'end_channel', 'library', 'end_library',
|
|
|
+ 'folder', 'end_folder', 'binaries', 'end_binaries', 'includes',
|
|
|
+ 'end_includes', 'sources', 'end_sources',
|
|
|
+
|
|
|
+ 'action', 'end_action', 'step', 'initial_step', 'end_step', 'transaction', 'end_transaction'
|
|
|
+ ],
|
|
|
+
|
|
|
+ typeKeywords: ['int', 'sint', 'dint', 'lint', 'usint', 'uint', 'udint', 'ulint',
|
|
|
+ 'real', 'lreal', 'time', 'date', 'time_of_day', 'date_and_time', 'string',
|
|
|
+ 'bool', 'byte', 'world', 'dworld', 'array', 'pointer', 'lworld'],
|
|
|
+
|
|
|
+ operators: ['=', '>', '<', ':', ':=', '<=', '>=', '<>', '&', '+', '-', '*', '**',
|
|
|
+ 'MOD', '^', 'or', 'and', 'not', 'xor', 'abs', 'acos', 'asin', 'atan', 'cos',
|
|
|
+ 'exp', 'expt', 'ln', 'log', 'sin', 'sqrt', 'tan', 'sel', 'max', 'min', 'limit',
|
|
|
+ 'mux', 'shl', 'shr', 'rol', 'ror', 'indexof', 'sizeof', 'adr', 'adrinst',
|
|
|
+ 'bitadr', 'is_valid'],
|
|
|
+
|
|
|
+ builtinVariables: [
|
|
|
+
|
|
|
+ ],
|
|
|
+
|
|
|
+ builtinFunctions: ['sr', 'rs', 'tp', 'ton', 'tof', 'eq', 'ge', 'le', 'lt',
|
|
|
+ 'ne', 'round', 'trunc', 'ctd', 'сtu', 'ctud', 'r_trig', 'f_trig',
|
|
|
+ 'move', 'concat', 'delete', 'find', 'insert', 'left', 'len', 'replace',
|
|
|
+ 'right', 'rtc'],
|
|
|
+
|
|
|
+ // we include these common regular expressions
|
|
|
+ symbols: /[=><!~?:&|+\-*\/\^%]+/,
|
|
|
+
|
|
|
+ // C# style strings
|
|
|
+ escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
|
+
|
|
|
+ // The main tokenizer for our languages
|
|
|
+ tokenizer: {
|
|
|
+ root: [
|
|
|
+ [/(T|DT|TOD)#[0-9:-_shmyd]*/, 'tag'],
|
|
|
+ [/[A-Za-z]{1,6}#[0-9]*/, 'tag'],
|
|
|
+ [/\%(I|Q|M)(X|B|W|D|L)[0-9\.]*/, 'tag'],
|
|
|
+ [/\%(I|Q|M)[0-9\.]*/, 'tag'],
|
|
|
+ [/(TO_|CTU_|CTD_|CTUD_|MUX_|SEL_)[A_Za-z]*/, 'predefined'],
|
|
|
+ [/[A_Za-z]*(_TO_)[A_Za-z]*/, 'predefined'],
|
|
|
+
|
|
|
+ // identifiers and keywords
|
|
|
+ [/[a-zA-Z_]\w*/, {
|
|
|
+ cases: {
|
|
|
+ '@operators': 'operators',
|
|
|
+ '@keywords': 'keyword',
|
|
|
+ '@typeKeywords': 'type',
|
|
|
+ '@defineKeywords': 'variable',
|
|
|
+ '@constant': 'constant',
|
|
|
+ '@builtinVariables': 'predefined',
|
|
|
+ '@builtinFunctions': 'predefined',
|
|
|
+ '@default': 'identifier'
|
|
|
+ }
|
|
|
+ }],
|
|
|
+
|
|
|
+ { include: '@whitespace' },
|
|
|
+
|
|
|
+ [/[;.]/, 'delimiter'],
|
|
|
+ [/[{}()\[\]]/, '@brackets'],
|
|
|
+ [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
|
|
|
+ [/16#[0-9a-fA-F]+/, 'number.hex'],
|
|
|
+ [/2#[0-9_]+/, 'number.binary'],
|
|
|
+ [/\d+/, 'number'],
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
|
|
+ [/"/, { token: 'string.quote', bracket: '@open', next: '@string_dq' }],
|
|
|
+ [/'/, { token: 'string.quote', bracket: '@open', next: '@string_sq' }],
|
|
|
+
|
|
|
+ [/'[^\\']'/, 'string'],
|
|
|
+ [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
|
|
|
+ [/'/, 'string.invalid']
|
|
|
+ ],
|
|
|
+ comment: [
|
|
|
+ [/[^\/*]+/, 'comment'],
|
|
|
+ [/\/\*/, 'comment', '@push'], // nested comment
|
|
|
+ ["\\*/", 'comment', '@pop'],
|
|
|
+ [/[\/*]/, 'comment']
|
|
|
+ ],
|
|
|
+ comment2: [
|
|
|
+ [/[^\(*]+/, 'comment'],
|
|
|
+ [/\(\*/, 'comment', '@push'], // nested comment
|
|
|
+ ["\\*\\)", 'comment', '@pop'],
|
|
|
+ [/[\(*]/, 'comment']
|
|
|
+ ],
|
|
|
+ whitespace: [
|
|
|
+ [/[ \t\r\n]+/, 'white'],
|
|
|
+ [/\/\/.*$/, 'comment'],
|
|
|
+ [/\/\*/, 'comment', '@comment'],
|
|
|
+ [/\(\*/, 'comment', '@comment2'],
|
|
|
+ ],
|
|
|
+ string_dq: [
|
|
|
+ [/[^\\"]+/, 'string'],
|
|
|
+ [/@escapes/, 'string.escape'],
|
|
|
+ [/\\./, 'string.escape.invalid'],
|
|
|
+ [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
|
|
|
+ ],
|
|
|
+ string_sq: [
|
|
|
+ [/[^\\']+/, 'string'],
|
|
|
+ [/@escapes/, 'string.escape'],
|
|
|
+ [/\\./, 'string.escape.invalid'],
|
|
|
+ [/'/, { token: 'string.quote', bracket: '@close', next: '@pop' }]
|
|
|
+ ]
|
|
|
+ }
|
|
|
+};
|