Debian Codegraph @

codemirror-legacy-modes/mode/troff.js

raw
1 var words = {};
2
3 function tokenBase(stream) {
4 if (stream.eatSpace()) return null;
5
6 var sol = stream.sol();
7 var ch = stream.next();
8
9 if (ch === '\\') {
10 if (stream.match('fB') || stream.match('fR') || stream.match('fI') ||
11 stream.match('u') || stream.match('d') ||
12 stream.match('%') || stream.match('&')) {
13 return 'string';
14 }
15 if (stream.match('m[')) {
16 stream.skipTo(']');
17 stream.next();
18 return 'string';
19 }
20 if (stream.match('s+') || stream.match('s-')) {
21 stream.eatWhile(/[\d-]/);
22 return 'string';
23 }
24 if (stream.match('\(') || stream.match('*\(')) {
25 stream.eatWhile(/[\w-]/);
26 return 'string';
27 }
28 return 'string';
29 }
30 if (sol && (ch === '.' || ch === '\'')) {
31 if (stream.eat('\\') && stream.eat('\"')) {
32 stream.skipToEnd();
33 return 'comment';
34 }
35 }
36 if (sol && ch === '.') {
37 if (stream.match('B ') || stream.match('I ') || stream.match('R ')) {
38 return 'attribute';
39 }
40 if (stream.match('TH ') || stream.match('SH ') || stream.match('SS ') || stream.match('HP ')) {
41 stream.skipToEnd();
42 return 'quote';
43 }
44 if ((stream.match(/[A-Z]/) && stream.match(/[A-Z]/)) || (stream.match(/[a-z]/) && stream.match(/[a-z]/))) {
45 return 'attribute';
46 }
47 }
48 stream.eatWhile(/[\w-]/);
49 var cur = stream.current();
50 return words.hasOwnProperty(cur) ? words[cur] : null;
51 }
52
53 function tokenize(stream, state) {
54 return (state.tokens[0] || tokenBase) (stream, state);
55 };
56
57 export const troff = {
58 name: "troff",
59 startState: function() {return {tokens:[]};},
60 token: function(stream, state) {
61 return tokenize(stream, state);
62 }
63 };