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