scratch – Diff between revs 75 and 125
?pathlinks?
Rev 75 | Rev 125 | |||
---|---|---|---|---|
1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
|
2 | var Dumper, Inline, Utils; |
2 | var Dumper, Inline, Utils; |
|
3 | |
3 | |
|
4 | Utils = require('./Utils'); |
4 | Utils = require('./Utils'); |
|
5 | |
5 | |
|
6 | Inline = require('./Inline'); |
6 | Inline = require('./Inline'); |
|
7 | |
7 | |
|
8 | Dumper = (function() { |
8 | Dumper = (function() { |
|
9 | function Dumper() {} |
9 | function Dumper() {} |
|
10 | |
10 | |
|
11 | Dumper.indentation = 4; |
11 | Dumper.indentation = 4; |
|
12 | |
12 | |
|
13 | Dumper.prototype.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) { |
13 | Dumper.prototype.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) { |
|
14 | var i, key, len, output, prefix, value, willBeInlined; |
14 | var i, key, len, output, prefix, value, willBeInlined; |
|
15 | if (inline == null) { |
15 | if (inline == null) { |
|
16 | inline = 0; |
16 | inline = 0; |
|
17 | } |
17 | } |
|
18 | if (indent == null) { |
18 | if (indent == null) { |
|
19 | indent = 0; |
19 | indent = 0; |
|
20 | } |
20 | } |
|
21 | if (exceptionOnInvalidType == null) { |
21 | if (exceptionOnInvalidType == null) { |
|
22 | exceptionOnInvalidType = false; |
22 | exceptionOnInvalidType = false; |
|
23 | } |
23 | } |
|
24 | if (objectEncoder == null) { |
24 | if (objectEncoder == null) { |
|
25 | objectEncoder = null; |
25 | objectEncoder = null; |
|
26 | } |
26 | } |
|
27 | output = ''; |
27 | output = ''; |
|
28 | prefix = (indent ? Utils.strRepeat(' ', indent) : ''); |
28 | prefix = (indent ? Utils.strRepeat(' ', indent) : ''); |
|
29 | if (inline <= 0 || typeof input !== 'object' || input instanceof Date || Utils.isEmpty(input)) { |
29 | if (inline <= 0 || typeof input !== 'object' || input instanceof Date || Utils.isEmpty(input)) { |
|
30 | output += prefix + Inline.dump(input, exceptionOnInvalidType, objectEncoder); |
30 | output += prefix + Inline.dump(input, exceptionOnInvalidType, objectEncoder); |
|
31 | } else { |
31 | } else { |
|
32 | if (input instanceof Array) { |
32 | if (input instanceof Array) { |
|
33 | for (i = 0, len = input.length; i < len; i++) { |
33 | for (i = 0, len = input.length; i < len; i++) { |
|
34 | value = input[i]; |
34 | value = input[i]; |
|
35 | willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value); |
35 | willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value); |
|
36 | output += prefix + '-' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : ''); |
36 | output += prefix + '-' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : ''); |
|
37 | } |
37 | } |
|
38 | } else { |
38 | } else { |
|
39 | for (key in input) { |
39 | for (key in input) { |
|
40 | value = input[key]; |
40 | value = input[key]; |
|
41 | willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value); |
41 | willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value); |
|
42 | output += prefix + Inline.dump(key, exceptionOnInvalidType, objectEncoder) + ':' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : ''); |
42 | output += prefix + Inline.dump(key, exceptionOnInvalidType, objectEncoder) + ':' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : ''); |
|
43 | } |
43 | } |
|
44 | } |
44 | } |
|
45 | } |
45 | } |
|
46 | return output; |
46 | return output; |
|
47 | }; |
47 | }; |
|
48 | |
48 | |
|
49 | return Dumper; |
49 | return Dumper; |
|
50 | |
50 | |
|
51 | })(); |
51 | })(); |
|
52 | |
52 | |
|
53 | module.exports = Dumper; |
53 | module.exports = Dumper; |
|
54 | |
54 | |
|
55 | |
55 | |
|
56 | },{"./Inline":5,"./Utils":9}],2:[function(require,module,exports){ |
56 | },{"./Inline":6,"./Utils":10}],2:[function(require,module,exports){ |
|
57 | var Escaper, Pattern; |
57 | var Escaper, Pattern; |
|
58 | |
58 | |
|
59 | Pattern = require('./Pattern'); |
59 | Pattern = require('./Pattern'); |
|
60 | |
60 | |
|
61 | Escaper = (function() { |
61 | Escaper = (function() { |
|
62 | var ch; |
62 | var ch; |
|
63 | |
63 | |
|
64 | function Escaper() {} |
64 | function Escaper() {} |
|
65 | |
65 | |
|
66 | Escaper.LIST_ESCAPEES = ['\\', '\\\\', '\\"', '"', "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", (ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)]; |
66 | Escaper.LIST_ESCAPEES = ['\\', '\\\\', '\\"', '"', "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", (ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)]; |
|
67 | |
67 | |
|
68 | Escaper.LIST_ESCAPED = ['\\\\', '\\"', '\\"', '\\"', "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f", "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17", "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f", "\\N", "\\_", "\\L", "\\P"]; |
68 | Escaper.LIST_ESCAPED = ['\\\\', '\\"', '\\"', '\\"', "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f", "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17", "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f", "\\N", "\\_", "\\L", "\\P"]; |
|
69 | |
69 | |
|
70 | Escaper.MAPPING_ESCAPEES_TO_ESCAPED = (function() { |
70 | Escaper.MAPPING_ESCAPEES_TO_ESCAPED = (function() { |
|
71 | var i, j, mapping, ref; |
71 | var i, j, mapping, ref; |
|
72 | mapping = {}; |
72 | mapping = {}; |
|
73 | for (i = j = 0, ref = Escaper.LIST_ESCAPEES.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { |
73 | for (i = j = 0, ref = Escaper.LIST_ESCAPEES.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { |
|
74 | mapping[Escaper.LIST_ESCAPEES[i]] = Escaper.LIST_ESCAPED[i]; |
74 | mapping[Escaper.LIST_ESCAPEES[i]] = Escaper.LIST_ESCAPED[i]; |
|
75 | } |
75 | } |
|
76 | return mapping; |
76 | return mapping; |
|
77 | })(); |
77 | })(); |
|
78 | |
78 | |
|
79 | Escaper.PATTERN_CHARACTERS_TO_ESCAPE = new Pattern('[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9'); |
79 | Escaper.PATTERN_CHARACTERS_TO_ESCAPE = new Pattern('[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9'); |
|
80 | |
80 | |
|
81 | Escaper.PATTERN_MAPPING_ESCAPEES = new Pattern(Escaper.LIST_ESCAPEES.join('|').split('\\').join('\\\\')); |
81 | Escaper.PATTERN_MAPPING_ESCAPEES = new Pattern(Escaper.LIST_ESCAPEES.join('|').split('\\').join('\\\\')); |
|
82 | |
82 | |
|
83 | Escaper.PATTERN_SINGLE_QUOTING = new Pattern('[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]'); |
83 | Escaper.PATTERN_SINGLE_QUOTING = new Pattern('[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]'); |
|
84 | |
84 | |
|
85 | Escaper.requiresDoubleQuoting = function(value) { |
85 | Escaper.requiresDoubleQuoting = function(value) { |
|
86 | return this.PATTERN_CHARACTERS_TO_ESCAPE.test(value); |
86 | return this.PATTERN_CHARACTERS_TO_ESCAPE.test(value); |
|
87 | }; |
87 | }; |
|
88 | |
88 | |
|
89 | Escaper.escapeWithDoubleQuotes = function(value) { |
89 | Escaper.escapeWithDoubleQuotes = function(value) { |
|
90 | var result; |
90 | var result; |
|
91 | result = this.PATTERN_MAPPING_ESCAPEES.replace(value, (function(_this) { |
91 | result = this.PATTERN_MAPPING_ESCAPEES.replace(value, (function(_this) { |
|
92 | return function(str) { |
92 | return function(str) { |
|
93 | return _this.MAPPING_ESCAPEES_TO_ESCAPED[str]; |
93 | return _this.MAPPING_ESCAPEES_TO_ESCAPED[str]; |
|
94 | }; |
94 | }; |
|
95 | })(this)); |
95 | })(this)); |
|
96 | return '"' + result + '"'; |
96 | return '"' + result + '"'; |
|
97 | }; |
97 | }; |
|
98 | |
98 | |
|
99 | Escaper.requiresSingleQuoting = function(value) { |
99 | Escaper.requiresSingleQuoting = function(value) { |
|
100 | return this.PATTERN_SINGLE_QUOTING.test(value); |
100 | return this.PATTERN_SINGLE_QUOTING.test(value); |
|
101 | }; |
101 | }; |
|
102 | |
102 | |
|
103 | Escaper.escapeWithSingleQuotes = function(value) { |
103 | Escaper.escapeWithSingleQuotes = function(value) { |
|
104 | return "'" + value.replace(/'/g, "''") + "'"; |
104 | return "'" + value.replace(/'/g, "''") + "'"; |
|
105 | }; |
105 | }; |
|
106 | |
106 | |
|
107 | return Escaper; |
107 | return Escaper; |
|
108 | |
108 | |
|
109 | })(); |
109 | })(); |
|
110 | |
110 | |
|
111 | module.exports = Escaper; |
111 | module.exports = Escaper; |
|
112 | |
112 | |
|
113 | |
113 | |
|
114 | },{"./Pattern":7}],3:[function(require,module,exports){ |
114 | },{"./Pattern":8}],3:[function(require,module,exports){ |
|
115 | var DumpException, |
115 | var DumpException, |
|
116 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
116 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
|
117 | hasProp = {}.hasOwnProperty; |
117 | hasProp = {}.hasOwnProperty; |
|
118 | |
118 | |
|
119 | DumpException = (function(superClass) { |
119 | DumpException = (function(superClass) { |
|
120 | extend(DumpException, superClass); |
120 | extend(DumpException, superClass); |
|
121 | |
121 | |
|
122 | function DumpException(message, parsedLine, snippet) { |
122 | function DumpException(message, parsedLine, snippet) { |
|
123 | this.message = message; |
123 | this.message = message; |
|
124 | this.parsedLine = parsedLine; |
124 | this.parsedLine = parsedLine; |
|
125 | this.snippet = snippet; |
125 | this.snippet = snippet; |
|
126 | } |
126 | } |
|
127 | |
127 | |
|
128 | DumpException.prototype.toString = function() { |
128 | DumpException.prototype.toString = function() { |
|
129 | if ((this.parsedLine != null) && (this.snippet != null)) { |
129 | if ((this.parsedLine != null) && (this.snippet != null)) { |
|
130 | return '<DumpException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')'; |
130 | return '<DumpException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')'; |
|
131 | } else { |
131 | } else { |
|
132 | return '<DumpException> ' + this.message; |
132 | return '<DumpException> ' + this.message; |
|
133 | } |
133 | } |
|
134 | }; |
134 | }; |
|
135 | |
135 | |
|
136 | return DumpException; |
136 | return DumpException; |
|
137 | |
137 | |
|
138 | })(Error); |
138 | })(Error); |
|
139 | |
139 | |
|
140 | module.exports = DumpException; |
140 | module.exports = DumpException; |
|
141 | |
141 | |
|
142 | |
142 | |
|
143 | },{}],4:[function(require,module,exports){ |
143 | },{}],4:[function(require,module,exports){ |
|
144 | var ParseException, |
144 | var ParseException, |
|
145 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
145 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
|
146 | hasProp = {}.hasOwnProperty; |
146 | hasProp = {}.hasOwnProperty; |
|
147 | |
147 | |
|
148 | ParseException = (function(superClass) { |
148 | ParseException = (function(superClass) { |
|
149 | extend(ParseException, superClass); |
149 | extend(ParseException, superClass); |
|
150 | |
150 | |
|
151 | function ParseException(message, parsedLine, snippet) { |
151 | function ParseException(message, parsedLine, snippet) { |
|
152 | this.message = message; |
152 | this.message = message; |
|
153 | this.parsedLine = parsedLine; |
153 | this.parsedLine = parsedLine; |
|
154 | this.snippet = snippet; |
154 | this.snippet = snippet; |
|
155 | } |
155 | } |
|
156 | |
156 | |
|
157 | ParseException.prototype.toString = function() { |
157 | ParseException.prototype.toString = function() { |
|
158 | if ((this.parsedLine != null) && (this.snippet != null)) { |
158 | if ((this.parsedLine != null) && (this.snippet != null)) { |
|
159 | return '<ParseException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')'; |
159 | return '<ParseException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')'; |
|
160 | } else { |
160 | } else { |
|
161 | return '<ParseException> ' + this.message; |
161 | return '<ParseException> ' + this.message; |
|
162 | } |
162 | } |
|
163 | }; |
163 | }; |
|
164 | |
164 | |
|
165 | return ParseException; |
165 | return ParseException; |
|
166 | |
166 | |
|
167 | })(Error); |
167 | })(Error); |
|
168 | |
168 | |
|
169 | module.exports = ParseException; |
169 | module.exports = ParseException; |
|
170 | |
170 | |
|
171 | |
171 | |
|
172 | },{}],5:[function(require,module,exports){ |
172 | },{}],5:[function(require,module,exports){ |
|
- | 173 | var ParseMore, |
||
- | 174 | extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, |
||
- | 175 | hasProp = {}.hasOwnProperty; |
||
- | 176 | |
||
- | 177 | ParseMore = (function(superClass) { |
||
- | 178 | extend(ParseMore, superClass); |
||
- | 179 | |
||
- | 180 | function ParseMore(message, parsedLine, snippet) { |
||
- | 181 | this.message = message; |
||
- | 182 | this.parsedLine = parsedLine; |
||
- | 183 | this.snippet = snippet; |
||
- | 184 | } |
||
- | 185 | |
||
- | 186 | ParseMore.prototype.toString = function() { |
||
- | 187 | if ((this.parsedLine != null) && (this.snippet != null)) { |
||
- | 188 | return '<ParseMore> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')'; |
||
- | 189 | } else { |
||
- | 190 | return '<ParseMore> ' + this.message; |
||
- | 191 | } |
||
- | 192 | }; |
||
- | 193 | |
||
- | 194 | return ParseMore; |
||
- | 195 | |
||
- | 196 | })(Error); |
||
- | 197 | |
||
- | 198 | module.exports = ParseMore; |
||
- | 199 | |
||
- | 200 | |
||
- | 201 | },{}],6:[function(require,module,exports){ |
||
173 | var DumpException, Escaper, Inline, ParseException, Pattern, Unescaper, Utils, |
202 | var DumpException, Escaper, Inline, ParseException, ParseMore, Pattern, Unescaper, Utils, |
|
174 | indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
203 | indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; |
|
175 | |
204 | |
|
176 | Pattern = require('./Pattern'); |
205 | Pattern = require('./Pattern'); |
|
177 | |
206 | |
|
178 | Unescaper = require('./Unescaper'); |
207 | Unescaper = require('./Unescaper'); |
|
179 | |
208 | |
|
180 | Escaper = require('./Escaper'); |
209 | Escaper = require('./Escaper'); |
|
181 | |
210 | |
|
182 | Utils = require('./Utils'); |
211 | Utils = require('./Utils'); |
|
183 | |
212 | |
|
184 | ParseException = require('./Exception/ParseException'); |
213 | ParseException = require('./Exception/ParseException'); |
|
- | 214 | |
||
- | 215 | ParseMore = require('./Exception/ParseMore'); |
||
185 | |
216 | |
|
186 | DumpException = require('./Exception/DumpException'); |
217 | DumpException = require('./Exception/DumpException'); |
|
187 | |
218 | |
|
188 | Inline = (function() { |
219 | Inline = (function() { |
|
189 | function Inline() {} |
220 | function Inline() {} |
|
190 | |
221 | |
|
191 | Inline.REGEX_QUOTED_STRING = '(?:"(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\']*(?:\'\'[^\']*)*)\')'; |
222 | Inline.REGEX_QUOTED_STRING = '(?:"(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\']*(?:\'\'[^\']*)*)\')'; |
|
192 | |
223 | |
|
193 | Inline.PATTERN_TRAILING_COMMENTS = new Pattern('^\\s*#.*$'); |
224 | Inline.PATTERN_TRAILING_COMMENTS = new Pattern('^\\s*#.*$'); |
|
194 | |
225 | |
|
195 | Inline.PATTERN_QUOTED_SCALAR = new Pattern('^' + Inline.REGEX_QUOTED_STRING); |
226 | Inline.PATTERN_QUOTED_SCALAR = new Pattern('^' + Inline.REGEX_QUOTED_STRING); |
|
196 | |
227 | |
|
197 | Inline.PATTERN_THOUSAND_NUMERIC_SCALAR = new Pattern('^(-|\\+)?[0-9,]+(\\.[0-9]+)?$'); |
228 | Inline.PATTERN_THOUSAND_NUMERIC_SCALAR = new Pattern('^(-|\\+)?[0-9,]+(\\.[0-9]+)?$'); |
|
198 | |
229 | |
|
199 | Inline.PATTERN_SCALAR_BY_DELIMITERS = {}; |
230 | Inline.PATTERN_SCALAR_BY_DELIMITERS = {}; |
|
200 | |
231 | |
|
201 | Inline.settings = {}; |
232 | Inline.settings = {}; |
|
202 | |
233 | |
|
203 | Inline.configure = function(exceptionOnInvalidType, objectDecoder) { |
234 | Inline.configure = function(exceptionOnInvalidType, objectDecoder) { |
|
204 | if (exceptionOnInvalidType == null) { |
235 | if (exceptionOnInvalidType == null) { |
|
205 | exceptionOnInvalidType = null; |
236 | exceptionOnInvalidType = null; |
|
206 | } |
237 | } |
|
207 | if (objectDecoder == null) { |
238 | if (objectDecoder == null) { |
|
208 | objectDecoder = null; |
239 | objectDecoder = null; |
|
209 | } |
240 | } |
|
210 | this.settings.exceptionOnInvalidType = exceptionOnInvalidType; |
241 | this.settings.exceptionOnInvalidType = exceptionOnInvalidType; |
|
211 | this.settings.objectDecoder = objectDecoder; |
242 | this.settings.objectDecoder = objectDecoder; |
|
212 | }; |
243 | }; |
|
213 | |
244 | |
|
214 | Inline.parse = function(value, exceptionOnInvalidType, objectDecoder) { |
245 | Inline.parse = function(value, exceptionOnInvalidType, objectDecoder) { |
|
215 | var context, result; |
246 | var context, result; |
|
216 | if (exceptionOnInvalidType == null) { |
247 | if (exceptionOnInvalidType == null) { |
|
217 | exceptionOnInvalidType = false; |
248 | exceptionOnInvalidType = false; |
|
218 | } |
249 | } |
|
219 | if (objectDecoder == null) { |
250 | if (objectDecoder == null) { |
|
220 | objectDecoder = null; |
251 | objectDecoder = null; |
|
221 | } |
252 | } |
|
222 | this.settings.exceptionOnInvalidType = exceptionOnInvalidType; |
253 | this.settings.exceptionOnInvalidType = exceptionOnInvalidType; |
|
223 | this.settings.objectDecoder = objectDecoder; |
254 | this.settings.objectDecoder = objectDecoder; |
|
224 | if (value == null) { |
255 | if (value == null) { |
|
225 | return ''; |
256 | return ''; |
|
226 | } |
257 | } |
|
227 | value = Utils.trim(value); |
258 | value = Utils.trim(value); |
|
228 | if (0 === value.length) { |
259 | if (0 === value.length) { |
|
229 | return ''; |
260 | return ''; |
|
230 | } |
261 | } |
|
231 | context = { |
262 | context = { |
|
232 | exceptionOnInvalidType: exceptionOnInvalidType, |
263 | exceptionOnInvalidType: exceptionOnInvalidType, |
|
233 | objectDecoder: objectDecoder, |
264 | objectDecoder: objectDecoder, |
|
234 | i: 0 |
265 | i: 0 |
|
235 | }; |
266 | }; |
|
236 | switch (value.charAt(0)) { |
267 | switch (value.charAt(0)) { |
|
237 | case '[': |
268 | case '[': |
|
238 | result = this.parseSequence(value, context); |
269 | result = this.parseSequence(value, context); |
|
239 | ++context.i; |
270 | ++context.i; |
|
240 | break; |
271 | break; |
|
241 | case '{': |
272 | case '{': |
|
242 | result = this.parseMapping(value, context); |
273 | result = this.parseMapping(value, context); |
|
243 | ++context.i; |
274 | ++context.i; |
|
244 | break; |
275 | break; |
|
245 | default: |
276 | default: |
|
246 | result = this.parseScalar(value, null, ['"', "'"], context); |
277 | result = this.parseScalar(value, null, ['"', "'"], context); |
|
247 | } |
278 | } |
|
248 | if (this.PATTERN_TRAILING_COMMENTS.replace(value.slice(context.i), '') !== '') { |
279 | if (this.PATTERN_TRAILING_COMMENTS.replace(value.slice(context.i), '') !== '') { |
|
249 | throw new ParseException('Unexpected characters near "' + value.slice(context.i) + '".'); |
280 | throw new ParseException('Unexpected characters near "' + value.slice(context.i) + '".'); |
|
250 | } |
281 | } |
|
251 | return result; |
282 | return result; |
|
252 | }; |
283 | }; |
|
253 | |
284 | |
|
254 | Inline.dump = function(value, exceptionOnInvalidType, objectEncoder) { |
285 | Inline.dump = function(value, exceptionOnInvalidType, objectEncoder) { |
|
255 | var ref, result, type; |
286 | var ref, result, type; |
|
256 | if (exceptionOnInvalidType == null) { |
287 | if (exceptionOnInvalidType == null) { |
|
257 | exceptionOnInvalidType = false; |
288 | exceptionOnInvalidType = false; |
|
258 | } |
289 | } |
|
259 | if (objectEncoder == null) { |
290 | if (objectEncoder == null) { |
|
260 | objectEncoder = null; |
291 | objectEncoder = null; |
|
261 | } |
292 | } |
|
262 | if (value == null) { |
293 | if (value == null) { |
|
263 | return 'null'; |
294 | return 'null'; |
|
264 | } |
295 | } |
|
265 | type = typeof value; |
296 | type = typeof value; |
|
266 | if (type === 'object') { |
297 | if (type === 'object') { |
|
267 | if (value instanceof Date) { |
298 | if (value instanceof Date) { |
|
268 | return value.toISOString(); |
299 | return value.toISOString(); |
|
269 | } else if (objectEncoder != null) { |
300 | } else if (objectEncoder != null) { |
|
270 | result = objectEncoder(value); |
301 | result = objectEncoder(value); |
|
271 | if (typeof result === 'string' || (result != null)) { |
302 | if (typeof result === 'string' || (result != null)) { |
|
272 | return result; |
303 | return result; |
|
273 | } |
304 | } |
|
274 | } |
305 | } |
|
275 | return this.dumpObject(value); |
306 | return this.dumpObject(value); |
|
276 | } |
307 | } |
|
277 | if (type === 'boolean') { |
308 | if (type === 'boolean') { |
|
278 | return (value ? 'true' : 'false'); |
309 | return (value ? 'true' : 'false'); |
|
279 | } |
310 | } |
|
280 | if (Utils.isDigits(value)) { |
311 | if (Utils.isDigits(value)) { |
|
281 | return (type === 'string' ? "'" + value + "'" : String(parseInt(value))); |
312 | return (type === 'string' ? "'" + value + "'" : String(parseInt(value))); |
|
282 | } |
313 | } |
|
283 | if (Utils.isNumeric(value)) { |
314 | if (Utils.isNumeric(value)) { |
|
284 | return (type === 'string' ? "'" + value + "'" : String(parseFloat(value))); |
315 | return (type === 'string' ? "'" + value + "'" : String(parseFloat(value))); |
|
285 | } |
316 | } |
|
286 | if (type === 'number') { |
317 | if (type === 'number') { |
|
287 | return (value === Infinity ? '.Inf' : (value === -Infinity ? '-.Inf' : (isNaN(value) ? '.NaN' : value))); |
318 | return (value === Infinity ? '.Inf' : (value === -Infinity ? '-.Inf' : (isNaN(value) ? '.NaN' : value))); |
|
288 | } |
319 | } |
|
289 | if (Escaper.requiresDoubleQuoting(value)) { |
320 | if (Escaper.requiresDoubleQuoting(value)) { |
|
290 | return Escaper.escapeWithDoubleQuotes(value); |
321 | return Escaper.escapeWithDoubleQuotes(value); |
|
291 | } |
322 | } |
|
292 | if (Escaper.requiresSingleQuoting(value)) { |
323 | if (Escaper.requiresSingleQuoting(value)) { |
|
293 | return Escaper.escapeWithSingleQuotes(value); |
324 | return Escaper.escapeWithSingleQuotes(value); |
|
294 | } |
325 | } |
|
295 | if ('' === value) { |
326 | if ('' === value) { |
|
296 | return '""'; |
327 | return '""'; |
|
297 | } |
328 | } |
|
298 | if (Utils.PATTERN_DATE.test(value)) { |
329 | if (Utils.PATTERN_DATE.test(value)) { |
|
299 | return "'" + value + "'"; |
330 | return "'" + value + "'"; |
|
300 | } |
331 | } |
|
301 | if ((ref = value.toLowerCase()) === 'null' || ref === '~' || ref === 'true' || ref === 'false') { |
332 | if ((ref = value.toLowerCase()) === 'null' || ref === '~' || ref === 'true' || ref === 'false') { |
|
302 | return "'" + value + "'"; |
333 | return "'" + value + "'"; |
|
303 | } |
334 | } |
|
304 | return value; |
335 | return value; |
|
305 | }; |
336 | }; |
|
306 | |
337 | |
|
307 | Inline.dumpObject = function(value, exceptionOnInvalidType, objectSupport) { |
338 | Inline.dumpObject = function(value, exceptionOnInvalidType, objectSupport) { |
|
308 | var j, key, len1, output, val; |
339 | var j, key, len1, output, val; |
|
309 | if (objectSupport == null) { |
340 | if (objectSupport == null) { |
|
310 | objectSupport = null; |
341 | objectSupport = null; |
|
311 | } |
342 | } |
|
312 | if (value instanceof Array) { |
343 | if (value instanceof Array) { |
|
313 | output = []; |
344 | output = []; |
|
314 | for (j = 0, len1 = value.length; j < len1; j++) { |
345 | for (j = 0, len1 = value.length; j < len1; j++) { |
|
315 | val = value[j]; |
346 | val = value[j]; |
|
316 | output.push(this.dump(val)); |
347 | output.push(this.dump(val)); |
|
317 | } |
348 | } |
|
318 | return '[' + output.join(', ') + ']'; |
349 | return '[' + output.join(', ') + ']'; |
|
319 | } else { |
350 | } else { |
|
320 | output = []; |
351 | output = []; |
|
321 | for (key in value) { |
352 | for (key in value) { |
|
322 | val = value[key]; |
353 | val = value[key]; |
|
323 | output.push(this.dump(key) + ': ' + this.dump(val)); |
354 | output.push(this.dump(key) + ': ' + this.dump(val)); |
|
324 | } |
355 | } |
|
325 | return '{' + output.join(', ') + '}'; |
356 | return '{' + output.join(', ') + '}'; |
|
326 | } |
357 | } |
|
327 | }; |
358 | }; |
|
328 | |
359 | |
|
329 | Inline.parseScalar = function(scalar, delimiters, stringDelimiters, context, evaluate) { |
360 | Inline.parseScalar = function(scalar, delimiters, stringDelimiters, context, evaluate) { |
|
330 | var i, joinedDelimiters, match, output, pattern, ref, ref1, strpos, tmp; |
361 | var i, joinedDelimiters, match, output, pattern, ref, ref1, strpos, tmp; |
|
331 | if (delimiters == null) { |
362 | if (delimiters == null) { |
|
332 | delimiters = null; |
363 | delimiters = null; |
|
333 | } |
364 | } |
|
334 | if (stringDelimiters == null) { |
365 | if (stringDelimiters == null) { |
|
335 | stringDelimiters = ['"', "'"]; |
366 | stringDelimiters = ['"', "'"]; |
|
336 | } |
367 | } |
|
337 | if (context == null) { |
368 | if (context == null) { |
|
338 | context = null; |
369 | context = null; |
|
339 | } |
370 | } |
|
340 | if (evaluate == null) { |
371 | if (evaluate == null) { |
|
341 | evaluate = true; |
372 | evaluate = true; |
|
342 | } |
373 | } |
|
343 | if (context == null) { |
374 | if (context == null) { |
|
344 | context = { |
375 | context = { |
|
345 | exceptionOnInvalidType: this.settings.exceptionOnInvalidType, |
376 | exceptionOnInvalidType: this.settings.exceptionOnInvalidType, |
|
346 | objectDecoder: this.settings.objectDecoder, |
377 | objectDecoder: this.settings.objectDecoder, |
|
347 | i: 0 |
378 | i: 0 |
|
348 | }; |
379 | }; |
|
349 | } |
380 | } |
|
350 | i = context.i; |
381 | i = context.i; |
|
351 | if (ref = scalar.charAt(i), indexOf.call(stringDelimiters, ref) >= 0) { |
382 | if (ref = scalar.charAt(i), indexOf.call(stringDelimiters, ref) >= 0) { |
|
352 | output = this.parseQuotedScalar(scalar, context); |
383 | output = this.parseQuotedScalar(scalar, context); |
|
353 | i = context.i; |
384 | i = context.i; |
|
354 | if (delimiters != null) { |
385 | if (delimiters != null) { |
|
355 | tmp = Utils.ltrim(scalar.slice(i), ' '); |
386 | tmp = Utils.ltrim(scalar.slice(i), ' '); |
|
356 | if (!(ref1 = tmp.charAt(0), indexOf.call(delimiters, ref1) >= 0)) { |
387 | if (!(ref1 = tmp.charAt(0), indexOf.call(delimiters, ref1) >= 0)) { |
|
357 | throw new ParseException('Unexpected characters (' + scalar.slice(i) + ').'); |
388 | throw new ParseException('Unexpected characters (' + scalar.slice(i) + ').'); |
|
358 | } |
389 | } |
|
359 | } |
390 | } |
|
360 | } else { |
391 | } else { |
|
361 | if (!delimiters) { |
392 | if (!delimiters) { |
|
362 | output = scalar.slice(i); |
393 | output = scalar.slice(i); |
|
363 | i += output.length; |
394 | i += output.length; |
|
364 | strpos = output.indexOf(' #'); |
395 | strpos = output.indexOf(' #'); |
|
365 | if (strpos !== -1) { |
396 | if (strpos !== -1) { |
|
366 | output = Utils.rtrim(output.slice(0, strpos)); |
397 | output = Utils.rtrim(output.slice(0, strpos)); |
|
367 | } |
398 | } |
|
368 | } else { |
399 | } else { |
|
369 | joinedDelimiters = delimiters.join('|'); |
400 | joinedDelimiters = delimiters.join('|'); |
|
370 | pattern = this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters]; |
401 | pattern = this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters]; |
|
371 | if (pattern == null) { |
402 | if (pattern == null) { |
|
372 | pattern = new Pattern('^(.+?)(' + joinedDelimiters + ')'); |
403 | pattern = new Pattern('^(.+?)(' + joinedDelimiters + ')'); |
|
373 | this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters] = pattern; |
404 | this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters] = pattern; |
|
374 | } |
405 | } |
|
375 | if (match = pattern.exec(scalar.slice(i))) { |
406 | if (match = pattern.exec(scalar.slice(i))) { |
|
376 | output = match[1]; |
407 | output = match[1]; |
|
377 | i += output.length; |
408 | i += output.length; |
|
378 | } else { |
409 | } else { |
|
379 | throw new ParseException('Malformed inline YAML string (' + scalar + ').'); |
410 | throw new ParseException('Malformed inline YAML string (' + scalar + ').'); |
|
380 | } |
411 | } |
|
381 | } |
412 | } |
|
382 | if (evaluate) { |
413 | if (evaluate) { |
|
383 | output = this.evaluateScalar(output, context); |
414 | output = this.evaluateScalar(output, context); |
|
384 | } |
415 | } |
|
385 | } |
416 | } |
|
386 | context.i = i; |
417 | context.i = i; |
|
387 | return output; |
418 | return output; |
|
388 | }; |
419 | }; |
|
389 | |
420 | |
|
390 | Inline.parseQuotedScalar = function(scalar, context) { |
421 | Inline.parseQuotedScalar = function(scalar, context) { |
|
391 | var i, match, output; |
422 | var i, match, output; |
|
392 | i = context.i; |
423 | i = context.i; |
|
393 | if (!(match = this.PATTERN_QUOTED_SCALAR.exec(scalar.slice(i)))) { |
424 | if (!(match = this.PATTERN_QUOTED_SCALAR.exec(scalar.slice(i)))) { |
|
394 | throw new ParseException('Malformed inline YAML string (' + scalar.slice(i) + ').'); |
425 | throw new ParseMore('Malformed inline YAML string (' + scalar.slice(i) + ').'); |
|
395 | } |
426 | } |
|
396 | output = match[0].substr(1, match[0].length - 2); |
427 | output = match[0].substr(1, match[0].length - 2); |
|
397 | if ('"' === scalar.charAt(i)) { |
428 | if ('"' === scalar.charAt(i)) { |
|
398 | output = Unescaper.unescapeDoubleQuotedString(output); |
429 | output = Unescaper.unescapeDoubleQuotedString(output); |
|
399 | } else { |
430 | } else { |
|
400 | output = Unescaper.unescapeSingleQuotedString(output); |
431 | output = Unescaper.unescapeSingleQuotedString(output); |
|
401 | } |
432 | } |
|
402 | i += match[0].length; |
433 | i += match[0].length; |
|
403 | context.i = i; |
434 | context.i = i; |
|
404 | return output; |
435 | return output; |
|
405 | }; |
436 | }; |
|
406 | |
437 | |
|
407 | Inline.parseSequence = function(sequence, context) { |
438 | Inline.parseSequence = function(sequence, context) { |
|
408 | var e, error, i, isQuoted, len, output, ref, value; |
439 | var e, error, i, isQuoted, len, output, ref, value; |
|
409 | output = []; |
440 | output = []; |
|
410 | len = sequence.length; |
441 | len = sequence.length; |
|
411 | i = context.i; |
442 | i = context.i; |
|
412 | i += 1; |
443 | i += 1; |
|
413 | while (i < len) { |
444 | while (i < len) { |
|
414 | context.i = i; |
445 | context.i = i; |
|
415 | switch (sequence.charAt(i)) { |
446 | switch (sequence.charAt(i)) { |
|
416 | case '[': |
447 | case '[': |
|
417 | output.push(this.parseSequence(sequence, context)); |
448 | output.push(this.parseSequence(sequence, context)); |
|
418 | i = context.i; |
449 | i = context.i; |
|
419 | break; |
450 | break; |
|
420 | case '{': |
451 | case '{': |
|
421 | output.push(this.parseMapping(sequence, context)); |
452 | output.push(this.parseMapping(sequence, context)); |
|
422 | i = context.i; |
453 | i = context.i; |
|
423 | break; |
454 | break; |
|
424 | case ']': |
455 | case ']': |
|
425 | return output; |
456 | return output; |
|
426 | case ',': |
457 | case ',': |
|
427 | case ' ': |
458 | case ' ': |
|
428 | case "\n": |
459 | case "\n": |
|
429 | break; |
460 | break; |
|
430 | default: |
461 | default: |
|
431 | isQuoted = ((ref = sequence.charAt(i)) === '"' || ref === "'"); |
462 | isQuoted = ((ref = sequence.charAt(i)) === '"' || ref === "'"); |
|
432 | value = this.parseScalar(sequence, [',', ']'], ['"', "'"], context); |
463 | value = this.parseScalar(sequence, [',', ']'], ['"', "'"], context); |
|
433 | i = context.i; |
464 | i = context.i; |
|
434 | if (!isQuoted && typeof value === 'string' && (value.indexOf(': ') !== -1 || value.indexOf(":\n") !== -1)) { |
465 | if (!isQuoted && typeof value === 'string' && (value.indexOf(': ') !== -1 || value.indexOf(":\n") !== -1)) { |
|
435 | try { |
466 | try { |
|
436 | value = this.parseMapping('{' + value + '}'); |
467 | value = this.parseMapping('{' + value + '}'); |
|
437 | } catch (error) { |
468 | } catch (error) { |
|
438 | e = error; |
469 | e = error; |
|
439 | } |
470 | } |
|
440 | } |
471 | } |
|
441 | output.push(value); |
472 | output.push(value); |
|
442 | --i; |
473 | --i; |
|
443 | } |
474 | } |
|
444 | ++i; |
475 | ++i; |
|
445 | } |
476 | } |
|
446 | throw new ParseException('Malformed inline YAML string ' + sequence); |
477 | throw new ParseMore('Malformed inline YAML string ' + sequence); |
|
447 | }; |
478 | }; |
|
448 | |
479 | |
|
449 | Inline.parseMapping = function(mapping, context) { |
480 | Inline.parseMapping = function(mapping, context) { |
|
450 | var done, i, key, len, output, shouldContinueWhileLoop, value; |
481 | var done, i, key, len, output, shouldContinueWhileLoop, value; |
|
451 | output = {}; |
482 | output = {}; |
|
452 | len = mapping.length; |
483 | len = mapping.length; |
|
453 | i = context.i; |
484 | i = context.i; |
|
454 | i += 1; |
485 | i += 1; |
|
455 | shouldContinueWhileLoop = false; |
486 | shouldContinueWhileLoop = false; |
|
456 | while (i < len) { |
487 | while (i < len) { |
|
457 | context.i = i; |
488 | context.i = i; |
|
458 | switch (mapping.charAt(i)) { |
489 | switch (mapping.charAt(i)) { |
|
459 | case ' ': |
490 | case ' ': |
|
460 | case ',': |
491 | case ',': |
|
461 | case "\n": |
492 | case "\n": |
|
462 | ++i; |
493 | ++i; |
|
463 | context.i = i; |
494 | context.i = i; |
|
464 | shouldContinueWhileLoop = true; |
495 | shouldContinueWhileLoop = true; |
|
465 | break; |
496 | break; |
|
466 | case '}': |
497 | case '}': |
|
467 | return output; |
498 | return output; |
|
468 | } |
499 | } |
|
469 | if (shouldContinueWhileLoop) { |
500 | if (shouldContinueWhileLoop) { |
|
470 | shouldContinueWhileLoop = false; |
501 | shouldContinueWhileLoop = false; |
|
471 | continue; |
502 | continue; |
|
472 | } |
503 | } |
|
473 | key = this.parseScalar(mapping, [':', ' ', "\n"], ['"', "'"], context, false); |
504 | key = this.parseScalar(mapping, [':', ' ', "\n"], ['"', "'"], context, false); |
|
474 | i = context.i; |
505 | i = context.i; |
|
475 | done = false; |
506 | done = false; |
|
476 | while (i < len) { |
507 | while (i < len) { |
|
477 | context.i = i; |
508 | context.i = i; |
|
478 | switch (mapping.charAt(i)) { |
509 | switch (mapping.charAt(i)) { |
|
479 | case '[': |
510 | case '[': |
|
480 | value = this.parseSequence(mapping, context); |
511 | value = this.parseSequence(mapping, context); |
|
481 | i = context.i; |
512 | i = context.i; |
|
482 | if (output[key] === void 0) { |
513 | if (output[key] === void 0) { |
|
483 | output[key] = value; |
514 | output[key] = value; |
|
484 | } |
515 | } |
|
485 | done = true; |
516 | done = true; |
|
486 | break; |
517 | break; |
|
487 | case '{': |
518 | case '{': |
|
488 | value = this.parseMapping(mapping, context); |
519 | value = this.parseMapping(mapping, context); |
|
489 | i = context.i; |
520 | i = context.i; |
|
490 | if (output[key] === void 0) { |
521 | if (output[key] === void 0) { |
|
491 | output[key] = value; |
522 | output[key] = value; |
|
492 | } |
523 | } |
|
493 | done = true; |
524 | done = true; |
|
494 | break; |
525 | break; |
|
495 | case ':': |
526 | case ':': |
|
496 | case ' ': |
527 | case ' ': |
|
497 | case "\n": |
528 | case "\n": |
|
498 | break; |
529 | break; |
|
499 | default: |
530 | default: |
|
500 | value = this.parseScalar(mapping, [',', '}'], ['"', "'"], context); |
531 | value = this.parseScalar(mapping, [',', '}'], ['"', "'"], context); |
|
501 | i = context.i; |
532 | i = context.i; |
|
502 | if (output[key] === void 0) { |
533 | if (output[key] === void 0) { |
|
503 | output[key] = value; |
534 | output[key] = value; |
|
504 | } |
535 | } |
|
505 | done = true; |
536 | done = true; |
|
506 | --i; |
537 | --i; |
|
507 | } |
538 | } |
|
508 | ++i; |
539 | ++i; |
|
509 | if (done) { |
540 | if (done) { |
|
510 | break; |
541 | break; |
|
511 | } |
542 | } |
|
512 | } |
543 | } |
|
513 | } |
544 | } |
|
514 | throw new ParseException('Malformed inline YAML string ' + mapping); |
545 | throw new ParseMore('Malformed inline YAML string ' + mapping); |
|
515 | }; |
546 | }; |
|
516 | |
547 | |
|
517 | Inline.evaluateScalar = function(scalar, context) { |
548 | Inline.evaluateScalar = function(scalar, context) { |
|
518 | var cast, date, exceptionOnInvalidType, firstChar, firstSpace, firstWord, objectDecoder, raw, scalarLower, subValue, trimmedScalar; |
549 | var cast, date, exceptionOnInvalidType, firstChar, firstSpace, firstWord, objectDecoder, raw, scalarLower, subValue, trimmedScalar; |
|
519 | scalar = Utils.trim(scalar); |
550 | scalar = Utils.trim(scalar); |
|
520 | scalarLower = scalar.toLowerCase(); |
551 | scalarLower = scalar.toLowerCase(); |
|
521 | switch (scalarLower) { |
552 | switch (scalarLower) { |
|
522 | case 'null': |
553 | case 'null': |
|
523 | case '': |
554 | case '': |
|
524 | case '~': |
555 | case '~': |
|
525 | return null; |
556 | return null; |
|
526 | case 'true': |
557 | case 'true': |
|
527 | return true; |
558 | return true; |
|
528 | case 'false': |
559 | case 'false': |
|
529 | return false; |
560 | return false; |
|
530 | case '.inf': |
561 | case '.inf': |
|
531 | return Infinity; |
562 | return Infinity; |
|
532 | case '.nan': |
563 | case '.nan': |
|
533 | return NaN; |
564 | return NaN; |
|
534 | case '-.inf': |
565 | case '-.inf': |
|
535 | return Infinity; |
566 | return Infinity; |
|
536 | default: |
567 | default: |
|
537 | firstChar = scalarLower.charAt(0); |
568 | firstChar = scalarLower.charAt(0); |
|
538 | switch (firstChar) { |
569 | switch (firstChar) { |
|
539 | case '!': |
570 | case '!': |
|
540 | firstSpace = scalar.indexOf(' '); |
571 | firstSpace = scalar.indexOf(' '); |
|
541 | if (firstSpace === -1) { |
572 | if (firstSpace === -1) { |
|
542 | firstWord = scalarLower; |
573 | firstWord = scalarLower; |
|
543 | } else { |
574 | } else { |
|
544 | firstWord = scalarLower.slice(0, firstSpace); |
575 | firstWord = scalarLower.slice(0, firstSpace); |
|
545 | } |
576 | } |
|
546 | switch (firstWord) { |
577 | switch (firstWord) { |
|
547 | case '!': |
578 | case '!': |
|
548 | if (firstSpace !== -1) { |
579 | if (firstSpace !== -1) { |
|
549 | return parseInt(this.parseScalar(scalar.slice(2))); |
580 | return parseInt(this.parseScalar(scalar.slice(2))); |
|
550 | } |
581 | } |
|
551 | return null; |
582 | return null; |
|
552 | case '!str': |
583 | case '!str': |
|
553 | return Utils.ltrim(scalar.slice(4)); |
584 | return Utils.ltrim(scalar.slice(4)); |
|
554 | case '!!str': |
585 | case '!!str': |
|
555 | return Utils.ltrim(scalar.slice(5)); |
586 | return Utils.ltrim(scalar.slice(5)); |
|
556 | case '!!int': |
587 | case '!!int': |
|
557 | return parseInt(this.parseScalar(scalar.slice(5))); |
588 | return parseInt(this.parseScalar(scalar.slice(5))); |
|
558 | case '!!bool': |
589 | case '!!bool': |
|
559 | return Utils.parseBoolean(this.parseScalar(scalar.slice(6)), false); |
590 | return Utils.parseBoolean(this.parseScalar(scalar.slice(6)), false); |
|
560 | case '!!float': |
591 | case '!!float': |
|
561 | return parseFloat(this.parseScalar(scalar.slice(7))); |
592 | return parseFloat(this.parseScalar(scalar.slice(7))); |
|
562 | case '!!timestamp': |
593 | case '!!timestamp': |
|
563 | return Utils.stringToDate(Utils.ltrim(scalar.slice(11))); |
594 | return Utils.stringToDate(Utils.ltrim(scalar.slice(11))); |
|
564 | default: |
595 | default: |
|
565 | if (context == null) { |
596 | if (context == null) { |
|
566 | context = { |
597 | context = { |
|
567 | exceptionOnInvalidType: this.settings.exceptionOnInvalidType, |
598 | exceptionOnInvalidType: this.settings.exceptionOnInvalidType, |
|
568 | objectDecoder: this.settings.objectDecoder, |
599 | objectDecoder: this.settings.objectDecoder, |
|
569 | i: 0 |
600 | i: 0 |
|
570 | }; |
601 | }; |
|
571 | } |
602 | } |
|
572 | objectDecoder = context.objectDecoder, exceptionOnInvalidType = context.exceptionOnInvalidType; |
603 | objectDecoder = context.objectDecoder, exceptionOnInvalidType = context.exceptionOnInvalidType; |
|
573 | if (objectDecoder) { |
604 | if (objectDecoder) { |
|
574 | trimmedScalar = Utils.rtrim(scalar); |
605 | trimmedScalar = Utils.rtrim(scalar); |
|
575 | firstSpace = trimmedScalar.indexOf(' '); |
606 | firstSpace = trimmedScalar.indexOf(' '); |
|
576 | if (firstSpace === -1) { |
607 | if (firstSpace === -1) { |
|
577 | return objectDecoder(trimmedScalar, null); |
608 | return objectDecoder(trimmedScalar, null); |
|
578 | } else { |
609 | } else { |
|
579 | subValue = Utils.ltrim(trimmedScalar.slice(firstSpace + 1)); |
610 | subValue = Utils.ltrim(trimmedScalar.slice(firstSpace + 1)); |
|
580 | if (!(subValue.length > 0)) { |
611 | if (!(subValue.length > 0)) { |
|
581 | subValue = null; |
612 | subValue = null; |
|
582 | } |
613 | } |
|
583 | return objectDecoder(trimmedScalar.slice(0, firstSpace), subValue); |
614 | return objectDecoder(trimmedScalar.slice(0, firstSpace), subValue); |
|
584 | } |
615 | } |
|
585 | } |
616 | } |
|
586 | if (exceptionOnInvalidType) { |
617 | if (exceptionOnInvalidType) { |
|
587 | throw new ParseException('Custom object support when parsing a YAML file has been disabled.'); |
618 | throw new ParseException('Custom object support when parsing a YAML file has been disabled.'); |
|
588 | } |
619 | } |
|
589 | return null; |
620 | return null; |
|
590 | } |
621 | } |
|
591 | break; |
622 | break; |
|
592 | case '0': |
623 | case '0': |
|
593 | if ('0x' === scalar.slice(0, 2)) { |
624 | if ('0x' === scalar.slice(0, 2)) { |
|
594 | return Utils.hexDec(scalar); |
625 | return Utils.hexDec(scalar); |
|
595 | } else if (Utils.isDigits(scalar)) { |
626 | } else if (Utils.isDigits(scalar)) { |
|
596 | return Utils.octDec(scalar); |
627 | return Utils.octDec(scalar); |
|
597 | } else if (Utils.isNumeric(scalar)) { |
628 | } else if (Utils.isNumeric(scalar)) { |
|
598 | return parseFloat(scalar); |
629 | return parseFloat(scalar); |
|
599 | } else { |
630 | } else { |
|
600 | return scalar; |
631 | return scalar; |
|
601 | } |
632 | } |
|
602 | break; |
633 | break; |
|
603 | case '+': |
634 | case '+': |
|
604 | if (Utils.isDigits(scalar)) { |
635 | if (Utils.isDigits(scalar)) { |
|
605 | raw = scalar; |
636 | raw = scalar; |
|
606 | cast = parseInt(raw); |
637 | cast = parseInt(raw); |
|
607 | if (raw === String(cast)) { |
638 | if (raw === String(cast)) { |
|
608 | return cast; |
639 | return cast; |
|
609 | } else { |
640 | } else { |
|
610 | return raw; |
641 | return raw; |
|
611 | } |
642 | } |
|
612 | } else if (Utils.isNumeric(scalar)) { |
643 | } else if (Utils.isNumeric(scalar)) { |
|
613 | return parseFloat(scalar); |
644 | return parseFloat(scalar); |
|
614 | } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) { |
645 | } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) { |
|
615 | return parseFloat(scalar.replace(',', '')); |
646 | return parseFloat(scalar.replace(',', '')); |
|
616 | } |
647 | } |
|
617 | return scalar; |
648 | return scalar; |
|
618 | case '-': |
649 | case '-': |
|
619 | if (Utils.isDigits(scalar.slice(1))) { |
650 | if (Utils.isDigits(scalar.slice(1))) { |
|
620 | if ('0' === scalar.charAt(1)) { |
651 | if ('0' === scalar.charAt(1)) { |
|
621 | return -Utils.octDec(scalar.slice(1)); |
652 | return -Utils.octDec(scalar.slice(1)); |
|
622 | } else { |
653 | } else { |
|
623 | raw = scalar.slice(1); |
654 | raw = scalar.slice(1); |
|
624 | cast = parseInt(raw); |
655 | cast = parseInt(raw); |
|
625 | if (raw === String(cast)) { |
656 | if (raw === String(cast)) { |
|
626 | return -cast; |
657 | return -cast; |
|
627 | } else { |
658 | } else { |
|
628 | return -raw; |
659 | return -raw; |
|
629 | } |
660 | } |
|
630 | } |
661 | } |
|
631 | } else if (Utils.isNumeric(scalar)) { |
662 | } else if (Utils.isNumeric(scalar)) { |
|
632 | return parseFloat(scalar); |
663 | return parseFloat(scalar); |
|
633 | } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) { |
664 | } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) { |
|
634 | return parseFloat(scalar.replace(',', '')); |
665 | return parseFloat(scalar.replace(',', '')); |
|
635 | } |
666 | } |
|
636 | return scalar; |
667 | return scalar; |
|
637 | default: |
668 | default: |
|
638 | if (date = Utils.stringToDate(scalar)) { |
669 | if (date = Utils.stringToDate(scalar)) { |
|
639 | return date; |
670 | return date; |
|
640 | } else if (Utils.isNumeric(scalar)) { |
671 | } else if (Utils.isNumeric(scalar)) { |
|
641 | return parseFloat(scalar); |
672 | return parseFloat(scalar); |
|
642 | } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) { |
673 | } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) { |
|
643 | return parseFloat(scalar.replace(',', '')); |
674 | return parseFloat(scalar.replace(',', '')); |
|
644 | } |
675 | } |
|
645 | return scalar; |
676 | return scalar; |
|
646 | } |
677 | } |
|
647 | } |
678 | } |
|
648 | }; |
679 | }; |
|
649 | |
680 | |
|
650 | return Inline; |
681 | return Inline; |
|
651 | |
682 | |
|
652 | })(); |
683 | })(); |
|
653 | |
684 | |
|
654 | module.exports = Inline; |
685 | module.exports = Inline; |
|
655 | |
686 | |
|
656 | |
687 | |
|
657 | },{"./Escaper":2,"./Exception/DumpException":3,"./Exception/ParseException":4,"./Pattern":7,"./Unescaper":8,"./Utils":9}],6:[function(require,module,exports){ |
688 | },{"./Escaper":2,"./Exception/DumpException":3,"./Exception/ParseException":4,"./Exception/ParseMore":5,"./Pattern":8,"./Unescaper":9,"./Utils":10}],7:[function(require,module,exports){ |
|
658 | var Inline, ParseException, Parser, Pattern, Utils; |
689 | var Inline, ParseException, ParseMore, Parser, Pattern, Utils; |
|
659 | |
690 | |
|
660 | Inline = require('./Inline'); |
691 | Inline = require('./Inline'); |
|
661 | |
692 | |
|
662 | Pattern = require('./Pattern'); |
693 | Pattern = require('./Pattern'); |
|
663 | |
694 | |
|
664 | Utils = require('./Utils'); |
695 | Utils = require('./Utils'); |
|
665 | |
696 | |
|
666 | ParseException = require('./Exception/ParseException'); |
697 | ParseException = require('./Exception/ParseException'); |
|
- | 698 | |
||
- | 699 | ParseMore = require('./Exception/ParseMore'); |
||
667 | |
700 | |
|
668 | Parser = (function() { |
701 | Parser = (function() { |
|
669 | Parser.prototype.PATTERN_FOLDED_SCALAR_ALL = new Pattern('^(?:(?<type>![^\\|>]*)\\s+)?(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
702 | Parser.prototype.PATTERN_FOLDED_SCALAR_ALL = new Pattern('^(?:(?<type>![^\\|>]*)\\s+)?(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
|
670 | |
703 | |
|
671 | Parser.prototype.PATTERN_FOLDED_SCALAR_END = new Pattern('(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
704 | Parser.prototype.PATTERN_FOLDED_SCALAR_END = new Pattern('(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
|
672 | |
705 | |
|
673 | Parser.prototype.PATTERN_SEQUENCE_ITEM = new Pattern('^\\-((?<leadspaces>\\s+)(?<value>.+?))?\\s*$'); |
706 | Parser.prototype.PATTERN_SEQUENCE_ITEM = new Pattern('^\\-((?<leadspaces>\\s+)(?<value>.+?))?\\s*$'); |
|
674 | |
707 | |
|
675 | Parser.prototype.PATTERN_ANCHOR_VALUE = new Pattern('^&(?<ref>[^ ]+) *(?<value>.*)'); |
708 | Parser.prototype.PATTERN_ANCHOR_VALUE = new Pattern('^&(?<ref>[^ ]+) *(?<value>.*)'); |
|
676 | |
709 | |
|
677 | Parser.prototype.PATTERN_COMPACT_NOTATION = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
710 | Parser.prototype.PATTERN_COMPACT_NOTATION = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
|
678 | |
711 | |
|
679 | Parser.prototype.PATTERN_MAPPING_ITEM = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
712 | Parser.prototype.PATTERN_MAPPING_ITEM = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
|
680 | |
713 | |
|
681 | Parser.prototype.PATTERN_DECIMAL = new Pattern('\\d+'); |
714 | Parser.prototype.PATTERN_DECIMAL = new Pattern('\\d+'); |
|
682 | |
715 | |
|
683 | Parser.prototype.PATTERN_INDENT_SPACES = new Pattern('^ +'); |
716 | Parser.prototype.PATTERN_INDENT_SPACES = new Pattern('^ +'); |
|
684 | |
717 | |
|
685 | Parser.prototype.PATTERN_TRAILING_LINES = new Pattern('(\n*)$'); |
718 | Parser.prototype.PATTERN_TRAILING_LINES = new Pattern('(\n*)$'); |
|
686 | |
719 | |
|
687 | Parser.prototype.PATTERN_YAML_HEADER = new Pattern('^\\%YAML[: ][\\d\\.]+.*\n'); |
720 | Parser.prototype.PATTERN_YAML_HEADER = new Pattern('^\\%YAML[: ][\\d\\.]+.*\n', 'm'); |
|
688 | |
721 | |
|
689 | Parser.prototype.PATTERN_LEADING_COMMENTS = new Pattern('^(\\#.*?\n)+'); |
722 | Parser.prototype.PATTERN_LEADING_COMMENTS = new Pattern('^(\\#.*?\n)+', 'm'); |
|
690 | |
723 | |
|
691 | Parser.prototype.PATTERN_DOCUMENT_MARKER_START = new Pattern('^\\-\\-\\-.*?\n'); |
724 | Parser.prototype.PATTERN_DOCUMENT_MARKER_START = new Pattern('^\\-\\-\\-.*?\n', 'm'); |
|
692 | |
725 | |
|
693 | Parser.prototype.PATTERN_DOCUMENT_MARKER_END = new Pattern('^\\.\\.\\.\\s*$'); |
726 | Parser.prototype.PATTERN_DOCUMENT_MARKER_END = new Pattern('^\\.\\.\\.\\s*$', 'm'); |
|
694 | |
727 | |
|
695 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION = {}; |
728 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION = {}; |
|
696 | |
729 | |
|
697 | Parser.prototype.CONTEXT_NONE = 0; |
730 | Parser.prototype.CONTEXT_NONE = 0; |
|
698 | |
731 | |
|
699 | Parser.prototype.CONTEXT_SEQUENCE = 1; |
732 | Parser.prototype.CONTEXT_SEQUENCE = 1; |
|
700 | |
733 | |
|
701 | Parser.prototype.CONTEXT_MAPPING = 2; |
734 | Parser.prototype.CONTEXT_MAPPING = 2; |
|
702 | |
735 | |
|
703 | function Parser(offset) { |
736 | function Parser(offset) { |
|
704 | this.offset = offset != null ? offset : 0; |
737 | this.offset = offset != null ? offset : 0; |
|
705 | this.lines = []; |
738 | this.lines = []; |
|
706 | this.currentLineNb = -1; |
739 | this.currentLineNb = -1; |
|
707 | this.currentLine = ''; |
740 | this.currentLine = ''; |
|
708 | this.refs = {}; |
741 | this.refs = {}; |
|
709 | } |
742 | } |
|
710 | |
743 | |
|
711 | Parser.prototype.parse = function(value, exceptionOnInvalidType, objectDecoder) { |
744 | Parser.prototype.parse = function(value, exceptionOnInvalidType, objectDecoder) { |
|
712 | var alias, allowOverwrite, block, c, context, data, e, error, error1, error2, first, i, indent, isRef, j, k, key, l, lastKey, len, len1, len2, len3, lineCount, m, matches, mergeNode, n, name, parsed, parsedItem, parser, ref, ref1, ref2, refName, refValue, val, values; |
745 | var alias, allowOverwrite, block, c, context, data, e, error, error1, error2, first, i, indent, isRef, j, k, key, l, lastKey, len, len1, len2, len3, lineCount, m, matches, mergeNode, n, name, parsed, parsedItem, parser, ref, ref1, ref2, refName, refValue, val, values; |
|
713 | if (exceptionOnInvalidType == null) { |
746 | if (exceptionOnInvalidType == null) { |
|
714 | exceptionOnInvalidType = false; |
747 | exceptionOnInvalidType = false; |
|
715 | } |
748 | } |
|
716 | if (objectDecoder == null) { |
749 | if (objectDecoder == null) { |
|
717 | objectDecoder = null; |
750 | objectDecoder = null; |
|
718 | } |
751 | } |
|
719 | this.currentLineNb = -1; |
752 | this.currentLineNb = -1; |
|
720 | this.currentLine = ''; |
753 | this.currentLine = ''; |
|
721 | this.lines = this.cleanup(value).split("\n"); |
754 | this.lines = this.cleanup(value).split("\n"); |
|
722 | data = null; |
755 | data = null; |
|
723 | context = this.CONTEXT_NONE; |
756 | context = this.CONTEXT_NONE; |
|
724 | allowOverwrite = false; |
757 | allowOverwrite = false; |
|
725 | while (this.moveToNextLine()) { |
758 | while (this.moveToNextLine()) { |
|
726 | if (this.isCurrentLineEmpty()) { |
759 | if (this.isCurrentLineEmpty()) { |
|
727 | continue; |
760 | continue; |
|
728 | } |
761 | } |
|
729 | if ("\t" === this.currentLine[0]) { |
762 | if ("\t" === this.currentLine[0]) { |
|
730 | throw new ParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine); |
763 | throw new ParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
731 | } |
764 | } |
|
732 | isRef = mergeNode = false; |
765 | isRef = mergeNode = false; |
|
733 | if (values = this.PATTERN_SEQUENCE_ITEM.exec(this.currentLine)) { |
766 | if (values = this.PATTERN_SEQUENCE_ITEM.exec(this.currentLine)) { |
|
734 | if (this.CONTEXT_MAPPING === context) { |
767 | if (this.CONTEXT_MAPPING === context) { |
|
735 | throw new ParseException('You cannot define a sequence item when in a mapping'); |
768 | throw new ParseException('You cannot define a sequence item when in a mapping'); |
|
736 | } |
769 | } |
|
737 | context = this.CONTEXT_SEQUENCE; |
770 | context = this.CONTEXT_SEQUENCE; |
|
738 | if (data == null) { |
771 | if (data == null) { |
|
739 | data = []; |
772 | data = []; |
|
740 | } |
773 | } |
|
741 | if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
774 | if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
|
742 | isRef = matches.ref; |
775 | isRef = matches.ref; |
|
743 | values.value = matches.value; |
776 | values.value = matches.value; |
|
744 | } |
777 | } |
|
745 | if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
778 | if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
|
746 | if (this.currentLineNb < this.lines.length - 1 && !this.isNextLineUnIndentedCollection()) { |
779 | if (this.currentLineNb < this.lines.length - 1 && !this.isNextLineUnIndentedCollection()) { |
|
747 | c = this.getRealCurrentLineNb() + 1; |
780 | c = this.getRealCurrentLineNb() + 1; |
|
748 | parser = new Parser(c); |
781 | parser = new Parser(c); |
|
749 | parser.refs = this.refs; |
782 | parser.refs = this.refs; |
|
750 | data.push(parser.parse(this.getNextEmbedBlock(null, true), exceptionOnInvalidType, objectDecoder)); |
783 | data.push(parser.parse(this.getNextEmbedBlock(null, true), exceptionOnInvalidType, objectDecoder)); |
|
751 | } else { |
784 | } else { |
|
752 | data.push(null); |
785 | data.push(null); |
|
753 | } |
786 | } |
|
754 | } else { |
787 | } else { |
|
755 | if (((ref = values.leadspaces) != null ? ref.length : void 0) && (matches = this.PATTERN_COMPACT_NOTATION.exec(values.value))) { |
788 | if (((ref = values.leadspaces) != null ? ref.length : void 0) && (matches = this.PATTERN_COMPACT_NOTATION.exec(values.value))) { |
|
756 | c = this.getRealCurrentLineNb(); |
789 | c = this.getRealCurrentLineNb(); |
|
757 | parser = new Parser(c); |
790 | parser = new Parser(c); |
|
758 | parser.refs = this.refs; |
791 | parser.refs = this.refs; |
|
759 | block = values.value; |
792 | block = values.value; |
|
760 | indent = this.getCurrentLineIndentation(); |
793 | indent = this.getCurrentLineIndentation(); |
|
761 | if (this.isNextLineIndented(false)) { |
794 | if (this.isNextLineIndented(false)) { |
|
762 | block += "\n" + this.getNextEmbedBlock(indent + values.leadspaces.length + 1, true); |
795 | block += "\n" + this.getNextEmbedBlock(indent + values.leadspaces.length + 1, true); |
|
763 | } |
796 | } |
|
764 | data.push(parser.parse(block, exceptionOnInvalidType, objectDecoder)); |
797 | data.push(parser.parse(block, exceptionOnInvalidType, objectDecoder)); |
|
765 | } else { |
798 | } else { |
|
766 | data.push(this.parseValue(values.value, exceptionOnInvalidType, objectDecoder)); |
799 | data.push(this.parseValue(values.value, exceptionOnInvalidType, objectDecoder)); |
|
767 | } |
800 | } |
|
768 | } |
801 | } |
|
769 | } else if ((values = this.PATTERN_MAPPING_ITEM.exec(this.currentLine)) && values.key.indexOf(' #') === -1) { |
802 | } else if ((values = this.PATTERN_MAPPING_ITEM.exec(this.currentLine)) && values.key.indexOf(' #') === -1) { |
|
770 | if (this.CONTEXT_SEQUENCE === context) { |
803 | if (this.CONTEXT_SEQUENCE === context) { |
|
771 | throw new ParseException('You cannot define a mapping item when in a sequence'); |
804 | throw new ParseException('You cannot define a mapping item when in a sequence'); |
|
772 | } |
805 | } |
|
773 | context = this.CONTEXT_MAPPING; |
806 | context = this.CONTEXT_MAPPING; |
|
774 | if (data == null) { |
807 | if (data == null) { |
|
775 | data = {}; |
808 | data = {}; |
|
776 | } |
809 | } |
|
777 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
810 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
|
778 | try { |
811 | try { |
|
779 | key = Inline.parseScalar(values.key); |
812 | key = Inline.parseScalar(values.key); |
|
780 | } catch (error) { |
813 | } catch (error) { |
|
781 | e = error; |
814 | e = error; |
|
782 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
815 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
783 | e.snippet = this.currentLine; |
816 | e.snippet = this.currentLine; |
|
784 | throw e; |
817 | throw e; |
|
785 | } |
818 | } |
|
786 | if ('<<' === key) { |
819 | if ('<<' === key) { |
|
787 | mergeNode = true; |
820 | mergeNode = true; |
|
788 | allowOverwrite = true; |
821 | allowOverwrite = true; |
|
789 | if (((ref1 = values.value) != null ? ref1.indexOf('*') : void 0) === 0) { |
822 | if (((ref1 = values.value) != null ? ref1.indexOf('*') : void 0) === 0) { |
|
790 | refName = values.value.slice(1); |
823 | refName = values.value.slice(1); |
|
791 | if (this.refs[refName] == null) { |
824 | if (this.refs[refName] == null) { |
|
792 | throw new ParseException('Reference "' + refName + '" does not exist.', this.getRealCurrentLineNb() + 1, this.currentLine); |
825 | throw new ParseException('Reference "' + refName + '" does not exist.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
793 | } |
826 | } |
|
794 | refValue = this.refs[refName]; |
827 | refValue = this.refs[refName]; |
|
795 | if (typeof refValue !== 'object') { |
828 | if (typeof refValue !== 'object') { |
|
796 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
829 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
797 | } |
830 | } |
|
798 | if (refValue instanceof Array) { |
831 | if (refValue instanceof Array) { |
|
799 | for (i = j = 0, len = refValue.length; j < len; i = ++j) { |
832 | for (i = j = 0, len = refValue.length; j < len; i = ++j) { |
|
800 | value = refValue[i]; |
833 | value = refValue[i]; |
|
801 | if (data[name = String(i)] == null) { |
834 | if (data[name = String(i)] == null) { |
|
802 | data[name] = value; |
835 | data[name] = value; |
|
803 | } |
836 | } |
|
804 | } |
837 | } |
|
805 | } else { |
838 | } else { |
|
806 | for (key in refValue) { |
839 | for (key in refValue) { |
|
807 | value = refValue[key]; |
840 | value = refValue[key]; |
|
808 | if (data[key] == null) { |
841 | if (data[key] == null) { |
|
809 | data[key] = value; |
842 | data[key] = value; |
|
810 | } |
843 | } |
|
811 | } |
844 | } |
|
812 | } |
845 | } |
|
813 | } else { |
846 | } else { |
|
814 | if ((values.value != null) && values.value !== '') { |
847 | if ((values.value != null) && values.value !== '') { |
|
815 | value = values.value; |
848 | value = values.value; |
|
816 | } else { |
849 | } else { |
|
817 | value = this.getNextEmbedBlock(); |
850 | value = this.getNextEmbedBlock(); |
|
818 | } |
851 | } |
|
819 | c = this.getRealCurrentLineNb() + 1; |
852 | c = this.getRealCurrentLineNb() + 1; |
|
820 | parser = new Parser(c); |
853 | parser = new Parser(c); |
|
821 | parser.refs = this.refs; |
854 | parser.refs = this.refs; |
|
822 | parsed = parser.parse(value, exceptionOnInvalidType); |
855 | parsed = parser.parse(value, exceptionOnInvalidType); |
|
823 | if (typeof parsed !== 'object') { |
856 | if (typeof parsed !== 'object') { |
|
824 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
857 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
825 | } |
858 | } |
|
826 | if (parsed instanceof Array) { |
859 | if (parsed instanceof Array) { |
|
827 | for (l = 0, len1 = parsed.length; l < len1; l++) { |
860 | for (l = 0, len1 = parsed.length; l < len1; l++) { |
|
828 | parsedItem = parsed[l]; |
861 | parsedItem = parsed[l]; |
|
829 | if (typeof parsedItem !== 'object') { |
862 | if (typeof parsedItem !== 'object') { |
|
830 | throw new ParseException('Merge items must be objects.', this.getRealCurrentLineNb() + 1, parsedItem); |
863 | throw new ParseException('Merge items must be objects.', this.getRealCurrentLineNb() + 1, parsedItem); |
|
831 | } |
864 | } |
|
832 | if (parsedItem instanceof Array) { |
865 | if (parsedItem instanceof Array) { |
|
833 | for (i = m = 0, len2 = parsedItem.length; m < len2; i = ++m) { |
866 | for (i = m = 0, len2 = parsedItem.length; m < len2; i = ++m) { |
|
834 | value = parsedItem[i]; |
867 | value = parsedItem[i]; |
|
835 | k = String(i); |
868 | k = String(i); |
|
836 | if (!data.hasOwnProperty(k)) { |
869 | if (!data.hasOwnProperty(k)) { |
|
837 | data[k] = value; |
870 | data[k] = value; |
|
838 | } |
871 | } |
|
839 | } |
872 | } |
|
840 | } else { |
873 | } else { |
|
841 | for (key in parsedItem) { |
874 | for (key in parsedItem) { |
|
842 | value = parsedItem[key]; |
875 | value = parsedItem[key]; |
|
843 | if (!data.hasOwnProperty(key)) { |
876 | if (!data.hasOwnProperty(key)) { |
|
844 | data[key] = value; |
877 | data[key] = value; |
|
845 | } |
878 | } |
|
846 | } |
879 | } |
|
847 | } |
880 | } |
|
848 | } |
881 | } |
|
849 | } else { |
882 | } else { |
|
850 | for (key in parsed) { |
883 | for (key in parsed) { |
|
851 | value = parsed[key]; |
884 | value = parsed[key]; |
|
852 | if (!data.hasOwnProperty(key)) { |
885 | if (!data.hasOwnProperty(key)) { |
|
853 | data[key] = value; |
886 | data[key] = value; |
|
854 | } |
887 | } |
|
855 | } |
888 | } |
|
856 | } |
889 | } |
|
857 | } |
890 | } |
|
858 | } else if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
891 | } else if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
|
859 | isRef = matches.ref; |
892 | isRef = matches.ref; |
|
860 | values.value = matches.value; |
893 | values.value = matches.value; |
|
861 | } |
894 | } |
|
862 | if (mergeNode) { |
895 | if (mergeNode) { |
|
863 | |
896 | |
|
864 | } else if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
897 | } else if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
|
865 | if (!(this.isNextLineIndented()) && !(this.isNextLineUnIndentedCollection())) { |
898 | if (!(this.isNextLineIndented()) && !(this.isNextLineUnIndentedCollection())) { |
|
866 | if (allowOverwrite || data[key] === void 0) { |
899 | if (allowOverwrite || data[key] === void 0) { |
|
867 | data[key] = null; |
900 | data[key] = null; |
|
868 | } |
901 | } |
|
869 | } else { |
902 | } else { |
|
870 | c = this.getRealCurrentLineNb() + 1; |
903 | c = this.getRealCurrentLineNb() + 1; |
|
871 | parser = new Parser(c); |
904 | parser = new Parser(c); |
|
872 | parser.refs = this.refs; |
905 | parser.refs = this.refs; |
|
873 | val = parser.parse(this.getNextEmbedBlock(), exceptionOnInvalidType, objectDecoder); |
906 | val = parser.parse(this.getNextEmbedBlock(), exceptionOnInvalidType, objectDecoder); |
|
874 | if (allowOverwrite || data[key] === void 0) { |
907 | if (allowOverwrite || data[key] === void 0) { |
|
875 | data[key] = val; |
908 | data[key] = val; |
|
876 | } |
909 | } |
|
877 | } |
910 | } |
|
878 | } else { |
911 | } else { |
|
879 | val = this.parseValue(values.value, exceptionOnInvalidType, objectDecoder); |
912 | val = this.parseValue(values.value, exceptionOnInvalidType, objectDecoder); |
|
880 | if (allowOverwrite || data[key] === void 0) { |
913 | if (allowOverwrite || data[key] === void 0) { |
|
881 | data[key] = val; |
914 | data[key] = val; |
|
882 | } |
915 | } |
|
883 | } |
916 | } |
|
884 | } else { |
917 | } else { |
|
885 | lineCount = this.lines.length; |
918 | lineCount = this.lines.length; |
|
886 | if (1 === lineCount || (2 === lineCount && Utils.isEmpty(this.lines[1]))) { |
919 | if (1 === lineCount || (2 === lineCount && Utils.isEmpty(this.lines[1]))) { |
|
887 | try { |
920 | try { |
|
888 | value = Inline.parse(this.lines[0], exceptionOnInvalidType, objectDecoder); |
921 | value = Inline.parse(this.lines[0], exceptionOnInvalidType, objectDecoder); |
|
889 | } catch (error1) { |
922 | } catch (error1) { |
|
890 | e = error1; |
923 | e = error1; |
|
891 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
924 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
892 | e.snippet = this.currentLine; |
925 | e.snippet = this.currentLine; |
|
893 | throw e; |
926 | throw e; |
|
894 | } |
927 | } |
|
895 | if (typeof value === 'object') { |
928 | if (typeof value === 'object') { |
|
896 | if (value instanceof Array) { |
929 | if (value instanceof Array) { |
|
897 | first = value[0]; |
930 | first = value[0]; |
|
898 | } else { |
931 | } else { |
|
899 | for (key in value) { |
932 | for (key in value) { |
|
900 | first = value[key]; |
933 | first = value[key]; |
|
901 | break; |
934 | break; |
|
902 | } |
935 | } |
|
903 | } |
936 | } |
|
904 | if (typeof first === 'string' && first.indexOf('*') === 0) { |
937 | if (typeof first === 'string' && first.indexOf('*') === 0) { |
|
905 | data = []; |
938 | data = []; |
|
906 | for (n = 0, len3 = value.length; n < len3; n++) { |
939 | for (n = 0, len3 = value.length; n < len3; n++) { |
|
907 | alias = value[n]; |
940 | alias = value[n]; |
|
908 | data.push(this.refs[alias.slice(1)]); |
941 | data.push(this.refs[alias.slice(1)]); |
|
909 | } |
942 | } |
|
910 | value = data; |
943 | value = data; |
|
911 | } |
944 | } |
|
912 | } |
945 | } |
|
913 | return value; |
946 | return value; |
|
914 | } else if ((ref2 = Utils.ltrim(value).charAt(0)) === '[' || ref2 === '{') { |
947 | } else if ((ref2 = Utils.ltrim(value).charAt(0)) === '[' || ref2 === '{') { |
|
915 | try { |
948 | try { |
|
916 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
949 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
|
917 | } catch (error2) { |
950 | } catch (error2) { |
|
918 | e = error2; |
951 | e = error2; |
|
919 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
952 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
920 | e.snippet = this.currentLine; |
953 | e.snippet = this.currentLine; |
|
921 | throw e; |
954 | throw e; |
|
922 | } |
955 | } |
|
923 | } |
956 | } |
|
924 | throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine); |
957 | throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
925 | } |
958 | } |
|
926 | if (isRef) { |
959 | if (isRef) { |
|
927 | if (data instanceof Array) { |
960 | if (data instanceof Array) { |
|
928 | this.refs[isRef] = data[data.length - 1]; |
961 | this.refs[isRef] = data[data.length - 1]; |
|
929 | } else { |
962 | } else { |
|
930 | lastKey = null; |
963 | lastKey = null; |
|
931 | for (key in data) { |
964 | for (key in data) { |
|
932 | lastKey = key; |
965 | lastKey = key; |
|
933 | } |
966 | } |
|
934 | this.refs[isRef] = data[lastKey]; |
967 | this.refs[isRef] = data[lastKey]; |
|
935 | } |
968 | } |
|
936 | } |
969 | } |
|
937 | } |
970 | } |
|
938 | if (Utils.isEmpty(data)) { |
971 | if (Utils.isEmpty(data)) { |
|
939 | return null; |
972 | return null; |
|
940 | } else { |
973 | } else { |
|
941 | return data; |
974 | return data; |
|
942 | } |
975 | } |
|
943 | }; |
976 | }; |
|
944 | |
977 | |
|
945 | Parser.prototype.getRealCurrentLineNb = function() { |
978 | Parser.prototype.getRealCurrentLineNb = function() { |
|
946 | return this.currentLineNb + this.offset; |
979 | return this.currentLineNb + this.offset; |
|
947 | }; |
980 | }; |
|
948 | |
981 | |
|
949 | Parser.prototype.getCurrentLineIndentation = function() { |
982 | Parser.prototype.getCurrentLineIndentation = function() { |
|
950 | return this.currentLine.length - Utils.ltrim(this.currentLine, ' ').length; |
983 | return this.currentLine.length - Utils.ltrim(this.currentLine, ' ').length; |
|
951 | }; |
984 | }; |
|
952 | |
985 | |
|
953 | Parser.prototype.getNextEmbedBlock = function(indentation, includeUnindentedCollection) { |
986 | Parser.prototype.getNextEmbedBlock = function(indentation, includeUnindentedCollection) { |
|
954 | var data, indent, isItUnindentedCollection, newIndent, removeComments, removeCommentsPattern, unindentedEmbedBlock; |
987 | var data, indent, isItUnindentedCollection, newIndent, removeComments, removeCommentsPattern, unindentedEmbedBlock; |
|
955 | if (indentation == null) { |
988 | if (indentation == null) { |
|
956 | indentation = null; |
989 | indentation = null; |
|
957 | } |
990 | } |
|
958 | if (includeUnindentedCollection == null) { |
991 | if (includeUnindentedCollection == null) { |
|
959 | includeUnindentedCollection = false; |
992 | includeUnindentedCollection = false; |
|
960 | } |
993 | } |
|
961 | this.moveToNextLine(); |
994 | this.moveToNextLine(); |
|
962 | if (indentation == null) { |
995 | if (indentation == null) { |
|
963 | newIndent = this.getCurrentLineIndentation(); |
996 | newIndent = this.getCurrentLineIndentation(); |
|
964 | unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine); |
997 | unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine); |
|
965 | if (!(this.isCurrentLineEmpty()) && 0 === newIndent && !unindentedEmbedBlock) { |
998 | if (!(this.isCurrentLineEmpty()) && 0 === newIndent && !unindentedEmbedBlock) { |
|
966 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
999 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
967 | } |
1000 | } |
|
968 | } else { |
1001 | } else { |
|
969 | newIndent = indentation; |
1002 | newIndent = indentation; |
|
970 | } |
1003 | } |
|
971 | data = [this.currentLine.slice(newIndent)]; |
1004 | data = [this.currentLine.slice(newIndent)]; |
|
972 | if (!includeUnindentedCollection) { |
1005 | if (!includeUnindentedCollection) { |
|
973 | isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine); |
1006 | isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine); |
|
974 | } |
1007 | } |
|
975 | removeCommentsPattern = this.PATTERN_FOLDED_SCALAR_END; |
1008 | removeCommentsPattern = this.PATTERN_FOLDED_SCALAR_END; |
|
976 | removeComments = !removeCommentsPattern.test(this.currentLine); |
1009 | removeComments = !removeCommentsPattern.test(this.currentLine); |
|
977 | while (this.moveToNextLine()) { |
1010 | while (this.moveToNextLine()) { |
|
978 | indent = this.getCurrentLineIndentation(); |
1011 | indent = this.getCurrentLineIndentation(); |
|
979 | if (indent === newIndent) { |
1012 | if (indent === newIndent) { |
|
980 | removeComments = !removeCommentsPattern.test(this.currentLine); |
1013 | removeComments = !removeCommentsPattern.test(this.currentLine); |
|
981 | } |
1014 | } |
|
982 | if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine) && indent === newIndent) { |
- | ||
983 | this.moveToPreviousLine(); |
1015 | if (removeComments && this.isCurrentLineComment()) { |
|
984 | break; |
1016 | continue; |
|
985 | } |
1017 | } |
|
986 | if (this.isCurrentLineBlank()) { |
1018 | if (this.isCurrentLineBlank()) { |
|
987 | data.push(this.currentLine.slice(newIndent)); |
1019 | data.push(this.currentLine.slice(newIndent)); |
|
988 | continue; |
1020 | continue; |
|
989 | } |
1021 | } |
|
990 | if (removeComments && this.isCurrentLineComment()) { |
1022 | if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine) && indent === newIndent) { |
|
991 | if (indent === newIndent) { |
1023 | this.moveToPreviousLine(); |
|
992 | continue; |
- | ||
993 | } |
1024 | break; |
|
994 | } |
1025 | } |
|
995 | if (indent >= newIndent) { |
1026 | if (indent >= newIndent) { |
|
996 | data.push(this.currentLine.slice(newIndent)); |
1027 | data.push(this.currentLine.slice(newIndent)); |
|
997 | } else if (Utils.ltrim(this.currentLine).charAt(0) === '#') { |
1028 | } else if (Utils.ltrim(this.currentLine).charAt(0) === '#') { |
|
998 | |
1029 | |
|
999 | } else if (0 === indent) { |
1030 | } else if (0 === indent) { |
|
1000 | this.moveToPreviousLine(); |
1031 | this.moveToPreviousLine(); |
|
1001 | break; |
1032 | break; |
|
1002 | } else { |
1033 | } else { |
|
1003 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
1034 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
1004 | } |
1035 | } |
|
1005 | } |
1036 | } |
|
1006 | return data.join("\n"); |
1037 | return data.join("\n"); |
|
1007 | }; |
1038 | }; |
|
1008 | |
1039 | |
|
1009 | Parser.prototype.moveToNextLine = function() { |
1040 | Parser.prototype.moveToNextLine = function() { |
|
1010 | if (this.currentLineNb >= this.lines.length - 1) { |
1041 | if (this.currentLineNb >= this.lines.length - 1) { |
|
1011 | return false; |
1042 | return false; |
|
1012 | } |
1043 | } |
|
1013 | this.currentLine = this.lines[++this.currentLineNb]; |
1044 | this.currentLine = this.lines[++this.currentLineNb]; |
|
1014 | return true; |
1045 | return true; |
|
1015 | }; |
1046 | }; |
|
1016 | |
1047 | |
|
1017 | Parser.prototype.moveToPreviousLine = function() { |
1048 | Parser.prototype.moveToPreviousLine = function() { |
|
1018 | this.currentLine = this.lines[--this.currentLineNb]; |
1049 | this.currentLine = this.lines[--this.currentLineNb]; |
|
1019 | }; |
1050 | }; |
|
1020 | |
1051 | |
|
1021 | Parser.prototype.parseValue = function(value, exceptionOnInvalidType, objectDecoder) { |
1052 | Parser.prototype.parseValue = function(value, exceptionOnInvalidType, objectDecoder) { |
|
1022 | var e, error, error1, foldedIndent, matches, modifiers, pos, ref, ref1, val; |
1053 | var e, error, foldedIndent, matches, modifiers, pos, ref, ref1, val; |
|
1023 | if (0 === value.indexOf('*')) { |
1054 | if (0 === value.indexOf('*')) { |
|
1024 | pos = value.indexOf('#'); |
1055 | pos = value.indexOf('#'); |
|
1025 | if (pos !== -1) { |
1056 | if (pos !== -1) { |
|
1026 | value = value.substr(1, pos - 2); |
1057 | value = value.substr(1, pos - 2); |
|
1027 | } else { |
1058 | } else { |
|
1028 | value = value.slice(1); |
1059 | value = value.slice(1); |
|
1029 | } |
1060 | } |
|
1030 | if (this.refs[value] === void 0) { |
1061 | if (this.refs[value] === void 0) { |
|
1031 | throw new ParseException('Reference "' + value + '" does not exist.', this.currentLine); |
1062 | throw new ParseException('Reference "' + value + '" does not exist.', this.currentLine); |
|
1032 | } |
1063 | } |
|
1033 | return this.refs[value]; |
1064 | return this.refs[value]; |
|
1034 | } |
1065 | } |
|
1035 | if (matches = this.PATTERN_FOLDED_SCALAR_ALL.exec(value)) { |
1066 | if (matches = this.PATTERN_FOLDED_SCALAR_ALL.exec(value)) { |
|
1036 | modifiers = (ref = matches.modifiers) != null ? ref : ''; |
1067 | modifiers = (ref = matches.modifiers) != null ? ref : ''; |
|
1037 | foldedIndent = Math.abs(parseInt(modifiers)); |
1068 | foldedIndent = Math.abs(parseInt(modifiers)); |
|
1038 | if (isNaN(foldedIndent)) { |
1069 | if (isNaN(foldedIndent)) { |
|
1039 | foldedIndent = 0; |
1070 | foldedIndent = 0; |
|
1040 | } |
1071 | } |
|
1041 | val = this.parseFoldedScalar(matches.separator, this.PATTERN_DECIMAL.replace(modifiers, ''), foldedIndent); |
1072 | val = this.parseFoldedScalar(matches.separator, this.PATTERN_DECIMAL.replace(modifiers, ''), foldedIndent); |
|
1042 | if (matches.type != null) { |
1073 | if (matches.type != null) { |
|
1043 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
1074 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
|
1044 | return Inline.parseScalar(matches.type + ' ' + val); |
1075 | return Inline.parseScalar(matches.type + ' ' + val); |
|
1045 | } else { |
1076 | } else { |
|
1046 | return val; |
1077 | return val; |
|
1047 | } |
1078 | } |
|
1048 | } |
1079 | } |
|
1049 | try { |
- | ||
1050 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
1080 | if ((ref1 = value.charAt(0)) === '[' || ref1 === '{' || ref1 === '"' || ref1 === "'") { |
|
1051 | } catch (error) { |
1081 | while (true) { |
|
1052 | e = error; |
- | ||
1053 | if (((ref1 = value.charAt(0)) === '[' || ref1 === '{') && e instanceof ParseException && this.isNextLineIndented()) { |
- | ||
1054 | value += "\n" + this.getNextEmbedBlock(); |
- | ||
1055 | try { |
1082 | try { |
|
1056 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
1083 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
|
1057 | } catch (error1) { |
1084 | } catch (error) { |
|
1058 | e = error1; |
1085 | e = error; |
|
- | 1086 | if (e instanceof ParseMore && this.moveToNextLine()) { |
||
- | 1087 | value += "\n" + Utils.trim(this.currentLine, ' '); |
||
- | 1088 | } else { |
||
1059 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
1089 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
1060 | e.snippet = this.currentLine; |
1090 | e.snippet = this.currentLine; |
|
1061 | throw e; |
1091 | throw e; |
|
- | 1092 | } |
||
1062 | } |
1093 | } |
|
1063 | } else { |
- | ||
1064 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
- | ||
1065 | e.snippet = this.currentLine; |
- | ||
1066 | throw e; |
- | ||
1067 | } |
1094 | } |
|
- | 1095 | } else { |
||
- | 1096 | if (this.isNextLineIndented()) { |
||
- | 1097 | value += "\n" + this.getNextEmbedBlock(); |
||
- | 1098 | } |
||
- | 1099 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
||
1068 | } |
1100 | } |
|
1069 | }; |
1101 | }; |
|
1070 | |
1102 | |
|
1071 | Parser.prototype.parseFoldedScalar = function(separator, indicator, indentation) { |
1103 | Parser.prototype.parseFoldedScalar = function(separator, indicator, indentation) { |
|
1072 | var isCurrentLineBlank, j, len, line, matches, newText, notEOF, pattern, ref, text; |
1104 | var isCurrentLineBlank, j, len, line, matches, newText, notEOF, pattern, ref, text; |
|
1073 | if (indicator == null) { |
1105 | if (indicator == null) { |
|
1074 | indicator = ''; |
1106 | indicator = ''; |
|
1075 | } |
1107 | } |
|
1076 | if (indentation == null) { |
1108 | if (indentation == null) { |
|
1077 | indentation = 0; |
1109 | indentation = 0; |
|
1078 | } |
1110 | } |
|
1079 | notEOF = this.moveToNextLine(); |
1111 | notEOF = this.moveToNextLine(); |
|
1080 | if (!notEOF) { |
1112 | if (!notEOF) { |
|
1081 | return ''; |
1113 | return ''; |
|
1082 | } |
1114 | } |
|
1083 | isCurrentLineBlank = this.isCurrentLineBlank(); |
1115 | isCurrentLineBlank = this.isCurrentLineBlank(); |
|
1084 | text = ''; |
1116 | text = ''; |
|
1085 | while (notEOF && isCurrentLineBlank) { |
1117 | while (notEOF && isCurrentLineBlank) { |
|
1086 | if (notEOF = this.moveToNextLine()) { |
1118 | if (notEOF = this.moveToNextLine()) { |
|
1087 | text += "\n"; |
1119 | text += "\n"; |
|
1088 | isCurrentLineBlank = this.isCurrentLineBlank(); |
1120 | isCurrentLineBlank = this.isCurrentLineBlank(); |
|
1089 | } |
1121 | } |
|
1090 | } |
1122 | } |
|
1091 | if (0 === indentation) { |
1123 | if (0 === indentation) { |
|
1092 | if (matches = this.PATTERN_INDENT_SPACES.exec(this.currentLine)) { |
1124 | if (matches = this.PATTERN_INDENT_SPACES.exec(this.currentLine)) { |
|
1093 | indentation = matches[0].length; |
1125 | indentation = matches[0].length; |
|
1094 | } |
1126 | } |
|
1095 | } |
1127 | } |
|
1096 | if (indentation > 0) { |
1128 | if (indentation > 0) { |
|
1097 | pattern = this.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation]; |
1129 | pattern = this.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation]; |
|
1098 | if (pattern == null) { |
1130 | if (pattern == null) { |
|
1099 | pattern = new Pattern('^ {' + indentation + '}(.*)$'); |
1131 | pattern = new Pattern('^ {' + indentation + '}(.*)$'); |
|
1100 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation] = pattern; |
1132 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation] = pattern; |
|
1101 | } |
1133 | } |
|
1102 | while (notEOF && (isCurrentLineBlank || (matches = pattern.exec(this.currentLine)))) { |
1134 | while (notEOF && (isCurrentLineBlank || (matches = pattern.exec(this.currentLine)))) { |
|
1103 | if (isCurrentLineBlank) { |
1135 | if (isCurrentLineBlank) { |
|
1104 | text += this.currentLine.slice(indentation); |
1136 | text += this.currentLine.slice(indentation); |
|
1105 | } else { |
1137 | } else { |
|
1106 | text += matches[1]; |
1138 | text += matches[1]; |
|
1107 | } |
1139 | } |
|
1108 | if (notEOF = this.moveToNextLine()) { |
1140 | if (notEOF = this.moveToNextLine()) { |
|
1109 | text += "\n"; |
1141 | text += "\n"; |
|
1110 | isCurrentLineBlank = this.isCurrentLineBlank(); |
1142 | isCurrentLineBlank = this.isCurrentLineBlank(); |
|
1111 | } |
1143 | } |
|
1112 | } |
1144 | } |
|
1113 | } else if (notEOF) { |
1145 | } else if (notEOF) { |
|
1114 | text += "\n"; |
1146 | text += "\n"; |
|
1115 | } |
1147 | } |
|
1116 | if (notEOF) { |
1148 | if (notEOF) { |
|
1117 | this.moveToPreviousLine(); |
1149 | this.moveToPreviousLine(); |
|
1118 | } |
1150 | } |
|
1119 | if ('>' === separator) { |
1151 | if ('>' === separator) { |
|
1120 | newText = ''; |
1152 | newText = ''; |
|
1121 | ref = text.split("\n"); |
1153 | ref = text.split("\n"); |
|
1122 | for (j = 0, len = ref.length; j < len; j++) { |
1154 | for (j = 0, len = ref.length; j < len; j++) { |
|
1123 | line = ref[j]; |
1155 | line = ref[j]; |
|
1124 | if (line.length === 0 || line.charAt(0) === ' ') { |
1156 | if (line.length === 0 || line.charAt(0) === ' ') { |
|
1125 | newText = Utils.rtrim(newText, ' ') + line + "\n"; |
1157 | newText = Utils.rtrim(newText, ' ') + line + "\n"; |
|
1126 | } else { |
1158 | } else { |
|
1127 | newText += line + ' '; |
1159 | newText += line + ' '; |
|
1128 | } |
1160 | } |
|
1129 | } |
1161 | } |
|
1130 | text = newText; |
1162 | text = newText; |
|
1131 | } |
1163 | } |
|
1132 | if ('+' !== indicator) { |
1164 | if ('+' !== indicator) { |
|
1133 | text = Utils.rtrim(text); |
1165 | text = Utils.rtrim(text); |
|
1134 | } |
1166 | } |
|
1135 | if ('' === indicator) { |
1167 | if ('' === indicator) { |
|
1136 | text = this.PATTERN_TRAILING_LINES.replace(text, "\n"); |
1168 | text = this.PATTERN_TRAILING_LINES.replace(text, "\n"); |
|
1137 | } else if ('-' === indicator) { |
1169 | } else if ('-' === indicator) { |
|
1138 | text = this.PATTERN_TRAILING_LINES.replace(text, ''); |
1170 | text = this.PATTERN_TRAILING_LINES.replace(text, ''); |
|
1139 | } |
1171 | } |
|
1140 | return text; |
1172 | return text; |
|
1141 | }; |
1173 | }; |
|
1142 | |
1174 | |
|
1143 | Parser.prototype.isNextLineIndented = function(ignoreComments) { |
1175 | Parser.prototype.isNextLineIndented = function(ignoreComments) { |
|
1144 | var EOF, currentIndentation, ret; |
1176 | var EOF, currentIndentation, ret; |
|
1145 | if (ignoreComments == null) { |
1177 | if (ignoreComments == null) { |
|
1146 | ignoreComments = true; |
1178 | ignoreComments = true; |
|
1147 | } |
1179 | } |
|
1148 | currentIndentation = this.getCurrentLineIndentation(); |
1180 | currentIndentation = this.getCurrentLineIndentation(); |
|
1149 | EOF = !this.moveToNextLine(); |
1181 | EOF = !this.moveToNextLine(); |
|
1150 | if (ignoreComments) { |
1182 | if (ignoreComments) { |
|
1151 | while (!EOF && this.isCurrentLineEmpty()) { |
1183 | while (!EOF && this.isCurrentLineEmpty()) { |
|
1152 | EOF = !this.moveToNextLine(); |
1184 | EOF = !this.moveToNextLine(); |
|
1153 | } |
1185 | } |
|
1154 | } else { |
1186 | } else { |
|
1155 | while (!EOF && this.isCurrentLineBlank()) { |
1187 | while (!EOF && this.isCurrentLineBlank()) { |
|
1156 | EOF = !this.moveToNextLine(); |
1188 | EOF = !this.moveToNextLine(); |
|
1157 | } |
1189 | } |
|
1158 | } |
1190 | } |
|
1159 | if (EOF) { |
1191 | if (EOF) { |
|
1160 | return false; |
1192 | return false; |
|
1161 | } |
1193 | } |
|
1162 | ret = false; |
1194 | ret = false; |
|
1163 | if (this.getCurrentLineIndentation() > currentIndentation) { |
1195 | if (this.getCurrentLineIndentation() > currentIndentation) { |
|
1164 | ret = true; |
1196 | ret = true; |
|
1165 | } |
1197 | } |
|
1166 | this.moveToPreviousLine(); |
1198 | this.moveToPreviousLine(); |
|
1167 | return ret; |
1199 | return ret; |
|
1168 | }; |
1200 | }; |
|
1169 | |
1201 | |
|
1170 | Parser.prototype.isCurrentLineEmpty = function() { |
1202 | Parser.prototype.isCurrentLineEmpty = function() { |
|
1171 | var trimmedLine; |
1203 | var trimmedLine; |
|
1172 | trimmedLine = Utils.trim(this.currentLine, ' '); |
1204 | trimmedLine = Utils.trim(this.currentLine, ' '); |
|
1173 | return trimmedLine.length === 0 || trimmedLine.charAt(0) === '#'; |
1205 | return trimmedLine.length === 0 || trimmedLine.charAt(0) === '#'; |
|
1174 | }; |
1206 | }; |
|
1175 | |
1207 | |
|
1176 | Parser.prototype.isCurrentLineBlank = function() { |
1208 | Parser.prototype.isCurrentLineBlank = function() { |
|
1177 | return '' === Utils.trim(this.currentLine, ' '); |
1209 | return '' === Utils.trim(this.currentLine, ' '); |
|
1178 | }; |
1210 | }; |
|
1179 | |
1211 | |
|
1180 | Parser.prototype.isCurrentLineComment = function() { |
1212 | Parser.prototype.isCurrentLineComment = function() { |
|
1181 | var ltrimmedLine; |
1213 | var ltrimmedLine; |
|
1182 | ltrimmedLine = Utils.ltrim(this.currentLine, ' '); |
1214 | ltrimmedLine = Utils.ltrim(this.currentLine, ' '); |
|
1183 | return ltrimmedLine.charAt(0) === '#'; |
1215 | return ltrimmedLine.charAt(0) === '#'; |
|
1184 | }; |
1216 | }; |
|
1185 | |
1217 | |
|
1186 | Parser.prototype.cleanup = function(value) { |
1218 | Parser.prototype.cleanup = function(value) { |
|
1187 | var count, i, indent, j, l, len, len1, line, lines, ref, ref1, ref2, smallestIndent, trimmedValue; |
1219 | var count, i, indent, j, l, len, len1, line, lines, ref, ref1, ref2, smallestIndent, trimmedValue; |
|
1188 | if (value.indexOf("\r") !== -1) { |
1220 | if (value.indexOf("\r") !== -1) { |
|
1189 | value = value.split("\r\n").join("\n").split("\r").join("\n"); |
1221 | value = value.split("\r\n").join("\n").split("\r").join("\n"); |
|
1190 | } |
1222 | } |
|
1191 | count = 0; |
1223 | count = 0; |
|
1192 | ref = this.PATTERN_YAML_HEADER.replaceAll(value, ''), value = ref[0], count = ref[1]; |
1224 | ref = this.PATTERN_YAML_HEADER.replaceAll(value, ''), value = ref[0], count = ref[1]; |
|
1193 | this.offset += count; |
1225 | this.offset += count; |
|
1194 | ref1 = this.PATTERN_LEADING_COMMENTS.replaceAll(value, '', 1), trimmedValue = ref1[0], count = ref1[1]; |
1226 | ref1 = this.PATTERN_LEADING_COMMENTS.replaceAll(value, '', 1), trimmedValue = ref1[0], count = ref1[1]; |
|
1195 | if (count === 1) { |
1227 | if (count === 1) { |
|
1196 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
1228 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
|
1197 | value = trimmedValue; |
1229 | value = trimmedValue; |
|
1198 | } |
1230 | } |
|
1199 | ref2 = this.PATTERN_DOCUMENT_MARKER_START.replaceAll(value, '', 1), trimmedValue = ref2[0], count = ref2[1]; |
1231 | ref2 = this.PATTERN_DOCUMENT_MARKER_START.replaceAll(value, '', 1), trimmedValue = ref2[0], count = ref2[1]; |
|
1200 | if (count === 1) { |
1232 | if (count === 1) { |
|
1201 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
1233 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
|
1202 | value = trimmedValue; |
1234 | value = trimmedValue; |
|
1203 | value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, ''); |
1235 | value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, ''); |
|
1204 | } |
1236 | } |
|
1205 | lines = value.split("\n"); |
1237 | lines = value.split("\n"); |
|
1206 | smallestIndent = -1; |
1238 | smallestIndent = -1; |
|
1207 | for (j = 0, len = lines.length; j < len; j++) { |
1239 | for (j = 0, len = lines.length; j < len; j++) { |
|
1208 | line = lines[j]; |
1240 | line = lines[j]; |
|
1209 | if (Utils.trim(line, ' ').length === 0) { |
1241 | if (Utils.trim(line, ' ').length === 0) { |
|
1210 | continue; |
1242 | continue; |
|
1211 | } |
1243 | } |
|
1212 | indent = line.length - Utils.ltrim(line).length; |
1244 | indent = line.length - Utils.ltrim(line).length; |
|
1213 | if (smallestIndent === -1 || indent < smallestIndent) { |
1245 | if (smallestIndent === -1 || indent < smallestIndent) { |
|
1214 | smallestIndent = indent; |
1246 | smallestIndent = indent; |
|
1215 | } |
1247 | } |
|
1216 | } |
1248 | } |
|
1217 | if (smallestIndent > 0) { |
1249 | if (smallestIndent > 0) { |
|
1218 | for (i = l = 0, len1 = lines.length; l < len1; i = ++l) { |
1250 | for (i = l = 0, len1 = lines.length; l < len1; i = ++l) { |
|
1219 | line = lines[i]; |
1251 | line = lines[i]; |
|
1220 | lines[i] = line.slice(smallestIndent); |
1252 | lines[i] = line.slice(smallestIndent); |
|
1221 | } |
1253 | } |
|
1222 | value = lines.join("\n"); |
1254 | value = lines.join("\n"); |
|
1223 | } |
1255 | } |
|
1224 | return value; |
1256 | return value; |
|
1225 | }; |
1257 | }; |
|
1226 | |
1258 | |
|
1227 | Parser.prototype.isNextLineUnIndentedCollection = function(currentIndentation) { |
1259 | Parser.prototype.isNextLineUnIndentedCollection = function(currentIndentation) { |
|
1228 | var notEOF, ret; |
1260 | var notEOF, ret; |
|
1229 | if (currentIndentation == null) { |
1261 | if (currentIndentation == null) { |
|
1230 | currentIndentation = null; |
1262 | currentIndentation = null; |
|
1231 | } |
1263 | } |
|
1232 | if (currentIndentation == null) { |
1264 | if (currentIndentation == null) { |
|
1233 | currentIndentation = this.getCurrentLineIndentation(); |
1265 | currentIndentation = this.getCurrentLineIndentation(); |
|
1234 | } |
1266 | } |
|
1235 | notEOF = this.moveToNextLine(); |
1267 | notEOF = this.moveToNextLine(); |
|
1236 | while (notEOF && this.isCurrentLineEmpty()) { |
1268 | while (notEOF && this.isCurrentLineEmpty()) { |
|
1237 | notEOF = this.moveToNextLine(); |
1269 | notEOF = this.moveToNextLine(); |
|
1238 | } |
1270 | } |
|
1239 | if (false === notEOF) { |
1271 | if (false === notEOF) { |
|
1240 | return false; |
1272 | return false; |
|
1241 | } |
1273 | } |
|
1242 | ret = false; |
1274 | ret = false; |
|
1243 | if (this.getCurrentLineIndentation() === currentIndentation && this.isStringUnIndentedCollectionItem(this.currentLine)) { |
1275 | if (this.getCurrentLineIndentation() === currentIndentation && this.isStringUnIndentedCollectionItem(this.currentLine)) { |
|
1244 | ret = true; |
1276 | ret = true; |
|
1245 | } |
1277 | } |
|
1246 | this.moveToPreviousLine(); |
1278 | this.moveToPreviousLine(); |
|
1247 | return ret; |
1279 | return ret; |
|
1248 | }; |
1280 | }; |
|
1249 | |
1281 | |
|
1250 | Parser.prototype.isStringUnIndentedCollectionItem = function() { |
1282 | Parser.prototype.isStringUnIndentedCollectionItem = function() { |
|
1251 | return this.currentLine === '-' || this.currentLine.slice(0, 2) === '- '; |
1283 | return this.currentLine === '-' || this.currentLine.slice(0, 2) === '- '; |
|
1252 | }; |
1284 | }; |
|
1253 | |
1285 | |
|
1254 | return Parser; |
1286 | return Parser; |
|
1255 | |
1287 | |
|
1256 | })(); |
1288 | })(); |
|
1257 | |
1289 | |
|
1258 | module.exports = Parser; |
1290 | module.exports = Parser; |
|
1259 | |
1291 | |
|
1260 | |
1292 | |
|
1261 | },{"./Exception/ParseException":4,"./Inline":5,"./Pattern":7,"./Utils":9}],7:[function(require,module,exports){ |
1293 | },{"./Exception/ParseException":4,"./Exception/ParseMore":5,"./Inline":6,"./Pattern":8,"./Utils":10}],8:[function(require,module,exports){ |
|
1262 | var Pattern; |
1294 | var Pattern; |
|
1263 | |
1295 | |
|
1264 | Pattern = (function() { |
1296 | Pattern = (function() { |
|
1265 | Pattern.prototype.regex = null; |
1297 | Pattern.prototype.regex = null; |
|
1266 | |
1298 | |
|
1267 | Pattern.prototype.rawRegex = null; |
1299 | Pattern.prototype.rawRegex = null; |
|
1268 | |
1300 | |
|
1269 | Pattern.prototype.cleanedRegex = null; |
1301 | Pattern.prototype.cleanedRegex = null; |
|
1270 | |
1302 | |
|
1271 | Pattern.prototype.mapping = null; |
1303 | Pattern.prototype.mapping = null; |
|
1272 | |
1304 | |
|
1273 | function Pattern(rawRegex, modifiers) { |
1305 | function Pattern(rawRegex, modifiers) { |
|
1274 | var _char, capturingBracketNumber, cleanedRegex, i, len, mapping, name, part, subChar; |
1306 | var _char, capturingBracketNumber, cleanedRegex, i, len, mapping, name, part, subChar; |
|
1275 | if (modifiers == null) { |
1307 | if (modifiers == null) { |
|
1276 | modifiers = ''; |
1308 | modifiers = ''; |
|
1277 | } |
1309 | } |
|
1278 | cleanedRegex = ''; |
1310 | cleanedRegex = ''; |
|
1279 | len = rawRegex.length; |
1311 | len = rawRegex.length; |
|
1280 | mapping = null; |
1312 | mapping = null; |
|
1281 | capturingBracketNumber = 0; |
1313 | capturingBracketNumber = 0; |
|
1282 | i = 0; |
1314 | i = 0; |
|
1283 | while (i < len) { |
1315 | while (i < len) { |
|
1284 | _char = rawRegex.charAt(i); |
1316 | _char = rawRegex.charAt(i); |
|
1285 | if (_char === '\\') { |
1317 | if (_char === '\\') { |
|
1286 | cleanedRegex += rawRegex.slice(i, +(i + 1) + 1 || 9e9); |
1318 | cleanedRegex += rawRegex.slice(i, +(i + 1) + 1 || 9e9); |
|
1287 | i++; |
1319 | i++; |
|
1288 | } else if (_char === '(') { |
1320 | } else if (_char === '(') { |
|
1289 | if (i < len - 2) { |
1321 | if (i < len - 2) { |
|
1290 | part = rawRegex.slice(i, +(i + 2) + 1 || 9e9); |
1322 | part = rawRegex.slice(i, +(i + 2) + 1 || 9e9); |
|
1291 | if (part === '(?:') { |
1323 | if (part === '(?:') { |
|
1292 | i += 2; |
1324 | i += 2; |
|
1293 | cleanedRegex += part; |
1325 | cleanedRegex += part; |
|
1294 | } else if (part === '(?<') { |
1326 | } else if (part === '(?<') { |
|
1295 | capturingBracketNumber++; |
1327 | capturingBracketNumber++; |
|
1296 | i += 2; |
1328 | i += 2; |
|
1297 | name = ''; |
1329 | name = ''; |
|
1298 | while (i + 1 < len) { |
1330 | while (i + 1 < len) { |
|
1299 | subChar = rawRegex.charAt(i + 1); |
1331 | subChar = rawRegex.charAt(i + 1); |
|
1300 | if (subChar === '>') { |
1332 | if (subChar === '>') { |
|
1301 | cleanedRegex += '('; |
1333 | cleanedRegex += '('; |
|
1302 | i++; |
1334 | i++; |
|
1303 | if (name.length > 0) { |
1335 | if (name.length > 0) { |
|
1304 | if (mapping == null) { |
1336 | if (mapping == null) { |
|
1305 | mapping = {}; |
1337 | mapping = {}; |
|
1306 | } |
1338 | } |
|
1307 | mapping[name] = capturingBracketNumber; |
1339 | mapping[name] = capturingBracketNumber; |
|
1308 | } |
1340 | } |
|
1309 | break; |
1341 | break; |
|
1310 | } else { |
1342 | } else { |
|
1311 | name += subChar; |
1343 | name += subChar; |
|
1312 | } |
1344 | } |
|
1313 | i++; |
1345 | i++; |
|
1314 | } |
1346 | } |
|
1315 | } else { |
1347 | } else { |
|
1316 | cleanedRegex += _char; |
1348 | cleanedRegex += _char; |
|
1317 | capturingBracketNumber++; |
1349 | capturingBracketNumber++; |
|
1318 | } |
1350 | } |
|
1319 | } else { |
1351 | } else { |
|
1320 | cleanedRegex += _char; |
1352 | cleanedRegex += _char; |
|
1321 | } |
1353 | } |
|
1322 | } else { |
1354 | } else { |
|
1323 | cleanedRegex += _char; |
1355 | cleanedRegex += _char; |
|
1324 | } |
1356 | } |
|
1325 | i++; |
1357 | i++; |
|
1326 | } |
1358 | } |
|
1327 | this.rawRegex = rawRegex; |
1359 | this.rawRegex = rawRegex; |
|
1328 | this.cleanedRegex = cleanedRegex; |
1360 | this.cleanedRegex = cleanedRegex; |
|
1329 | this.regex = new RegExp(this.cleanedRegex, 'g' + modifiers.replace('g', '')); |
1361 | this.regex = new RegExp(this.cleanedRegex, 'g' + modifiers.replace('g', '')); |
|
1330 | this.mapping = mapping; |
1362 | this.mapping = mapping; |
|
1331 | } |
1363 | } |
|
1332 | |
1364 | |
|
1333 | Pattern.prototype.exec = function(str) { |
1365 | Pattern.prototype.exec = function(str) { |
|
1334 | var index, matches, name, ref; |
1366 | var index, matches, name, ref; |
|
1335 | this.regex.lastIndex = 0; |
1367 | this.regex.lastIndex = 0; |
|
1336 | matches = this.regex.exec(str); |
1368 | matches = this.regex.exec(str); |
|
1337 | if (matches == null) { |
1369 | if (matches == null) { |
|
1338 | return null; |
1370 | return null; |
|
1339 | } |
1371 | } |
|
1340 | if (this.mapping != null) { |
1372 | if (this.mapping != null) { |
|
1341 | ref = this.mapping; |
1373 | ref = this.mapping; |
|
1342 | for (name in ref) { |
1374 | for (name in ref) { |
|
1343 | index = ref[name]; |
1375 | index = ref[name]; |
|
1344 | matches[name] = matches[index]; |
1376 | matches[name] = matches[index]; |
|
1345 | } |
1377 | } |
|
1346 | } |
1378 | } |
|
1347 | return matches; |
1379 | return matches; |
|
1348 | }; |
1380 | }; |
|
1349 | |
1381 | |
|
1350 | Pattern.prototype.test = function(str) { |
1382 | Pattern.prototype.test = function(str) { |
|
1351 | this.regex.lastIndex = 0; |
1383 | this.regex.lastIndex = 0; |
|
1352 | return this.regex.test(str); |
1384 | return this.regex.test(str); |
|
1353 | }; |
1385 | }; |
|
1354 | |
1386 | |
|
1355 | Pattern.prototype.replace = function(str, replacement) { |
1387 | Pattern.prototype.replace = function(str, replacement) { |
|
1356 | this.regex.lastIndex = 0; |
1388 | this.regex.lastIndex = 0; |
|
1357 | return str.replace(this.regex, replacement); |
1389 | return str.replace(this.regex, replacement); |
|
1358 | }; |
1390 | }; |
|
1359 | |
1391 | |
|
1360 | Pattern.prototype.replaceAll = function(str, replacement, limit) { |
1392 | Pattern.prototype.replaceAll = function(str, replacement, limit) { |
|
1361 | var count; |
1393 | var count; |
|
1362 | if (limit == null) { |
1394 | if (limit == null) { |
|
1363 | limit = 0; |
1395 | limit = 0; |
|
1364 | } |
1396 | } |
|
1365 | this.regex.lastIndex = 0; |
1397 | this.regex.lastIndex = 0; |
|
1366 | count = 0; |
1398 | count = 0; |
|
1367 | while (this.regex.test(str) && (limit === 0 || count < limit)) { |
1399 | while (this.regex.test(str) && (limit === 0 || count < limit)) { |
|
1368 | this.regex.lastIndex = 0; |
1400 | this.regex.lastIndex = 0; |
|
1369 | str = str.replace(this.regex, ''); |
1401 | str = str.replace(this.regex, replacement); |
|
1370 | count++; |
1402 | count++; |
|
1371 | } |
1403 | } |
|
1372 | return [str, count]; |
1404 | return [str, count]; |
|
1373 | }; |
1405 | }; |
|
1374 | |
1406 | |
|
1375 | return Pattern; |
1407 | return Pattern; |
|
1376 | |
1408 | |
|
1377 | })(); |
1409 | })(); |
|
1378 | |
1410 | |
|
1379 | module.exports = Pattern; |
1411 | module.exports = Pattern; |
|
1380 | |
1412 | |
|
1381 | |
1413 | |
|
1382 | },{}],8:[function(require,module,exports){ |
1414 | },{}],9:[function(require,module,exports){ |
|
1383 | var Pattern, Unescaper, Utils; |
1415 | var Pattern, Unescaper, Utils; |
|
1384 | |
1416 | |
|
1385 | Utils = require('./Utils'); |
1417 | Utils = require('./Utils'); |
|
1386 | |
1418 | |
|
1387 | Pattern = require('./Pattern'); |
1419 | Pattern = require('./Pattern'); |
|
1388 | |
1420 | |
|
1389 | Unescaper = (function() { |
1421 | Unescaper = (function() { |
|
1390 | function Unescaper() {} |
1422 | function Unescaper() {} |
|
1391 | |
1423 | |
|
1392 | Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})'); |
1424 | Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})'); |
|
1393 | |
1425 | |
|
1394 | Unescaper.unescapeSingleQuotedString = function(value) { |
1426 | Unescaper.unescapeSingleQuotedString = function(value) { |
|
1395 | return value.replace(/\'\'/g, '\''); |
1427 | return value.replace(/\'\'/g, '\''); |
|
1396 | }; |
1428 | }; |
|
1397 | |
1429 | |
|
1398 | Unescaper.unescapeDoubleQuotedString = function(value) { |
1430 | Unescaper.unescapeDoubleQuotedString = function(value) { |
|
1399 | if (this._unescapeCallback == null) { |
1431 | if (this._unescapeCallback == null) { |
|
1400 | this._unescapeCallback = (function(_this) { |
1432 | this._unescapeCallback = (function(_this) { |
|
1401 | return function(str) { |
1433 | return function(str) { |
|
1402 | return _this.unescapeCharacter(str); |
1434 | return _this.unescapeCharacter(str); |
|
1403 | }; |
1435 | }; |
|
1404 | })(this); |
1436 | })(this); |
|
1405 | } |
1437 | } |
|
1406 | return this.PATTERN_ESCAPED_CHARACTER.replace(value, this._unescapeCallback); |
1438 | return this.PATTERN_ESCAPED_CHARACTER.replace(value, this._unescapeCallback); |
|
1407 | }; |
1439 | }; |
|
1408 | |
1440 | |
|
1409 | Unescaper.unescapeCharacter = function(value) { |
1441 | Unescaper.unescapeCharacter = function(value) { |
|
1410 | var ch; |
1442 | var ch; |
|
1411 | ch = String.fromCharCode; |
1443 | ch = String.fromCharCode; |
|
1412 | switch (value.charAt(1)) { |
1444 | switch (value.charAt(1)) { |
|
1413 | case '0': |
1445 | case '0': |
|
1414 | return ch(0); |
1446 | return ch(0); |
|
1415 | case 'a': |
1447 | case 'a': |
|
1416 | return ch(7); |
1448 | return ch(7); |
|
1417 | case 'b': |
1449 | case 'b': |
|
1418 | return ch(8); |
1450 | return ch(8); |
|
1419 | case 't': |
1451 | case 't': |
|
1420 | return "\t"; |
1452 | return "\t"; |
|
1421 | case "\t": |
1453 | case "\t": |
|
1422 | return "\t"; |
1454 | return "\t"; |
|
1423 | case 'n': |
1455 | case 'n': |
|
1424 | return "\n"; |
1456 | return "\n"; |
|
1425 | case 'v': |
1457 | case 'v': |
|
1426 | return ch(11); |
1458 | return ch(11); |
|
1427 | case 'f': |
1459 | case 'f': |
|
1428 | return ch(12); |
1460 | return ch(12); |
|
1429 | case 'r': |
1461 | case 'r': |
|
1430 | return ch(13); |
1462 | return ch(13); |
|
1431 | case 'e': |
1463 | case 'e': |
|
1432 | return ch(27); |
1464 | return ch(27); |
|
1433 | case ' ': |
1465 | case ' ': |
|
1434 | return ' '; |
1466 | return ' '; |
|
1435 | case '"': |
1467 | case '"': |
|
1436 | return '"'; |
1468 | return '"'; |
|
1437 | case '/': |
1469 | case '/': |
|
1438 | return '/'; |
1470 | return '/'; |
|
1439 | case '\\': |
1471 | case '\\': |
|
1440 | return '\\'; |
1472 | return '\\'; |
|
1441 | case 'N': |
1473 | case 'N': |
|
1442 | return ch(0x0085); |
1474 | return ch(0x0085); |
|
1443 | case '_': |
1475 | case '_': |
|
1444 | return ch(0x00A0); |
1476 | return ch(0x00A0); |
|
1445 | case 'L': |
1477 | case 'L': |
|
1446 | return ch(0x2028); |
1478 | return ch(0x2028); |
|
1447 | case 'P': |
1479 | case 'P': |
|
1448 | return ch(0x2029); |
1480 | return ch(0x2029); |
|
1449 | case 'x': |
1481 | case 'x': |
|
1450 | return Utils.utf8chr(Utils.hexDec(value.substr(2, 2))); |
1482 | return Utils.utf8chr(Utils.hexDec(value.substr(2, 2))); |
|
1451 | case 'u': |
1483 | case 'u': |
|
1452 | return Utils.utf8chr(Utils.hexDec(value.substr(2, 4))); |
1484 | return Utils.utf8chr(Utils.hexDec(value.substr(2, 4))); |
|
1453 | case 'U': |
1485 | case 'U': |
|
1454 | return Utils.utf8chr(Utils.hexDec(value.substr(2, 8))); |
1486 | return Utils.utf8chr(Utils.hexDec(value.substr(2, 8))); |
|
1455 | default: |
1487 | default: |
|
1456 | return ''; |
1488 | return ''; |
|
1457 | } |
1489 | } |
|
1458 | }; |
1490 | }; |
|
1459 | |
1491 | |
|
1460 | return Unescaper; |
1492 | return Unescaper; |
|
1461 | |
1493 | |
|
1462 | })(); |
1494 | })(); |
|
1463 | |
1495 | |
|
1464 | module.exports = Unescaper; |
1496 | module.exports = Unescaper; |
|
1465 | |
1497 | |
|
1466 | |
1498 | |
|
1467 | },{"./Pattern":7,"./Utils":9}],9:[function(require,module,exports){ |
1499 | },{"./Pattern":8,"./Utils":10}],10:[function(require,module,exports){ |
|
- | 1500 | var Pattern, Utils, |
||
1468 | var Pattern, Utils; |
1501 | hasProp = {}.hasOwnProperty; |
|
1469 | |
1502 | |
|
1470 | Pattern = require('./Pattern'); |
1503 | Pattern = require('./Pattern'); |
|
1471 | |
1504 | |
|
1472 | Utils = (function() { |
1505 | Utils = (function() { |
|
1473 | function Utils() {} |
1506 | function Utils() {} |
|
1474 | |
1507 | |
|
1475 | Utils.REGEX_LEFT_TRIM_BY_CHAR = {}; |
1508 | Utils.REGEX_LEFT_TRIM_BY_CHAR = {}; |
|
1476 | |
1509 | |
|
1477 | Utils.REGEX_RIGHT_TRIM_BY_CHAR = {}; |
1510 | Utils.REGEX_RIGHT_TRIM_BY_CHAR = {}; |
|
1478 | |
1511 | |
|
1479 | Utils.REGEX_SPACES = /\s+/g; |
1512 | Utils.REGEX_SPACES = /\s+/g; |
|
1480 | |
1513 | |
|
1481 | Utils.REGEX_DIGITS = /^\d+$/; |
1514 | Utils.REGEX_DIGITS = /^\d+$/; |
|
1482 | |
1515 | |
|
1483 | Utils.REGEX_OCTAL = /[^0-7]/gi; |
1516 | Utils.REGEX_OCTAL = /[^0-7]/gi; |
|
1484 | |
1517 | |
|
1485 | Utils.REGEX_HEXADECIMAL = /[^a-f0-9]/gi; |
1518 | Utils.REGEX_HEXADECIMAL = /[^a-f0-9]/gi; |
|
1486 | |
1519 | |
|
1487 | Utils.PATTERN_DATE = new Pattern('^' + '(?<year>[0-9][0-9][0-9][0-9])' + '-(?<month>[0-9][0-9]?)' + '-(?<day>[0-9][0-9]?)' + '(?:(?:[Tt]|[ \t]+)' + '(?<hour>[0-9][0-9]?)' + ':(?<minute>[0-9][0-9])' + ':(?<second>[0-9][0-9])' + '(?:\.(?<fraction>[0-9]*))?' + '(?:[ \t]*(?<tz>Z|(?<tz_sign>[-+])(?<tz_hour>[0-9][0-9]?)' + '(?::(?<tz_minute>[0-9][0-9]))?))?)?' + '$', 'i'); |
1520 | Utils.PATTERN_DATE = new Pattern('^' + '(?<year>[0-9][0-9][0-9][0-9])' + '-(?<month>[0-9][0-9]?)' + '-(?<day>[0-9][0-9]?)' + '(?:(?:[Tt]|[ \t]+)' + '(?<hour>[0-9][0-9]?)' + ':(?<minute>[0-9][0-9])' + ':(?<second>[0-9][0-9])' + '(?:\.(?<fraction>[0-9]*))?' + '(?:[ \t]*(?<tz>Z|(?<tz_sign>[-+])(?<tz_hour>[0-9][0-9]?)' + '(?::(?<tz_minute>[0-9][0-9]))?))?)?' + '$', 'i'); |
|
1488 | |
1521 | |
|
1489 | Utils.LOCAL_TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000; |
1522 | Utils.LOCAL_TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000; |
|
1490 | |
1523 | |
|
1491 | Utils.trim = function(str, _char) { |
1524 | Utils.trim = function(str, _char) { |
|
1492 | var regexLeft, regexRight; |
1525 | var regexLeft, regexRight; |
|
1493 | if (_char == null) { |
1526 | if (_char == null) { |
|
1494 | _char = '\\s'; |
1527 | _char = '\\s'; |
|
1495 | } |
1528 | } |
|
1496 | return str.trim(); |
- | ||
1497 | regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[_char]; |
1529 | regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[_char]; |
|
1498 | if (regexLeft == null) { |
1530 | if (regexLeft == null) { |
|
1499 | this.REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp('^' + _char + '' + _char + '*'); |
1531 | this.REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp('^' + _char + '' + _char + '*'); |
|
1500 | } |
1532 | } |
|
1501 | regexLeft.lastIndex = 0; |
1533 | regexLeft.lastIndex = 0; |
|
1502 | regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[_char]; |
1534 | regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[_char]; |
|
1503 | if (regexRight == null) { |
1535 | if (regexRight == null) { |
|
1504 | this.REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp(_char + '' + _char + '*$'); |
1536 | this.REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp(_char + '' + _char + '*$'); |
|
1505 | } |
1537 | } |
|
1506 | regexRight.lastIndex = 0; |
1538 | regexRight.lastIndex = 0; |
|
1507 | return str.replace(regexLeft, '').replace(regexRight, ''); |
1539 | return str.replace(regexLeft, '').replace(regexRight, ''); |
|
1508 | }; |
1540 | }; |
|
1509 | |
1541 | |
|
1510 | Utils.ltrim = function(str, _char) { |
1542 | Utils.ltrim = function(str, _char) { |
|
1511 | var regexLeft; |
1543 | var regexLeft; |
|
1512 | if (_char == null) { |
1544 | if (_char == null) { |
|
1513 | _char = '\\s'; |
1545 | _char = '\\s'; |
|
1514 | } |
1546 | } |
|
1515 | regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[_char]; |
1547 | regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[_char]; |
|
1516 | if (regexLeft == null) { |
1548 | if (regexLeft == null) { |
|
1517 | this.REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp('^' + _char + '' + _char + '*'); |
1549 | this.REGEX_LEFT_TRIM_BY_CHAR[_char] = regexLeft = new RegExp('^' + _char + '' + _char + '*'); |
|
1518 | } |
1550 | } |
|
1519 | regexLeft.lastIndex = 0; |
1551 | regexLeft.lastIndex = 0; |
|
1520 | return str.replace(regexLeft, ''); |
1552 | return str.replace(regexLeft, ''); |
|
1521 | }; |
1553 | }; |
|
1522 | |
1554 | |
|
1523 | Utils.rtrim = function(str, _char) { |
1555 | Utils.rtrim = function(str, _char) { |
|
1524 | var regexRight; |
1556 | var regexRight; |
|
1525 | if (_char == null) { |
1557 | if (_char == null) { |
|
1526 | _char = '\\s'; |
1558 | _char = '\\s'; |
|
1527 | } |
1559 | } |
|
1528 | regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[_char]; |
1560 | regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[_char]; |
|
1529 | if (regexRight == null) { |
1561 | if (regexRight == null) { |
|
1530 | this.REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp(_char + '' + _char + '*$'); |
1562 | this.REGEX_RIGHT_TRIM_BY_CHAR[_char] = regexRight = new RegExp(_char + '' + _char + '*$'); |
|
1531 | } |
1563 | } |
|
1532 | regexRight.lastIndex = 0; |
1564 | regexRight.lastIndex = 0; |
|
1533 | return str.replace(regexRight, ''); |
1565 | return str.replace(regexRight, ''); |
|
1534 | }; |
1566 | }; |
|
1535 | |
1567 | |
|
1536 | Utils.isEmpty = function(value) { |
1568 | Utils.isEmpty = function(value) { |
|
1537 | return !value || value === '' || value === '0' || (value instanceof Array && value.length === 0); |
1569 | return !value || value === '' || value === '0' || (value instanceof Array && value.length === 0) || this.isEmptyObject(value); |
|
- | 1570 | }; |
||
- | 1571 | |
||
- | 1572 | Utils.isEmptyObject = function(value) { |
||
- | 1573 | var k; |
||
- | 1574 | return value instanceof Object && ((function() { |
||
- | 1575 | var results; |
||
- | 1576 | results = []; |
||
- | 1577 | for (k in value) { |
||
- | 1578 | if (!hasProp.call(value, k)) continue; |
||
- | 1579 | results.push(k); |
||
- | 1580 | } |
||
- | 1581 | return results; |
||
- | 1582 | })()).length === 0; |
||
1538 | }; |
1583 | }; |
|
1539 | |
1584 | |
|
1540 | Utils.subStrCount = function(string, subString, start, length) { |
1585 | Utils.subStrCount = function(string, subString, start, length) { |
|
1541 | var c, i, j, len, ref, sublen; |
1586 | var c, i, j, len, ref, sublen; |
|
1542 | c = 0; |
1587 | c = 0; |
|
1543 | string = '' + string; |
1588 | string = '' + string; |
|
1544 | subString = '' + subString; |
1589 | subString = '' + subString; |
|
1545 | if (start != null) { |
1590 | if (start != null) { |
|
1546 | string = string.slice(start); |
1591 | string = string.slice(start); |
|
1547 | } |
1592 | } |
|
1548 | if (length != null) { |
1593 | if (length != null) { |
|
1549 | string = string.slice(0, length); |
1594 | string = string.slice(0, length); |
|
1550 | } |
1595 | } |
|
1551 | len = string.length; |
1596 | len = string.length; |
|
1552 | sublen = subString.length; |
1597 | sublen = subString.length; |
|
1553 | for (i = j = 0, ref = len; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { |
1598 | for (i = j = 0, ref = len; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { |
|
1554 | if (subString === string.slice(i, sublen)) { |
1599 | if (subString === string.slice(i, sublen)) { |
|
1555 | c++; |
1600 | c++; |
|
1556 | i += sublen - 1; |
1601 | i += sublen - 1; |
|
1557 | } |
1602 | } |
|
1558 | } |
1603 | } |
|
1559 | return c; |
1604 | return c; |
|
1560 | }; |
1605 | }; |
|
1561 | |
1606 | |
|
1562 | Utils.isDigits = function(input) { |
1607 | Utils.isDigits = function(input) { |
|
1563 | this.REGEX_DIGITS.lastIndex = 0; |
1608 | this.REGEX_DIGITS.lastIndex = 0; |
|
1564 | return this.REGEX_DIGITS.test(input); |
1609 | return this.REGEX_DIGITS.test(input); |
|
1565 | }; |
1610 | }; |
|
1566 | |
1611 | |
|
1567 | Utils.octDec = function(input) { |
1612 | Utils.octDec = function(input) { |
|
1568 | this.REGEX_OCTAL.lastIndex = 0; |
1613 | this.REGEX_OCTAL.lastIndex = 0; |
|
1569 | return parseInt((input + '').replace(this.REGEX_OCTAL, ''), 8); |
1614 | return parseInt((input + '').replace(this.REGEX_OCTAL, ''), 8); |
|
1570 | }; |
1615 | }; |
|
1571 | |
1616 | |
|
1572 | Utils.hexDec = function(input) { |
1617 | Utils.hexDec = function(input) { |
|
1573 | this.REGEX_HEXADECIMAL.lastIndex = 0; |
1618 | this.REGEX_HEXADECIMAL.lastIndex = 0; |
|
1574 | input = this.trim(input); |
1619 | input = this.trim(input); |
|
1575 | if ((input + '').slice(0, 2) === '0x') { |
1620 | if ((input + '').slice(0, 2) === '0x') { |
|
1576 | input = (input + '').slice(2); |
1621 | input = (input + '').slice(2); |
|
1577 | } |
1622 | } |
|
1578 | return parseInt((input + '').replace(this.REGEX_HEXADECIMAL, ''), 16); |
1623 | return parseInt((input + '').replace(this.REGEX_HEXADECIMAL, ''), 16); |
|
1579 | }; |
1624 | }; |
|
1580 | |
1625 | |
|
1581 | Utils.utf8chr = function(c) { |
1626 | Utils.utf8chr = function(c) { |
|
1582 | var ch; |
1627 | var ch; |
|
1583 | ch = String.fromCharCode; |
1628 | ch = String.fromCharCode; |
|
1584 | if (0x80 > (c %= 0x200000)) { |
1629 | if (0x80 > (c %= 0x200000)) { |
|
1585 | return ch(c); |
1630 | return ch(c); |
|
1586 | } |
1631 | } |
|
1587 | if (0x800 > c) { |
1632 | if (0x800 > c) { |
|
1588 | return ch(0xC0 | c >> 6) + ch(0x80 | c & 0x3F); |
1633 | return ch(0xC0 | c >> 6) + ch(0x80 | c & 0x3F); |
|
1589 | } |
1634 | } |
|
1590 | if (0x10000 > c) { |
1635 | if (0x10000 > c) { |
|
1591 | return ch(0xE0 | c >> 12) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F); |
1636 | return ch(0xE0 | c >> 12) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F); |
|
1592 | } |
1637 | } |
|
1593 | return ch(0xF0 | c >> 18) + ch(0x80 | c >> 12 & 0x3F) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F); |
1638 | return ch(0xF0 | c >> 18) + ch(0x80 | c >> 12 & 0x3F) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F); |
|
1594 | }; |
1639 | }; |
|
1595 | |
1640 | |
|
1596 | Utils.parseBoolean = function(input, strict) { |
1641 | Utils.parseBoolean = function(input, strict) { |
|
1597 | var lowerInput; |
1642 | var lowerInput; |
|
1598 | if (strict == null) { |
1643 | if (strict == null) { |
|
1599 | strict = true; |
1644 | strict = true; |
|
1600 | } |
1645 | } |
|
1601 | if (typeof input === 'string') { |
1646 | if (typeof input === 'string') { |
|
1602 | lowerInput = input.toLowerCase(); |
1647 | lowerInput = input.toLowerCase(); |
|
1603 | if (!strict) { |
1648 | if (!strict) { |
|
1604 | if (lowerInput === 'no') { |
1649 | if (lowerInput === 'no') { |
|
1605 | return false; |
1650 | return false; |
|
1606 | } |
1651 | } |
|
1607 | } |
1652 | } |
|
1608 | if (lowerInput === '0') { |
1653 | if (lowerInput === '0') { |
|
1609 | return false; |
1654 | return false; |
|
1610 | } |
1655 | } |
|
1611 | if (lowerInput === 'false') { |
1656 | if (lowerInput === 'false') { |
|
1612 | return false; |
1657 | return false; |
|
1613 | } |
1658 | } |
|
1614 | if (lowerInput === '') { |
1659 | if (lowerInput === '') { |
|
1615 | return false; |
1660 | return false; |
|
1616 | } |
1661 | } |
|
1617 | return true; |
1662 | return true; |
|
1618 | } |
1663 | } |
|
1619 | return !!input; |
1664 | return !!input; |
|
1620 | }; |
1665 | }; |
|
1621 | |
1666 | |
|
1622 | Utils.isNumeric = function(input) { |
1667 | Utils.isNumeric = function(input) { |
|
1623 | this.REGEX_SPACES.lastIndex = 0; |
1668 | this.REGEX_SPACES.lastIndex = 0; |
|
1624 | return typeof input === 'number' || typeof input === 'string' && !isNaN(input) && input.replace(this.REGEX_SPACES, '') !== ''; |
1669 | return typeof input === 'number' || typeof input === 'string' && !isNaN(input) && input.replace(this.REGEX_SPACES, '') !== ''; |
|
1625 | }; |
1670 | }; |
|
1626 | |
1671 | |
|
1627 | Utils.stringToDate = function(str) { |
1672 | Utils.stringToDate = function(str) { |
|
1628 | var date, day, fraction, hour, info, minute, month, second, tz_hour, tz_minute, tz_offset, year; |
1673 | var date, day, fraction, hour, info, minute, month, second, tz_hour, tz_minute, tz_offset, year; |
|
1629 | if (!(str != null ? str.length : void 0)) { |
1674 | if (!(str != null ? str.length : void 0)) { |
|
1630 | return null; |
1675 | return null; |
|
1631 | } |
1676 | } |
|
1632 | info = this.PATTERN_DATE.exec(str); |
1677 | info = this.PATTERN_DATE.exec(str); |
|
1633 | if (!info) { |
1678 | if (!info) { |
|
1634 | return null; |
1679 | return null; |
|
1635 | } |
1680 | } |
|
1636 | year = parseInt(info.year, 10); |
1681 | year = parseInt(info.year, 10); |
|
1637 | month = parseInt(info.month, 10) - 1; |
1682 | month = parseInt(info.month, 10) - 1; |
|
1638 | day = parseInt(info.day, 10); |
1683 | day = parseInt(info.day, 10); |
|
1639 | if (info.hour == null) { |
1684 | if (info.hour == null) { |
|
1640 | date = new Date(Date.UTC(year, month, day)); |
1685 | date = new Date(Date.UTC(year, month, day)); |
|
1641 | return date; |
1686 | return date; |
|
1642 | } |
1687 | } |
|
1643 | hour = parseInt(info.hour, 10); |
1688 | hour = parseInt(info.hour, 10); |
|
1644 | minute = parseInt(info.minute, 10); |
1689 | minute = parseInt(info.minute, 10); |
|
1645 | second = parseInt(info.second, 10); |
1690 | second = parseInt(info.second, 10); |
|
1646 | if (info.fraction != null) { |
1691 | if (info.fraction != null) { |
|
1647 | fraction = info.fraction.slice(0, 3); |
1692 | fraction = info.fraction.slice(0, 3); |
|
1648 | while (fraction.length < 3) { |
1693 | while (fraction.length < 3) { |
|
1649 | fraction += '0'; |
1694 | fraction += '0'; |
|
1650 | } |
1695 | } |
|
1651 | fraction = parseInt(fraction, 10); |
1696 | fraction = parseInt(fraction, 10); |
|
1652 | } else { |
1697 | } else { |
|
1653 | fraction = 0; |
1698 | fraction = 0; |
|
1654 | } |
1699 | } |
|
1655 | if (info.tz != null) { |
1700 | if (info.tz != null) { |
|
1656 | tz_hour = parseInt(info.tz_hour, 10); |
1701 | tz_hour = parseInt(info.tz_hour, 10); |
|
1657 | if (info.tz_minute != null) { |
1702 | if (info.tz_minute != null) { |
|
1658 | tz_minute = parseInt(info.tz_minute, 10); |
1703 | tz_minute = parseInt(info.tz_minute, 10); |
|
1659 | } else { |
1704 | } else { |
|
1660 | tz_minute = 0; |
1705 | tz_minute = 0; |
|
1661 | } |
1706 | } |
|
1662 | tz_offset = (tz_hour * 60 + tz_minute) * 60000; |
1707 | tz_offset = (tz_hour * 60 + tz_minute) * 60000; |
|
1663 | if ('-' === info.tz_sign) { |
1708 | if ('-' === info.tz_sign) { |
|
1664 | tz_offset *= -1; |
1709 | tz_offset *= -1; |
|
1665 | } |
1710 | } |
|
1666 | } |
1711 | } |
|
1667 | date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction)); |
1712 | date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction)); |
|
1668 | if (tz_offset) { |
1713 | if (tz_offset) { |
|
1669 | date.setTime(date.getTime() + tz_offset); |
1714 | date.setTime(date.getTime() - tz_offset); |
|
1670 | } |
1715 | } |
|
1671 | return date; |
1716 | return date; |
|
1672 | }; |
1717 | }; |
|
1673 | |
1718 | |
|
1674 | Utils.strRepeat = function(str, number) { |
1719 | Utils.strRepeat = function(str, number) { |
|
1675 | var i, res; |
1720 | var i, res; |
|
1676 | res = ''; |
1721 | res = ''; |
|
1677 | i = 0; |
1722 | i = 0; |
|
1678 | while (i < number) { |
1723 | while (i < number) { |
|
1679 | res += str; |
1724 | res += str; |
|
1680 | i++; |
1725 | i++; |
|
1681 | } |
1726 | } |
|
1682 | return res; |
1727 | return res; |
|
1683 | }; |
1728 | }; |
|
1684 | |
1729 | |
|
1685 | Utils.getStringFromFile = function(path, callback) { |
1730 | Utils.getStringFromFile = function(path, callback) { |
|
1686 | var data, fs, j, len1, name, ref, req, xhr; |
1731 | var data, fs, j, len1, name, ref, req, xhr; |
|
1687 | if (callback == null) { |
1732 | if (callback == null) { |
|
1688 | callback = null; |
1733 | callback = null; |
|
1689 | } |
1734 | } |
|
1690 | xhr = null; |
1735 | xhr = null; |
|
1691 | if (typeof window !== "undefined" && window !== null) { |
1736 | if (typeof window !== "undefined" && window !== null) { |
|
1692 | if (window.XMLHttpRequest) { |
1737 | if (window.XMLHttpRequest) { |
|
1693 | xhr = new XMLHttpRequest(); |
1738 | xhr = new XMLHttpRequest(); |
|
1694 | } else if (window.ActiveXObject) { |
1739 | } else if (window.ActiveXObject) { |
|
1695 | ref = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]; |
1740 | ref = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]; |
|
1696 | for (j = 0, len1 = ref.length; j < len1; j++) { |
1741 | for (j = 0, len1 = ref.length; j < len1; j++) { |
|
1697 | name = ref[j]; |
1742 | name = ref[j]; |
|
1698 | try { |
1743 | try { |
|
1699 | xhr = new ActiveXObject(name); |
1744 | xhr = new ActiveXObject(name); |
|
1700 | } catch (undefined) {} |
1745 | } catch (undefined) {} |
|
1701 | } |
1746 | } |
|
1702 | } |
1747 | } |
|
1703 | } |
1748 | } |
|
1704 | if (xhr != null) { |
1749 | if (xhr != null) { |
|
1705 | if (callback != null) { |
1750 | if (callback != null) { |
|
1706 | xhr.onreadystatechange = function() { |
1751 | xhr.onreadystatechange = function() { |
|
1707 | if (xhr.readyState === 4) { |
1752 | if (xhr.readyState === 4) { |
|
1708 | if (xhr.status === 200 || xhr.status === 0) { |
1753 | if (xhr.status === 200 || xhr.status === 0) { |
|
1709 | return callback(xhr.responseText); |
1754 | return callback(xhr.responseText); |
|
1710 | } else { |
1755 | } else { |
|
1711 | return callback(null); |
1756 | return callback(null); |
|
1712 | } |
1757 | } |
|
1713 | } |
1758 | } |
|
1714 | }; |
1759 | }; |
|
1715 | xhr.open('GET', path, true); |
1760 | xhr.open('GET', path, true); |
|
1716 | return xhr.send(null); |
1761 | return xhr.send(null); |
|
1717 | } else { |
1762 | } else { |
|
1718 | xhr.open('GET', path, false); |
1763 | xhr.open('GET', path, false); |
|
1719 | xhr.send(null); |
1764 | xhr.send(null); |
|
1720 | if (xhr.status === 200 || xhr.status === 0) { |
1765 | if (xhr.status === 200 || xhr.status === 0) { |
|
1721 | return xhr.responseText; |
1766 | return xhr.responseText; |
|
1722 | } |
1767 | } |
|
1723 | return null; |
1768 | return null; |
|
1724 | } |
1769 | } |
|
1725 | } else { |
1770 | } else { |
|
1726 | req = require; |
1771 | req = require; |
|
1727 | fs = req('fs'); |
1772 | fs = req('fs'); |
|
1728 | if (callback != null) { |
1773 | if (callback != null) { |
|
1729 | return fs.readFile(path, function(err, data) { |
1774 | return fs.readFile(path, function(err, data) { |
|
1730 | if (err) { |
1775 | if (err) { |
|
1731 | return callback(null); |
1776 | return callback(null); |
|
1732 | } else { |
1777 | } else { |
|
1733 | return callback(String(data)); |
1778 | return callback(String(data)); |
|
1734 | } |
1779 | } |
|
1735 | }); |
1780 | }); |
|
1736 | } else { |
1781 | } else { |
|
1737 | data = fs.readFileSync(path); |
1782 | data = fs.readFileSync(path); |
|
1738 | if (data != null) { |
1783 | if (data != null) { |
|
1739 | return String(data); |
1784 | return String(data); |
|
1740 | } |
1785 | } |
|
1741 | return null; |
1786 | return null; |
|
1742 | } |
1787 | } |
|
1743 | } |
1788 | } |
|
1744 | }; |
1789 | }; |
|
1745 | |
1790 | |
|
1746 | return Utils; |
1791 | return Utils; |
|
1747 | |
1792 | |
|
1748 | })(); |
1793 | })(); |
|
1749 | |
1794 | |
|
1750 | module.exports = Utils; |
1795 | module.exports = Utils; |
|
1751 | |
1796 | |
|
1752 | |
1797 | |
|
1753 | },{"./Pattern":7}],10:[function(require,module,exports){ |
1798 | },{"./Pattern":8}],11:[function(require,module,exports){ |
|
1754 | var Dumper, Parser, Utils, Yaml; |
1799 | var Dumper, Parser, Utils, Yaml; |
|
1755 | |
1800 | |
|
1756 | Parser = require('./Parser'); |
1801 | Parser = require('./Parser'); |
|
1757 | |
1802 | |
|
1758 | Dumper = require('./Dumper'); |
1803 | Dumper = require('./Dumper'); |
|
1759 | |
1804 | |
|
1760 | Utils = require('./Utils'); |
1805 | Utils = require('./Utils'); |
|
1761 | |
1806 | |
|
1762 | Yaml = (function() { |
1807 | Yaml = (function() { |
|
1763 | function Yaml() {} |
1808 | function Yaml() {} |
|
1764 | |
1809 | |
|
1765 | Yaml.parse = function(input, exceptionOnInvalidType, objectDecoder) { |
1810 | Yaml.parse = function(input, exceptionOnInvalidType, objectDecoder) { |
|
1766 | if (exceptionOnInvalidType == null) { |
1811 | if (exceptionOnInvalidType == null) { |
|
1767 | exceptionOnInvalidType = false; |
1812 | exceptionOnInvalidType = false; |
|
1768 | } |
1813 | } |
|
1769 | if (objectDecoder == null) { |
1814 | if (objectDecoder == null) { |
|
1770 | objectDecoder = null; |
1815 | objectDecoder = null; |
|
1771 | } |
1816 | } |
|
1772 | return new Parser().parse(input, exceptionOnInvalidType, objectDecoder); |
1817 | return new Parser().parse(input, exceptionOnInvalidType, objectDecoder); |
|
1773 | }; |
1818 | }; |
|
1774 | |
1819 | |
|
1775 | Yaml.parseFile = function(path, callback, exceptionOnInvalidType, objectDecoder) { |
1820 | Yaml.parseFile = function(path, callback, exceptionOnInvalidType, objectDecoder) { |
|
1776 | var input; |
1821 | var input; |
|
1777 | if (callback == null) { |
1822 | if (callback == null) { |
|
1778 | callback = null; |
1823 | callback = null; |
|
1779 | } |
1824 | } |
|
1780 | if (exceptionOnInvalidType == null) { |
1825 | if (exceptionOnInvalidType == null) { |
|
1781 | exceptionOnInvalidType = false; |
1826 | exceptionOnInvalidType = false; |
|
1782 | } |
1827 | } |
|
1783 | if (objectDecoder == null) { |
1828 | if (objectDecoder == null) { |
|
1784 | objectDecoder = null; |
1829 | objectDecoder = null; |
|
1785 | } |
1830 | } |
|
1786 | if (callback != null) { |
1831 | if (callback != null) { |
|
1787 | return Utils.getStringFromFile(path, (function(_this) { |
1832 | return Utils.getStringFromFile(path, (function(_this) { |
|
1788 | return function(input) { |
1833 | return function(input) { |
|
1789 | var result; |
1834 | var result; |
|
1790 | result = null; |
1835 | result = null; |
|
1791 | if (input != null) { |
1836 | if (input != null) { |
|
1792 | result = _this.parse(input, exceptionOnInvalidType, objectDecoder); |
1837 | result = _this.parse(input, exceptionOnInvalidType, objectDecoder); |
|
1793 | } |
1838 | } |
|
1794 | callback(result); |
1839 | callback(result); |
|
1795 | }; |
1840 | }; |
|
1796 | })(this)); |
1841 | })(this)); |
|
1797 | } else { |
1842 | } else { |
|
1798 | input = Utils.getStringFromFile(path); |
1843 | input = Utils.getStringFromFile(path); |
|
1799 | if (input != null) { |
1844 | if (input != null) { |
|
1800 | return this.parse(input, exceptionOnInvalidType, objectDecoder); |
1845 | return this.parse(input, exceptionOnInvalidType, objectDecoder); |
|
1801 | } |
1846 | } |
|
1802 | return null; |
1847 | return null; |
|
1803 | } |
1848 | } |
|
1804 | }; |
1849 | }; |
|
1805 | |
1850 | |
|
1806 | Yaml.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) { |
1851 | Yaml.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) { |
|
1807 | var yaml; |
1852 | var yaml; |
|
1808 | if (inline == null) { |
1853 | if (inline == null) { |
|
1809 | inline = 2; |
1854 | inline = 2; |
|
1810 | } |
1855 | } |
|
1811 | if (indent == null) { |
1856 | if (indent == null) { |
|
1812 | indent = 4; |
1857 | indent = 4; |
|
1813 | } |
1858 | } |
|
1814 | if (exceptionOnInvalidType == null) { |
1859 | if (exceptionOnInvalidType == null) { |
|
1815 | exceptionOnInvalidType = false; |
1860 | exceptionOnInvalidType = false; |
|
1816 | } |
1861 | } |
|
1817 | if (objectEncoder == null) { |
1862 | if (objectEncoder == null) { |
|
1818 | objectEncoder = null; |
1863 | objectEncoder = null; |
|
1819 | } |
1864 | } |
|
1820 | yaml = new Dumper(); |
1865 | yaml = new Dumper(); |
|
1821 | yaml.indentation = indent; |
1866 | yaml.indentation = indent; |
|
1822 | return yaml.dump(input, inline, 0, exceptionOnInvalidType, objectEncoder); |
1867 | return yaml.dump(input, inline, 0, exceptionOnInvalidType, objectEncoder); |
|
1823 | }; |
1868 | }; |
|
1824 | |
- | ||
1825 | Yaml.register = function() { |
- | ||
1826 | var require_handler; |
- | ||
1827 | require_handler = function(module, filename) { |
- | ||
1828 | return module.exports = YAML.parseFile(filename); |
- | ||
1829 | }; |
- | ||
1830 | if ((typeof require !== "undefined" && require !== null ? require.extensions : void 0) != null) { |
- | ||
1831 | require.extensions['.yml'] = require_handler; |
- | ||
1832 | return require.extensions['.yaml'] = require_handler; |
- | ||
1833 | } |
- | ||
1834 | }; |
- | ||
1835 | |
1869 | |
|
1836 | Yaml.stringify = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) { |
1870 | Yaml.stringify = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) { |
|
1837 | return this.dump(input, inline, indent, exceptionOnInvalidType, objectEncoder); |
1871 | return this.dump(input, inline, indent, exceptionOnInvalidType, objectEncoder); |
|
1838 | }; |
1872 | }; |
|
1839 | |
1873 | |
|
1840 | Yaml.load = function(path, callback, exceptionOnInvalidType, objectDecoder) { |
1874 | Yaml.load = function(path, callback, exceptionOnInvalidType, objectDecoder) { |
|
1841 | return this.parseFile(path, callback, exceptionOnInvalidType, objectDecoder); |
1875 | return this.parseFile(path, callback, exceptionOnInvalidType, objectDecoder); |
|
1842 | }; |
1876 | }; |
|
1843 | |
1877 | |
|
1844 | return Yaml; |
1878 | return Yaml; |
|
1845 | |
1879 | |
|
1846 | })(); |
1880 | })(); |
|
1847 | |
1881 | |
|
1848 | if (typeof window !== "undefined" && window !== null) { |
1882 | if (typeof window !== "undefined" && window !== null) { |
|
1849 | window.YAML = Yaml; |
1883 | window.YAML = Yaml; |
|
1850 | } |
1884 | } |
|
1851 | |
1885 | |
|
1852 | if (typeof window === "undefined" || window === null) { |
1886 | if (typeof window === "undefined" || window === null) { |
|
1853 | this.YAML = Yaml; |
1887 | this.YAML = Yaml; |
|
1854 | } |
1888 | } |
|
1855 | |
1889 | |
|
1856 | module.exports = Yaml; |
1890 | module.exports = Yaml; |
|
1857 | |
1891 | |
|
1858 | |
1892 | |
|
1859 | },{"./Dumper":1,"./Parser":6,"./Utils":9}]},{},[10]); |
1893 | },{"./Dumper":1,"./Parser":7,"./Utils":10}]},{},[11]); |
|
1860 | |
1894 | |