|
| 1 | +(function (Prism) { |
| 2 | + |
| 3 | + /** |
| 4 | + * Regular expression for characters that are not allowed in identifiers. |
| 5 | + * @type {String} |
| 6 | + */ |
| 7 | + var nonId = /\s\x00-\x1f\x22-\x2f\x3a-\x3f\x5b-\x5e\x60\x7b-\x7e/.source; |
| 8 | + |
| 9 | + /** |
| 10 | + * Surround a regular expression for IDs with patterns for non-ID sequences. |
| 11 | + * @param {String} pattern A regular expression for identifiers. |
| 12 | + * @param {String} [flags] The regular expression flags. |
| 13 | + * @returns {RegExp} A wrapped regular expression for identifiers. |
| 14 | + */ |
| 15 | + function wrapId(pattern, flags) { |
| 16 | + return RegExp(pattern.replace(/<nonId>/g, nonId), flags); |
| 17 | + } |
| 18 | + |
| 19 | + Prism.languages.kumir = { |
| 20 | + 'comment': { |
| 21 | + pattern: /\|.*/ |
| 22 | + }, |
| 23 | + |
| 24 | + 'prolog': { |
| 25 | + pattern: /#.*/, |
| 26 | + greedy: true |
| 27 | + }, |
| 28 | + |
| 29 | + 'string': { |
| 30 | + pattern: /"[^\n\r"]*"|'[^\n\r']*'/, |
| 31 | + greedy: true |
| 32 | + }, |
| 33 | + |
| 34 | + 'boolean': { |
| 35 | + pattern: wrapId(/(^|[<nonId>])(?:да|нет)(?=[<nonId>]|$)/.source), |
| 36 | + lookbehind: true |
| 37 | + }, |
| 38 | + |
| 39 | + 'operator-word': { |
| 40 | + pattern: wrapId(/(^|[<nonId>])(?:и|или|не)(?=[<nonId>]|$)/.source), |
| 41 | + lookbehind: true, |
| 42 | + alias: 'keyword' |
| 43 | + }, |
| 44 | + |
| 45 | + 'system-variable': { |
| 46 | + pattern: wrapId(/(^|[<nonId>])знач(?=[<nonId>]|$)/.source), |
| 47 | + lookbehind: true, |
| 48 | + alias: 'keyword' |
| 49 | + }, |
| 50 | + |
| 51 | + 'type': [ |
| 52 | + { |
| 53 | + pattern: wrapId(/(^|[<nonId>])(?:вещ|лит|лог|сим|цел)(?:\x20*таб)?(?=[<nonId>]|$)/.source), |
| 54 | + lookbehind: true, |
| 55 | + alias: 'builtin' |
| 56 | + }, |
| 57 | + { |
| 58 | + pattern: wrapId(/(^|[<nonId>])(?:компл|сканкод|файл|цвет)(?=[<nonId>]|$)/.source), |
| 59 | + lookbehind: true, |
| 60 | + alias: 'important' |
| 61 | + } |
| 62 | + ], |
| 63 | + |
| 64 | + /** |
| 65 | + * Should be performed after searching for type names because of "таб". |
| 66 | + * "таб" is a reserved word, but never used without a preceding type name. |
| 67 | + * "НАЗНАЧИТЬ", "Фввод", and "Фвывод" are not reserved words. |
| 68 | + */ |
| 69 | + 'keyword': { |
| 70 | + pattern: wrapId(/(^|[<nonId>])(?:алг|арг(?:\x20*рез)?|ввод|ВКЛЮЧИТЬ|вс[её]|выбор|вывод|выход|дано|для|до|дс|если|иначе|исп|использовать|кон(?:(?:\x20+|_)исп)?|кц(?:(?:\x20+|_)при)?|надо|нач|нс|нц|от|пауза|пока|при|раза?|рез|стоп|таб|то|утв|шаг)(?=[<nonId>]|$)/.source), |
| 71 | + lookbehind: true |
| 72 | + }, |
| 73 | + |
| 74 | + /** Should be performed after searching for reserved words. */ |
| 75 | + 'name': { |
| 76 | + pattern: wrapId(/(^|[<nonId>])[^\d<nonId>][^<nonId>]*(?:\x20+[^<nonId>]+)*(?=[<nonId>]|$)/.source), |
| 77 | + lookbehind: true |
| 78 | + }, |
| 79 | + |
| 80 | + /** Should be performed after searching for names. */ |
| 81 | + 'number': { |
| 82 | + pattern: wrapId(/(^|[<nonId>])(?:\B\$[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)(?=[<nonId>]|$)/.source, 'i'), |
| 83 | + lookbehind: true |
| 84 | + }, |
| 85 | + |
| 86 | + /** Should be performed after searching for words. */ |
| 87 | + 'punctuation': /:=|[(),:;\[\]]/, |
| 88 | + |
| 89 | + /** |
| 90 | + * Should be performed after searching for |
| 91 | + * - numeric constants (because of "+" and "-"); |
| 92 | + * - punctuation marks (because of ":=" and "="). |
| 93 | + */ |
| 94 | + 'operator-char': { |
| 95 | + pattern: /\*\*?|<[=>]?|>=?|[-+/=]/, |
| 96 | + alias: 'operator' |
| 97 | + } |
| 98 | + }; |
| 99 | + |
| 100 | + Prism.languages.kum = Prism.languages.kumir; |
| 101 | + |
| 102 | +}(Prism)); |
0 commit comments