Debian Codegraph @

codemirror-legacy-modes/mode/http.js

raw
1 function failFirstLine(stream, state) {
2 stream.skipToEnd();
3 state.cur = header;
4 return "error";
5 }
6
7 function start(stream, state) {
8 if (stream.match(/^HTTP\/\d\.\d/)) {
9 state.cur = responseStatusCode;
10 return "keyword";
11 } else if (stream.match(/^[A-Z]+/) && /[ \t]/.test(stream.peek())) {
12 state.cur = requestPath;
13 return "keyword";
14 } else {
15 return failFirstLine(stream, state);
16 }
17 }
18
19 function responseStatusCode(stream, state) {
20 var code = stream.match(/^\d+/);
21 if (!code) return failFirstLine(stream, state);
22
23 state.cur = responseStatusText;
24 var status = Number(code[0]);
25 if (status >= 100 && status < 400) {
26 return "atom";
27 } else {
28 return "error";
29 }
30 }
31
32 function responseStatusText(stream, state) {
33 stream.skipToEnd();
34 state.cur = header;
35 return null;
36 }
37
38 function requestPath(stream, state) {
39 stream.eatWhile(/\S/);
40 state.cur = requestProtocol;
41 return "string.special";
42 }
43
44 function requestProtocol(stream, state) {
45 if (stream.match(/^HTTP\/\d\.\d$/)) {
46 state.cur = header;
47 return "keyword";
48 } else {
49 return failFirstLine(stream, state);
50 }
51 }
52
53 function header(stream) {
54 if (stream.sol() && !stream.eat(/[ \t]/)) {
55 if (stream.match(/^.*?:/)) {
56 return "atom";
57 } else {
58 stream.skipToEnd();
59 return "error";
60 }
61 } else {
62 stream.skipToEnd();
63 return "string";
64 }
65 }
66
67 function body(stream) {
68 stream.skipToEnd();
69 return null;
70 }
71
72 export const http = {
73 name: "http",
74 token: function(stream, state) {
75 var cur = state.cur;
76 if (cur != header && cur != body && stream.eatSpace()) return null;
77 return cur(stream, state);
78 },
79
80 blankLine: function(state) {
81 state.cur = body;
82 },
83
84 startState: function() {
85 return {cur: start};
86 }
87 };