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