1 CodeMirror.defineMode("yaml", function() {
3 var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
4 var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
7 token: function(stream, state) {
8 var ch = stream.peek();
9 var esc = state.escaped;
10 state.escaped = false;
12 if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
13 stream.skipToEnd(); return "comment";
15 if (state.literal && stream.indentation() > state.keyCol) {
16 stream.skipToEnd(); return "string";
17 } else if (state.literal) { state.literal = false; }
21 state.pairStart = false;
23 if(stream.match(/---/)) { return "def"; }
25 if (stream.match(/\.\.\./)) { return "def"; }
27 if (stream.match(/\s*-\s+/)) { return 'meta'; }
29 /* pairs (associative arrays) -> key */
30 if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) {
32 state.keyCol = stream.indentation();
35 if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
37 /* inline pairs/lists */
38 if (stream.match(/^(\{|\}|\[|\])/)) {
51 if (state.inlineList > 0 && !esc && ch == ',') {
56 if (state.inlinePairs > 0 && !esc && ch == ',') {
59 state.pairStart = false;
64 /* start of value of a pair */
65 if (state.pairStart) {
67 if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
69 if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
71 if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
72 if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
74 if (stream.match(keywordRegex)) { return 'keyword'; }
77 /* nothing found, continue */
78 state.pairStart = false;
79 state.escaped = (ch == '\\');
83 startState: function() {
97 CodeMirror.defineMIME("text/x-yaml", "yaml");