LaravelTest
113 строк · 2.7 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("http", function() {15function failFirstLine(stream, state) {16stream.skipToEnd();17state.cur = header;18return "error";19}20
21function start(stream, state) {22if (stream.match(/^HTTP\/\d\.\d/)) {23state.cur = responseStatusCode;24return "keyword";25} else if (stream.match(/^[A-Z]+/) && /[ \t]/.test(stream.peek())) {26state.cur = requestPath;27return "keyword";28} else {29return failFirstLine(stream, state);30}31}32
33function responseStatusCode(stream, state) {34var code = stream.match(/^\d+/);35if (!code) return failFirstLine(stream, state);36
37state.cur = responseStatusText;38var status = Number(code[0]);39if (status >= 100 && status < 200) {40return "positive informational";41} else if (status >= 200 && status < 300) {42return "positive success";43} else if (status >= 300 && status < 400) {44return "positive redirect";45} else if (status >= 400 && status < 500) {46return "negative client-error";47} else if (status >= 500 && status < 600) {48return "negative server-error";49} else {50return "error";51}52}53
54function responseStatusText(stream, state) {55stream.skipToEnd();56state.cur = header;57return null;58}59
60function requestPath(stream, state) {61stream.eatWhile(/\S/);62state.cur = requestProtocol;63return "string-2";64}65
66function requestProtocol(stream, state) {67if (stream.match(/^HTTP\/\d\.\d$/)) {68state.cur = header;69return "keyword";70} else {71return failFirstLine(stream, state);72}73}74
75function header(stream) {76if (stream.sol() && !stream.eat(/[ \t]/)) {77if (stream.match(/^.*?:/)) {78return "atom";79} else {80stream.skipToEnd();81return "error";82}83} else {84stream.skipToEnd();85return "string";86}87}88
89function body(stream) {90stream.skipToEnd();91return null;92}93
94return {95token: function(stream, state) {96var cur = state.cur;97if (cur != header && cur != body && stream.eatSpace()) return null;98return cur(stream, state);99},100
101blankLine: function(state) {102state.cur = body;103},104
105startState: function() {106return {cur: start};107}108};109});110
111CodeMirror.defineMIME("message/http", "http");112
113});114