Fix: merge conflict
[myslice.git] / third-party / codemirror-3.15 / mode / yaml / yaml.js
1 CodeMirror.defineMode("yaml", function() {
2
3   var cons = ['true', 'false', 'on', 'off', 'yes', 'no'];
4   var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i');
5
6   return {
7     token: function(stream, state) {
8       var ch = stream.peek();
9       var esc = state.escaped;
10       state.escaped = false;
11       /* comments */
12       if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) {
13         stream.skipToEnd(); return "comment";
14       }
15       if (state.literal && stream.indentation() > state.keyCol) {
16         stream.skipToEnd(); return "string";
17       } else if (state.literal) { state.literal = false; }
18       if (stream.sol()) {
19         state.keyCol = 0;
20         state.pair = false;
21         state.pairStart = false;
22         /* document start */
23         if(stream.match(/---/)) { return "def"; }
24         /* document end */
25         if (stream.match(/\.\.\./)) { return "def"; }
26         /* array list item */
27         if (stream.match(/\s*-\s+/)) { return 'meta'; }
28       }
29       /* pairs (associative arrays) -> key */
30       if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) {
31         state.pair = true;
32         state.keyCol = stream.indentation();
33         return "atom";
34       }
35       if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
36
37       /* inline pairs/lists */
38       if (stream.match(/^(\{|\}|\[|\])/)) {
39         if (ch == '{')
40           state.inlinePairs++;
41         else if (ch == '}')
42           state.inlinePairs--;
43         else if (ch == '[')
44           state.inlineList++;
45         else
46           state.inlineList--;
47         return 'meta';
48       }
49
50       /* list seperator */
51       if (state.inlineList > 0 && !esc && ch == ',') {
52         stream.next();
53         return 'meta';
54       }
55       /* pairs seperator */
56       if (state.inlinePairs > 0 && !esc && ch == ',') {
57         state.keyCol = 0;
58         state.pair = false;
59         state.pairStart = false;
60         stream.next();
61         return 'meta';
62       }
63
64       /* start of value of a pair */
65       if (state.pairStart) {
66         /* block literals */
67         if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
68         /* references */
69         if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
70         /* numbers */
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'; }
73         /* keywords */
74         if (stream.match(keywordRegex)) { return 'keyword'; }
75       }
76
77       /* nothing found, continue */
78       state.pairStart = false;
79       state.escaped = (ch == '\\');
80       stream.next();
81       return null;
82     },
83     startState: function() {
84       return {
85         pair: false,
86         pairStart: false,
87         keyCol: 0,
88         inlinePairs: 0,
89         inlineList: 0,
90         literal: false,
91         escaped: false
92       };
93     }
94   };
95 });
96
97 CodeMirror.defineMIME("text/x-yaml", "yaml");