You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.3 KiB

7 months ago
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object")
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd)
  7. define(["../../lib/codemirror"], mod);
  8. else
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.defineMode('troff', function() {
  13. var words = {};
  14. function tokenBase(stream) {
  15. if (stream.eatSpace()) return null;
  16. var sol = stream.sol();
  17. var ch = stream.next();
  18. if (ch === '\\') {
  19. if (stream.match('fB') || stream.match('fR') || stream.match('fI') ||
  20. stream.match('u') || stream.match('d') ||
  21. stream.match('%') || stream.match('&')) {
  22. return 'string';
  23. }
  24. if (stream.match('m[')) {
  25. stream.skipTo(']');
  26. stream.next();
  27. return 'string';
  28. }
  29. if (stream.match('s+') || stream.match('s-')) {
  30. stream.eatWhile(/[\d-]/);
  31. return 'string';
  32. }
  33. if (stream.match('\(') || stream.match('*\(')) {
  34. stream.eatWhile(/[\w-]/);
  35. return 'string';
  36. }
  37. return 'string';
  38. }
  39. if (sol && (ch === '.' || ch === '\'')) {
  40. if (stream.eat('\\') && stream.eat('\"')) {
  41. stream.skipToEnd();
  42. return 'comment';
  43. }
  44. }
  45. if (sol && ch === '.') {
  46. if (stream.match('B ') || stream.match('I ') || stream.match('R ')) {
  47. return 'attribute';
  48. }
  49. if (stream.match('TH ') || stream.match('SH ') || stream.match('SS ') || stream.match('HP ')) {
  50. stream.skipToEnd();
  51. return 'quote';
  52. }
  53. if ((stream.match(/[A-Z]/) && stream.match(/[A-Z]/)) || (stream.match(/[a-z]/) && stream.match(/[a-z]/))) {
  54. return 'attribute';
  55. }
  56. }
  57. stream.eatWhile(/[\w-]/);
  58. var cur = stream.current();
  59. return words.hasOwnProperty(cur) ? words[cur] : null;
  60. }
  61. function tokenize(stream, state) {
  62. return (state.tokens[0] || tokenBase) (stream, state);
  63. };
  64. return {
  65. startState: function() {return {tokens:[]};},
  66. token: function(stream, state) {
  67. return tokenize(stream, state);
  68. }
  69. };
  70. });
  71. CodeMirror.defineMIME('text/troff', 'troff');
  72. CodeMirror.defineMIME('text/x-troff', 'troff');
  73. CodeMirror.defineMIME('application/x-troff', 'troff');
  74. });