prism-kumir.js 3.1 KB

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