LaravelTest
120 строк · 3.6 Кб
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("yaml", function() {15
16var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];17var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');18
19return {20token: function(stream, state) {21var ch = stream.peek();22var esc = state.escaped;23state.escaped = false;24/* comments */25if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {26stream.skipToEnd();27return "comment";28}29
30if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))31return "string";32
33if (state.literal && stream.indentation() > state.keyCol) {34stream.skipToEnd(); return "string";35} else if (state.literal) { state.literal = false; }36if (stream.sol()) {37state.keyCol = 0;38state.pair = false;39state.pairStart = false;40/* document start */41if(stream.match('---')) { return "def"; }42/* document end */43if (stream.match('...')) { return "def"; }44/* array list item */45if (stream.match(/\s*-\s+/)) { return 'meta'; }46}47/* inline pairs/lists */48if (stream.match(/^(\{|\}|\[|\])/)) {49if (ch == '{')50state.inlinePairs++;51else if (ch == '}')52state.inlinePairs--;53else if (ch == '[')54state.inlineList++;55else56state.inlineList--;57return 'meta';58}59
60/* list separator */61if (state.inlineList > 0 && !esc && ch == ',') {62stream.next();63return 'meta';64}65/* pairs separator */66if (state.inlinePairs > 0 && !esc && ch == ',') {67state.keyCol = 0;68state.pair = false;69state.pairStart = false;70stream.next();71return 'meta';72}73
74/* start of value of a pair */75if (state.pairStart) {76/* block literals */77if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };78/* references */79if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }80/* numbers */81if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }82if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }83/* keywords */84if (stream.match(keywordRegex)) { return 'keyword'; }85}86
87/* pairs (associative arrays) -> key */88if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {89state.pair = true;90state.keyCol = stream.indentation();91return "atom";92}93if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }94
95/* nothing found, continue */96state.pairStart = false;97state.escaped = (ch == '\\');98stream.next();99return null;100},101startState: function() {102return {103pair: false,104pairStart: false,105keyCol: 0,106inlinePairs: 0,107inlineList: 0,108literal: false,109escaped: false110};111},112lineComment: "#",113fold: "indent"114};115});116
117CodeMirror.defineMIME("text/x-yaml", "yaml");118CodeMirror.defineMIME("text/yaml", "yaml");119
120});121