aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/yaml
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-24 12:08:49 -0800
committerPushkar Joshi2012-02-24 12:08:49 -0800
commit03ca7a5ed13c25faaa9100bb666e062fd15335e6 (patch)
treec51112223ceb9121cd595a60335eb2795215590f /imports/codemirror/mode/yaml
parentfcb12cc09eb3cd3b42bd215877ba18f449275b75 (diff)
parent053fc63a2950c7a5ee4ebf98033b64d474a3c46e (diff)
downloadninja-03ca7a5ed13c25faaa9100bb666e062fd15335e6.tar.gz
Merge branch 'pentool' into brushtool
Conflicts: imports/codemirror/mode/scheme/scheme.js js/tools/BrushTool.js
Diffstat (limited to 'imports/codemirror/mode/yaml')
-rwxr-xr-ximports/codemirror/mode/yaml/index.html67
-rwxr-xr-ximports/codemirror/mode/yaml/yaml.js95
2 files changed, 162 insertions, 0 deletions
diff --git a/imports/codemirror/mode/yaml/index.html b/imports/codemirror/mode/yaml/index.html
new file mode 100755
index 00000000..7f2c7929
--- /dev/null
+++ b/imports/codemirror/mode/yaml/index.html
@@ -0,0 +1,67 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror: YAML mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="yaml.js"></script>
8 <style>.CodeMirror { border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; }</style>
9 <link rel="stylesheet" href="../../doc/docs.css">
10 </head>
11 <body>
12 <h1>CodeMirror: YAML mode</h1>
13 <form><textarea id="code" name="code">
14--- # Favorite movies
15- Casablanca
16- North by Northwest
17- The Man Who Wasn't There
18--- # Shopping list
19[milk, pumpkin pie, eggs, juice]
20--- # Indented Blocks, common in YAML data files, use indentation and new lines to separate the key: value pairs
21 name: John Smith
22 age: 33
23--- # Inline Blocks, common in YAML data streams, use commas to separate the key: value pairs between braces
24{name: John Smith, age: 33}
25---
26receipt: Oz-Ware Purchase Invoice
27date: 2007-08-06
28customer:
29 given: Dorothy
30 family: Gale
31
32items:
33 - part_no: A4786
34 descrip: Water Bucket (Filled)
35 price: 1.47
36 quantity: 4
37
38 - part_no: E1628
39 descrip: High Heeled "Ruby" Slippers
40 size: 8
41 price: 100.27
42 quantity: 1
43
44bill-to: &id001
45 street: |
46 123 Tornado Alley
47 Suite 16
48 city: East Centerville
49 state: KS
50
51ship-to: *id001
52
53specialDelivery: >
54 Follow the Yellow Brick
55 Road to the Emerald City.
56 Pay no attention to the
57 man behind the curtain.
58...
59</textarea></form>
60 <script>
61 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
62 </script>
63
64 <p><strong>MIME types defined:</strong> <code>text/x-yaml</code>.</p>
65
66 </body>
67</html>
diff --git a/imports/codemirror/mode/yaml/yaml.js b/imports/codemirror/mode/yaml/yaml.js
new file mode 100755
index 00000000..59e2641a
--- /dev/null
+++ b/imports/codemirror/mode/yaml/yaml.js
@@ -0,0 +1,95 @@
1CodeMirror.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.skipToEnd(); return "comment"; }
13 if (state.literal && stream.indentation() > state.keyCol) {
14 stream.skipToEnd(); return "string";
15 } else if (state.literal) { state.literal = false; }
16 if (stream.sol()) {
17 state.keyCol = 0;
18 state.pair = false;
19 state.pairStart = false;
20 /* document start */
21 if(stream.match(/---/)) { return "def"; }
22 /* document end */
23 if (stream.match(/\.\.\./)) { return "def"; }
24 /* array list item */
25 if (stream.match(/\s*-\s+/)) { return 'meta'; }
26 }
27 /* pairs (associative arrays) -> key */
28 if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) {
29 state.pair = true;
30 state.keyCol = stream.indentation();
31 return "atom";
32 }
33 if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; }
34
35 /* inline pairs/lists */
36 if (stream.match(/^(\{|\}|\[|\])/)) {
37 if (ch == '{')
38 state.inlinePairs++;
39 else if (ch == '}')
40 state.inlinePairs--;
41 else if (ch == '[')
42 state.inlineList++;
43 else
44 state.inlineList--;
45 return 'meta';
46 }
47
48 /* list seperator */
49 if (state.inlineList > 0 && !esc && ch == ',') {
50 stream.next();
51 return 'meta';
52 }
53 /* pairs seperator */
54 if (state.inlinePairs > 0 && !esc && ch == ',') {
55 state.keyCol = 0;
56 state.pair = false;
57 state.pairStart = false;
58 stream.next();
59 return 'meta';
60 }
61
62 /* start of value of a pair */
63 if (state.pairStart) {
64 /* block literals */
65 if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; };
66 /* references */
67 if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; }
68 /* numbers */
69 if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; }
70 if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; }
71 /* keywords */
72 if (stream.match(keywordRegex)) { return 'keyword'; }
73 }
74
75 /* nothing found, continue */
76 state.pairStart = false;
77 state.escaped = (ch == '\\');
78 stream.next();
79 return null;
80 },
81 startState: function() {
82 return {
83 pair: false,
84 pairStart: false,
85 keyCol: 0,
86 inlinePairs: 0,
87 inlineList: 0,
88 literal: false,
89 escaped: false
90 };
91 }
92 };
93});
94
95CodeMirror.defineMIME("text/x-yaml", "yaml");