1 /* CodeMirror version: 5.40.2 */
2 // CodeMirror, copyright (c) by Marijn Haverbeke and others
3 // Distributed under an MIT license: https://codemirror.net/LICENSE
6 if (typeof exports == "object" && typeof module == "object") // CommonJS
7 mod(require("../../lib/codemirror"));
8 else if (typeof define == "function" && define.amd) // AMD
9 define(["../../lib/codemirror"], mod);
10 else // Plain browser env
12 })(function(CodeMirror) {
15 CodeMirror.defineMode("yaml", function() {
17 var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
18 var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
21 token: function(stream, state) {
22 var ch = stream.peek();
23 var esc = state.escaped;
24 state.escaped = false;
26 if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
31 if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))
34 if (state.literal && stream.indentation() > state.keyCol) {
35 stream.skipToEnd(); return "string";
36 } else if (state.literal) { state.literal = false; }
40 state.pairStart = false;
42 if(stream.match(/---/)) { return "def"; }
44 if (stream.match(/\.\.\./)) { return "def"; }
46 if (stream.match(/\s*-\s+/)) { return 'meta'; }
48 /* inline pairs/lists */
49 if (stream.match(/^(\{|\}|\[|\])/)) {
62 if (state.inlineList > 0 && !esc && ch == ',') {
67 if (state.inlinePairs > 0 && !esc && ch == ',') {
70 state.pairStart = false;
75 /* start of value of a pair */
76 if (state.pairStart) {
78 if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
80 if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
82 if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
83 if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
85 if (stream.match(keywordRegex)) { return 'keyword'; }
88 /* pairs (associative arrays) -> key */
89 if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {
91 state.keyCol = stream.indentation();
94 if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
96 /* nothing found, continue */
97 state.pairStart = false;
98 state.escaped = (ch == '\\');
102 startState: function() {
118 CodeMirror.defineMIME("text/x-yaml", "yaml");
119 CodeMirror.defineMIME("text/yaml", "yaml");