5a5163602766be8f71354f75f0f10db5b5ad2b3f
[myslice.git] / third-party / codemirror-3.15 / mode / http / http.js
1 CodeMirror.defineMode("http", function() {
2   function failFirstLine(stream, state) {
3     stream.skipToEnd();
4     state.cur = header;
5     return "error";
6   }
7
8   function start(stream, state) {
9     if (stream.match(/^HTTP\/\d\.\d/)) {
10       state.cur = responseStatusCode;
11       return "keyword";
12     } else if (stream.match(/^[A-Z]+/) && /[ \t]/.test(stream.peek())) {
13       state.cur = requestPath;
14       return "keyword";
15     } else {
16       return failFirstLine(stream, state);
17     }
18   }
19
20   function responseStatusCode(stream, state) {
21     var code = stream.match(/^\d+/);
22     if (!code) return failFirstLine(stream, state);
23
24     state.cur = responseStatusText;
25     var status = Number(code[0]);
26     if (status >= 100 && status < 200) {
27       return "positive informational";
28     } else if (status >= 200 && status < 300) {
29       return "positive success";
30     } else if (status >= 300 && status < 400) {
31       return "positive redirect";
32     } else if (status >= 400 && status < 500) {
33       return "negative client-error";
34     } else if (status >= 500 && status < 600) {
35       return "negative server-error";
36     } else {
37       return "error";
38     }
39   }
40
41   function responseStatusText(stream, state) {
42     stream.skipToEnd();
43     state.cur = header;
44     return null;
45   }
46
47   function requestPath(stream, state) {
48     stream.eatWhile(/\S/);
49     state.cur = requestProtocol;
50     return "string-2";
51   }
52
53   function requestProtocol(stream, state) {
54     if (stream.match(/^HTTP\/\d\.\d$/)) {
55       state.cur = header;
56       return "keyword";
57     } else {
58       return failFirstLine(stream, state);
59     }
60   }
61
62   function header(stream) {
63     if (stream.sol() && !stream.eat(/[ \t]/)) {
64       if (stream.match(/^.*?:/)) {
65         return "atom";
66       } else {
67         stream.skipToEnd();
68         return "error";
69       }
70     } else {
71       stream.skipToEnd();
72       return "string";
73     }
74   }
75
76   function body(stream) {
77     stream.skipToEnd();
78     return null;
79   }
80
81   return {
82     token: function(stream, state) {
83       var cur = state.cur;
84       if (cur != header && cur != body && stream.eatSpace()) return null;
85       return cur(stream, state);
86     },
87
88     blankLine: function(state) {
89       state.cur = body;
90     },
91
92     startState: function() {
93       return {cur: start};
94     }
95   };
96 });
97
98 CodeMirror.defineMIME("message/http", "http");