5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("yaml", function() {
16
var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
17
var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
20
token: function(stream, state) {
21
var ch = stream.peek();
22
var esc = state.escaped;
23
state.escaped = false;
25
if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
30
if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))
33
if (state.literal && stream.indentation() > state.keyCol) {
34
stream.skipToEnd(); return "string";
35
} else if (state.literal) { state.literal = false; }
39
state.pairStart = false;
41
if(stream.match('---')) { return "def"; }
43
if (stream.match('...')) { return "def"; }
45
if (stream.match(/\s*-\s+/)) { return 'meta'; }
48
if (stream.match(/^(\{|\}|\[|\])/)) {
61
if (state.inlineList > 0 && !esc && ch == ',') {
66
if (state.inlinePairs > 0 && !esc && ch == ',') {
69
state.pairStart = false;
75
if (state.pairStart) {
77
if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
79
if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
81
if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
82
if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
84
if (stream.match(keywordRegex)) { return 'keyword'; }
88
if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) {
90
state.keyCol = stream.indentation();
93
if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
96
state.pairStart = false;
97
state.escaped = (ch == '\\');
101
startState: function() {
117
CodeMirror.defineMIME("text/x-yaml", "yaml");
118
CodeMirror.defineMIME("text/yaml", "yaml");