scratch – Diff between revs 75 and 125
?pathlinks?
Rev 75 | Rev 125 | |||
---|---|---|---|---|
1 | // Generated by CoffeeScript 1.10.0 |
1 | // Generated by CoffeeScript 1.12.4 |
|
2 | var Inline, ParseException, Parser, Pattern, Utils; |
2 | var Inline, ParseException, ParseMore, Parser, Pattern, Utils; |
|
3 | |
3 | |
|
4 | Inline = require('./Inline'); |
4 | Inline = require('./Inline'); |
|
5 | |
5 | |
|
6 | Pattern = require('./Pattern'); |
6 | Pattern = require('./Pattern'); |
|
7 | |
7 | |
|
8 | Utils = require('./Utils'); |
8 | Utils = require('./Utils'); |
|
9 | |
9 | |
|
10 | ParseException = require('./Exception/ParseException'); |
10 | ParseException = require('./Exception/ParseException'); |
|
- | 11 | |
||
- | 12 | ParseMore = require('./Exception/ParseMore'); |
||
11 | |
13 | |
|
12 | Parser = (function() { |
14 | Parser = (function() { |
|
13 | Parser.prototype.PATTERN_FOLDED_SCALAR_ALL = new Pattern('^(?:(?<type>![^\\|>]*)\\s+)?(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
15 | Parser.prototype.PATTERN_FOLDED_SCALAR_ALL = new Pattern('^(?:(?<type>![^\\|>]*)\\s+)?(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
|
14 | |
16 | |
|
15 | Parser.prototype.PATTERN_FOLDED_SCALAR_END = new Pattern('(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
17 | Parser.prototype.PATTERN_FOLDED_SCALAR_END = new Pattern('(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$'); |
|
16 | |
18 | |
|
17 | Parser.prototype.PATTERN_SEQUENCE_ITEM = new Pattern('^\\-((?<leadspaces>\\s+)(?<value>.+?))?\\s*$'); |
19 | Parser.prototype.PATTERN_SEQUENCE_ITEM = new Pattern('^\\-((?<leadspaces>\\s+)(?<value>.+?))?\\s*$'); |
|
18 | |
20 | |
|
19 | Parser.prototype.PATTERN_ANCHOR_VALUE = new Pattern('^&(?<ref>[^ ]+) *(?<value>.*)'); |
21 | Parser.prototype.PATTERN_ANCHOR_VALUE = new Pattern('^&(?<ref>[^ ]+) *(?<value>.*)'); |
|
20 | |
22 | |
|
21 | Parser.prototype.PATTERN_COMPACT_NOTATION = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
23 | Parser.prototype.PATTERN_COMPACT_NOTATION = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
|
22 | |
24 | |
|
23 | Parser.prototype.PATTERN_MAPPING_ITEM = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
25 | Parser.prototype.PATTERN_MAPPING_ITEM = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$'); |
|
24 | |
26 | |
|
25 | Parser.prototype.PATTERN_DECIMAL = new Pattern('\\d+'); |
27 | Parser.prototype.PATTERN_DECIMAL = new Pattern('\\d+'); |
|
26 | |
28 | |
|
27 | Parser.prototype.PATTERN_INDENT_SPACES = new Pattern('^ +'); |
29 | Parser.prototype.PATTERN_INDENT_SPACES = new Pattern('^ +'); |
|
28 | |
30 | |
|
29 | Parser.prototype.PATTERN_TRAILING_LINES = new Pattern('(\n*)$'); |
31 | Parser.prototype.PATTERN_TRAILING_LINES = new Pattern('(\n*)$'); |
|
30 | |
32 | |
|
31 | Parser.prototype.PATTERN_YAML_HEADER = new Pattern('^\\%YAML[: ][\\d\\.]+.*\n'); |
33 | Parser.prototype.PATTERN_YAML_HEADER = new Pattern('^\\%YAML[: ][\\d\\.]+.*\n', 'm'); |
|
32 | |
34 | |
|
33 | Parser.prototype.PATTERN_LEADING_COMMENTS = new Pattern('^(\\#.*?\n)+'); |
35 | Parser.prototype.PATTERN_LEADING_COMMENTS = new Pattern('^(\\#.*?\n)+', 'm'); |
|
34 | |
36 | |
|
35 | Parser.prototype.PATTERN_DOCUMENT_MARKER_START = new Pattern('^\\-\\-\\-.*?\n'); |
37 | Parser.prototype.PATTERN_DOCUMENT_MARKER_START = new Pattern('^\\-\\-\\-.*?\n', 'm'); |
|
36 | |
38 | |
|
37 | Parser.prototype.PATTERN_DOCUMENT_MARKER_END = new Pattern('^\\.\\.\\.\\s*$'); |
39 | Parser.prototype.PATTERN_DOCUMENT_MARKER_END = new Pattern('^\\.\\.\\.\\s*$', 'm'); |
|
38 | |
40 | |
|
39 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION = {}; |
41 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION = {}; |
|
40 | |
42 | |
|
41 | Parser.prototype.CONTEXT_NONE = 0; |
43 | Parser.prototype.CONTEXT_NONE = 0; |
|
42 | |
44 | |
|
43 | Parser.prototype.CONTEXT_SEQUENCE = 1; |
45 | Parser.prototype.CONTEXT_SEQUENCE = 1; |
|
44 | |
46 | |
|
45 | Parser.prototype.CONTEXT_MAPPING = 2; |
47 | Parser.prototype.CONTEXT_MAPPING = 2; |
|
46 | |
48 | |
|
47 | function Parser(offset) { |
49 | function Parser(offset) { |
|
48 | this.offset = offset != null ? offset : 0; |
50 | this.offset = offset != null ? offset : 0; |
|
49 | this.lines = []; |
51 | this.lines = []; |
|
50 | this.currentLineNb = -1; |
52 | this.currentLineNb = -1; |
|
51 | this.currentLine = ''; |
53 | this.currentLine = ''; |
|
52 | this.refs = {}; |
54 | this.refs = {}; |
|
53 | } |
55 | } |
|
54 | |
56 | |
|
55 | Parser.prototype.parse = function(value, exceptionOnInvalidType, objectDecoder) { |
57 | Parser.prototype.parse = function(value, exceptionOnInvalidType, objectDecoder) { |
|
56 | 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; |
58 | var alias, allowOverwrite, block, c, context, data, e, 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; |
|
57 | if (exceptionOnInvalidType == null) { |
59 | if (exceptionOnInvalidType == null) { |
|
58 | exceptionOnInvalidType = false; |
60 | exceptionOnInvalidType = false; |
|
59 | } |
61 | } |
|
60 | if (objectDecoder == null) { |
62 | if (objectDecoder == null) { |
|
61 | objectDecoder = null; |
63 | objectDecoder = null; |
|
62 | } |
64 | } |
|
63 | this.currentLineNb = -1; |
65 | this.currentLineNb = -1; |
|
64 | this.currentLine = ''; |
66 | this.currentLine = ''; |
|
65 | this.lines = this.cleanup(value).split("\n"); |
67 | this.lines = this.cleanup(value).split("\n"); |
|
66 | data = null; |
68 | data = null; |
|
67 | context = this.CONTEXT_NONE; |
69 | context = this.CONTEXT_NONE; |
|
68 | allowOverwrite = false; |
70 | allowOverwrite = false; |
|
69 | while (this.moveToNextLine()) { |
71 | while (this.moveToNextLine()) { |
|
70 | if (this.isCurrentLineEmpty()) { |
72 | if (this.isCurrentLineEmpty()) { |
|
71 | continue; |
73 | continue; |
|
72 | } |
74 | } |
|
73 | if ("\t" === this.currentLine[0]) { |
75 | if ("\t" === this.currentLine[0]) { |
|
74 | throw new ParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine); |
76 | throw new ParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
75 | } |
77 | } |
|
76 | isRef = mergeNode = false; |
78 | isRef = mergeNode = false; |
|
77 | if (values = this.PATTERN_SEQUENCE_ITEM.exec(this.currentLine)) { |
79 | if (values = this.PATTERN_SEQUENCE_ITEM.exec(this.currentLine)) { |
|
78 | if (this.CONTEXT_MAPPING === context) { |
80 | if (this.CONTEXT_MAPPING === context) { |
|
79 | throw new ParseException('You cannot define a sequence item when in a mapping'); |
81 | throw new ParseException('You cannot define a sequence item when in a mapping'); |
|
80 | } |
82 | } |
|
81 | context = this.CONTEXT_SEQUENCE; |
83 | context = this.CONTEXT_SEQUENCE; |
|
82 | if (data == null) { |
84 | if (data == null) { |
|
83 | data = []; |
85 | data = []; |
|
84 | } |
86 | } |
|
85 | if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
87 | if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
|
86 | isRef = matches.ref; |
88 | isRef = matches.ref; |
|
87 | values.value = matches.value; |
89 | values.value = matches.value; |
|
88 | } |
90 | } |
|
89 | if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
91 | if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
|
90 | if (this.currentLineNb < this.lines.length - 1 && !this.isNextLineUnIndentedCollection()) { |
92 | if (this.currentLineNb < this.lines.length - 1 && !this.isNextLineUnIndentedCollection()) { |
|
91 | c = this.getRealCurrentLineNb() + 1; |
93 | c = this.getRealCurrentLineNb() + 1; |
|
92 | parser = new Parser(c); |
94 | parser = new Parser(c); |
|
93 | parser.refs = this.refs; |
95 | parser.refs = this.refs; |
|
94 | data.push(parser.parse(this.getNextEmbedBlock(null, true), exceptionOnInvalidType, objectDecoder)); |
96 | data.push(parser.parse(this.getNextEmbedBlock(null, true), exceptionOnInvalidType, objectDecoder)); |
|
95 | } else { |
97 | } else { |
|
96 | data.push(null); |
98 | data.push(null); |
|
97 | } |
99 | } |
|
98 | } else { |
100 | } else { |
|
99 | if (((ref = values.leadspaces) != null ? ref.length : void 0) && (matches = this.PATTERN_COMPACT_NOTATION.exec(values.value))) { |
101 | if (((ref = values.leadspaces) != null ? ref.length : void 0) && (matches = this.PATTERN_COMPACT_NOTATION.exec(values.value))) { |
|
100 | c = this.getRealCurrentLineNb(); |
102 | c = this.getRealCurrentLineNb(); |
|
101 | parser = new Parser(c); |
103 | parser = new Parser(c); |
|
102 | parser.refs = this.refs; |
104 | parser.refs = this.refs; |
|
103 | block = values.value; |
105 | block = values.value; |
|
104 | indent = this.getCurrentLineIndentation(); |
106 | indent = this.getCurrentLineIndentation(); |
|
105 | if (this.isNextLineIndented(false)) { |
107 | if (this.isNextLineIndented(false)) { |
|
106 | block += "\n" + this.getNextEmbedBlock(indent + values.leadspaces.length + 1, true); |
108 | block += "\n" + this.getNextEmbedBlock(indent + values.leadspaces.length + 1, true); |
|
107 | } |
109 | } |
|
108 | data.push(parser.parse(block, exceptionOnInvalidType, objectDecoder)); |
110 | data.push(parser.parse(block, exceptionOnInvalidType, objectDecoder)); |
|
109 | } else { |
111 | } else { |
|
110 | data.push(this.parseValue(values.value, exceptionOnInvalidType, objectDecoder)); |
112 | data.push(this.parseValue(values.value, exceptionOnInvalidType, objectDecoder)); |
|
111 | } |
113 | } |
|
112 | } |
114 | } |
|
113 | } else if ((values = this.PATTERN_MAPPING_ITEM.exec(this.currentLine)) && values.key.indexOf(' #') === -1) { |
115 | } else if ((values = this.PATTERN_MAPPING_ITEM.exec(this.currentLine)) && values.key.indexOf(' #') === -1) { |
|
114 | if (this.CONTEXT_SEQUENCE === context) { |
116 | if (this.CONTEXT_SEQUENCE === context) { |
|
115 | throw new ParseException('You cannot define a mapping item when in a sequence'); |
117 | throw new ParseException('You cannot define a mapping item when in a sequence'); |
|
116 | } |
118 | } |
|
117 | context = this.CONTEXT_MAPPING; |
119 | context = this.CONTEXT_MAPPING; |
|
118 | if (data == null) { |
120 | if (data == null) { |
|
119 | data = {}; |
121 | data = {}; |
|
120 | } |
122 | } |
|
121 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
123 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
|
122 | try { |
124 | try { |
|
123 | key = Inline.parseScalar(values.key); |
125 | key = Inline.parseScalar(values.key); |
|
124 | } catch (error) { |
126 | } catch (error) { |
|
125 | e = error; |
127 | e = error; |
|
126 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
128 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
127 | e.snippet = this.currentLine; |
129 | e.snippet = this.currentLine; |
|
128 | throw e; |
130 | throw e; |
|
129 | } |
131 | } |
|
130 | if ('<<' === key) { |
132 | if ('<<' === key) { |
|
131 | mergeNode = true; |
133 | mergeNode = true; |
|
132 | allowOverwrite = true; |
134 | allowOverwrite = true; |
|
133 | if (((ref1 = values.value) != null ? ref1.indexOf('*') : void 0) === 0) { |
135 | if (((ref1 = values.value) != null ? ref1.indexOf('*') : void 0) === 0) { |
|
134 | refName = values.value.slice(1); |
136 | refName = values.value.slice(1); |
|
135 | if (this.refs[refName] == null) { |
137 | if (this.refs[refName] == null) { |
|
136 | throw new ParseException('Reference "' + refName + '" does not exist.', this.getRealCurrentLineNb() + 1, this.currentLine); |
138 | throw new ParseException('Reference "' + refName + '" does not exist.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
137 | } |
139 | } |
|
138 | refValue = this.refs[refName]; |
140 | refValue = this.refs[refName]; |
|
139 | if (typeof refValue !== 'object') { |
141 | if (typeof refValue !== 'object') { |
|
140 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
142 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
141 | } |
143 | } |
|
142 | if (refValue instanceof Array) { |
144 | if (refValue instanceof Array) { |
|
143 | for (i = j = 0, len = refValue.length; j < len; i = ++j) { |
145 | for (i = j = 0, len = refValue.length; j < len; i = ++j) { |
|
144 | value = refValue[i]; |
146 | value = refValue[i]; |
|
145 | if (data[name = String(i)] == null) { |
147 | if (data[name = String(i)] == null) { |
|
146 | data[name] = value; |
148 | data[name] = value; |
|
147 | } |
149 | } |
|
148 | } |
150 | } |
|
149 | } else { |
151 | } else { |
|
150 | for (key in refValue) { |
152 | for (key in refValue) { |
|
151 | value = refValue[key]; |
153 | value = refValue[key]; |
|
152 | if (data[key] == null) { |
154 | if (data[key] == null) { |
|
153 | data[key] = value; |
155 | data[key] = value; |
|
154 | } |
156 | } |
|
155 | } |
157 | } |
|
156 | } |
158 | } |
|
157 | } else { |
159 | } else { |
|
158 | if ((values.value != null) && values.value !== '') { |
160 | if ((values.value != null) && values.value !== '') { |
|
159 | value = values.value; |
161 | value = values.value; |
|
160 | } else { |
162 | } else { |
|
161 | value = this.getNextEmbedBlock(); |
163 | value = this.getNextEmbedBlock(); |
|
162 | } |
164 | } |
|
163 | c = this.getRealCurrentLineNb() + 1; |
165 | c = this.getRealCurrentLineNb() + 1; |
|
164 | parser = new Parser(c); |
166 | parser = new Parser(c); |
|
165 | parser.refs = this.refs; |
167 | parser.refs = this.refs; |
|
166 | parsed = parser.parse(value, exceptionOnInvalidType); |
168 | parsed = parser.parse(value, exceptionOnInvalidType); |
|
167 | if (typeof parsed !== 'object') { |
169 | if (typeof parsed !== 'object') { |
|
168 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
170 | throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
169 | } |
171 | } |
|
170 | if (parsed instanceof Array) { |
172 | if (parsed instanceof Array) { |
|
171 | for (l = 0, len1 = parsed.length; l < len1; l++) { |
173 | for (l = 0, len1 = parsed.length; l < len1; l++) { |
|
172 | parsedItem = parsed[l]; |
174 | parsedItem = parsed[l]; |
|
173 | if (typeof parsedItem !== 'object') { |
175 | if (typeof parsedItem !== 'object') { |
|
174 | throw new ParseException('Merge items must be objects.', this.getRealCurrentLineNb() + 1, parsedItem); |
176 | throw new ParseException('Merge items must be objects.', this.getRealCurrentLineNb() + 1, parsedItem); |
|
175 | } |
177 | } |
|
176 | if (parsedItem instanceof Array) { |
178 | if (parsedItem instanceof Array) { |
|
177 | for (i = m = 0, len2 = parsedItem.length; m < len2; i = ++m) { |
179 | for (i = m = 0, len2 = parsedItem.length; m < len2; i = ++m) { |
|
178 | value = parsedItem[i]; |
180 | value = parsedItem[i]; |
|
179 | k = String(i); |
181 | k = String(i); |
|
180 | if (!data.hasOwnProperty(k)) { |
182 | if (!data.hasOwnProperty(k)) { |
|
181 | data[k] = value; |
183 | data[k] = value; |
|
182 | } |
184 | } |
|
183 | } |
185 | } |
|
184 | } else { |
186 | } else { |
|
185 | for (key in parsedItem) { |
187 | for (key in parsedItem) { |
|
186 | value = parsedItem[key]; |
188 | value = parsedItem[key]; |
|
187 | if (!data.hasOwnProperty(key)) { |
189 | if (!data.hasOwnProperty(key)) { |
|
188 | data[key] = value; |
190 | data[key] = value; |
|
189 | } |
191 | } |
|
190 | } |
192 | } |
|
191 | } |
193 | } |
|
192 | } |
194 | } |
|
193 | } else { |
195 | } else { |
|
194 | for (key in parsed) { |
196 | for (key in parsed) { |
|
195 | value = parsed[key]; |
197 | value = parsed[key]; |
|
196 | if (!data.hasOwnProperty(key)) { |
198 | if (!data.hasOwnProperty(key)) { |
|
197 | data[key] = value; |
199 | data[key] = value; |
|
198 | } |
200 | } |
|
199 | } |
201 | } |
|
200 | } |
202 | } |
|
201 | } |
203 | } |
|
202 | } else if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
204 | } else if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) { |
|
203 | isRef = matches.ref; |
205 | isRef = matches.ref; |
|
204 | values.value = matches.value; |
206 | values.value = matches.value; |
|
205 | } |
207 | } |
|
206 | if (mergeNode) { |
208 | if (mergeNode) { |
|
207 | |
209 | |
|
208 | } else if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
210 | } else if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) { |
|
209 | if (!(this.isNextLineIndented()) && !(this.isNextLineUnIndentedCollection())) { |
211 | if (!(this.isNextLineIndented()) && !(this.isNextLineUnIndentedCollection())) { |
|
210 | if (allowOverwrite || data[key] === void 0) { |
212 | if (allowOverwrite || data[key] === void 0) { |
|
211 | data[key] = null; |
213 | data[key] = null; |
|
212 | } |
214 | } |
|
213 | } else { |
215 | } else { |
|
214 | c = this.getRealCurrentLineNb() + 1; |
216 | c = this.getRealCurrentLineNb() + 1; |
|
215 | parser = new Parser(c); |
217 | parser = new Parser(c); |
|
216 | parser.refs = this.refs; |
218 | parser.refs = this.refs; |
|
217 | val = parser.parse(this.getNextEmbedBlock(), exceptionOnInvalidType, objectDecoder); |
219 | val = parser.parse(this.getNextEmbedBlock(), exceptionOnInvalidType, objectDecoder); |
|
218 | if (allowOverwrite || data[key] === void 0) { |
220 | if (allowOverwrite || data[key] === void 0) { |
|
219 | data[key] = val; |
221 | data[key] = val; |
|
220 | } |
222 | } |
|
221 | } |
223 | } |
|
222 | } else { |
224 | } else { |
|
223 | val = this.parseValue(values.value, exceptionOnInvalidType, objectDecoder); |
225 | val = this.parseValue(values.value, exceptionOnInvalidType, objectDecoder); |
|
224 | if (allowOverwrite || data[key] === void 0) { |
226 | if (allowOverwrite || data[key] === void 0) { |
|
225 | data[key] = val; |
227 | data[key] = val; |
|
226 | } |
228 | } |
|
227 | } |
229 | } |
|
228 | } else { |
230 | } else { |
|
229 | lineCount = this.lines.length; |
231 | lineCount = this.lines.length; |
|
230 | if (1 === lineCount || (2 === lineCount && Utils.isEmpty(this.lines[1]))) { |
232 | if (1 === lineCount || (2 === lineCount && Utils.isEmpty(this.lines[1]))) { |
|
231 | try { |
233 | try { |
|
232 | value = Inline.parse(this.lines[0], exceptionOnInvalidType, objectDecoder); |
234 | value = Inline.parse(this.lines[0], exceptionOnInvalidType, objectDecoder); |
|
233 | } catch (error1) { |
235 | } catch (error) { |
|
234 | e = error1; |
236 | e = error; |
|
235 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
237 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
236 | e.snippet = this.currentLine; |
238 | e.snippet = this.currentLine; |
|
237 | throw e; |
239 | throw e; |
|
238 | } |
240 | } |
|
239 | if (typeof value === 'object') { |
241 | if (typeof value === 'object') { |
|
240 | if (value instanceof Array) { |
242 | if (value instanceof Array) { |
|
241 | first = value[0]; |
243 | first = value[0]; |
|
242 | } else { |
244 | } else { |
|
243 | for (key in value) { |
245 | for (key in value) { |
|
244 | first = value[key]; |
246 | first = value[key]; |
|
245 | break; |
247 | break; |
|
246 | } |
248 | } |
|
247 | } |
249 | } |
|
248 | if (typeof first === 'string' && first.indexOf('*') === 0) { |
250 | if (typeof first === 'string' && first.indexOf('*') === 0) { |
|
249 | data = []; |
251 | data = []; |
|
250 | for (n = 0, len3 = value.length; n < len3; n++) { |
252 | for (n = 0, len3 = value.length; n < len3; n++) { |
|
251 | alias = value[n]; |
253 | alias = value[n]; |
|
252 | data.push(this.refs[alias.slice(1)]); |
254 | data.push(this.refs[alias.slice(1)]); |
|
253 | } |
255 | } |
|
254 | value = data; |
256 | value = data; |
|
255 | } |
257 | } |
|
256 | } |
258 | } |
|
257 | return value; |
259 | return value; |
|
258 | } else if ((ref2 = Utils.ltrim(value).charAt(0)) === '[' || ref2 === '{') { |
260 | } else if ((ref2 = Utils.ltrim(value).charAt(0)) === '[' || ref2 === '{') { |
|
259 | try { |
261 | try { |
|
260 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
262 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
|
261 | } catch (error2) { |
263 | } catch (error) { |
|
262 | e = error2; |
264 | e = error; |
|
263 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
265 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
264 | e.snippet = this.currentLine; |
266 | e.snippet = this.currentLine; |
|
265 | throw e; |
267 | throw e; |
|
266 | } |
268 | } |
|
267 | } |
269 | } |
|
268 | throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine); |
270 | throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
269 | } |
271 | } |
|
270 | if (isRef) { |
272 | if (isRef) { |
|
271 | if (data instanceof Array) { |
273 | if (data instanceof Array) { |
|
272 | this.refs[isRef] = data[data.length - 1]; |
274 | this.refs[isRef] = data[data.length - 1]; |
|
273 | } else { |
275 | } else { |
|
274 | lastKey = null; |
276 | lastKey = null; |
|
275 | for (key in data) { |
277 | for (key in data) { |
|
276 | lastKey = key; |
278 | lastKey = key; |
|
277 | } |
279 | } |
|
278 | this.refs[isRef] = data[lastKey]; |
280 | this.refs[isRef] = data[lastKey]; |
|
279 | } |
281 | } |
|
280 | } |
282 | } |
|
281 | } |
283 | } |
|
282 | if (Utils.isEmpty(data)) { |
284 | if (Utils.isEmpty(data)) { |
|
283 | return null; |
285 | return null; |
|
284 | } else { |
286 | } else { |
|
285 | return data; |
287 | return data; |
|
286 | } |
288 | } |
|
287 | }; |
289 | }; |
|
288 | |
290 | |
|
289 | Parser.prototype.getRealCurrentLineNb = function() { |
291 | Parser.prototype.getRealCurrentLineNb = function() { |
|
290 | return this.currentLineNb + this.offset; |
292 | return this.currentLineNb + this.offset; |
|
291 | }; |
293 | }; |
|
292 | |
294 | |
|
293 | Parser.prototype.getCurrentLineIndentation = function() { |
295 | Parser.prototype.getCurrentLineIndentation = function() { |
|
294 | return this.currentLine.length - Utils.ltrim(this.currentLine, ' ').length; |
296 | return this.currentLine.length - Utils.ltrim(this.currentLine, ' ').length; |
|
295 | }; |
297 | }; |
|
296 | |
298 | |
|
297 | Parser.prototype.getNextEmbedBlock = function(indentation, includeUnindentedCollection) { |
299 | Parser.prototype.getNextEmbedBlock = function(indentation, includeUnindentedCollection) { |
|
298 | var data, indent, isItUnindentedCollection, newIndent, removeComments, removeCommentsPattern, unindentedEmbedBlock; |
300 | var data, indent, isItUnindentedCollection, newIndent, removeComments, removeCommentsPattern, unindentedEmbedBlock; |
|
299 | if (indentation == null) { |
301 | if (indentation == null) { |
|
300 | indentation = null; |
302 | indentation = null; |
|
301 | } |
303 | } |
|
302 | if (includeUnindentedCollection == null) { |
304 | if (includeUnindentedCollection == null) { |
|
303 | includeUnindentedCollection = false; |
305 | includeUnindentedCollection = false; |
|
304 | } |
306 | } |
|
305 | this.moveToNextLine(); |
307 | this.moveToNextLine(); |
|
306 | if (indentation == null) { |
308 | if (indentation == null) { |
|
307 | newIndent = this.getCurrentLineIndentation(); |
309 | newIndent = this.getCurrentLineIndentation(); |
|
308 | unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine); |
310 | unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine); |
|
309 | if (!(this.isCurrentLineEmpty()) && 0 === newIndent && !unindentedEmbedBlock) { |
311 | if (!(this.isCurrentLineEmpty()) && 0 === newIndent && !unindentedEmbedBlock) { |
|
310 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
312 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
311 | } |
313 | } |
|
312 | } else { |
314 | } else { |
|
313 | newIndent = indentation; |
315 | newIndent = indentation; |
|
314 | } |
316 | } |
|
315 | data = [this.currentLine.slice(newIndent)]; |
317 | data = [this.currentLine.slice(newIndent)]; |
|
316 | if (!includeUnindentedCollection) { |
318 | if (!includeUnindentedCollection) { |
|
317 | isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine); |
319 | isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine); |
|
318 | } |
320 | } |
|
319 | removeCommentsPattern = this.PATTERN_FOLDED_SCALAR_END; |
321 | removeCommentsPattern = this.PATTERN_FOLDED_SCALAR_END; |
|
320 | removeComments = !removeCommentsPattern.test(this.currentLine); |
322 | removeComments = !removeCommentsPattern.test(this.currentLine); |
|
321 | while (this.moveToNextLine()) { |
323 | while (this.moveToNextLine()) { |
|
322 | indent = this.getCurrentLineIndentation(); |
324 | indent = this.getCurrentLineIndentation(); |
|
323 | if (indent === newIndent) { |
325 | if (indent === newIndent) { |
|
324 | removeComments = !removeCommentsPattern.test(this.currentLine); |
326 | removeComments = !removeCommentsPattern.test(this.currentLine); |
|
325 | } |
327 | } |
|
326 | if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine) && indent === newIndent) { |
- | ||
327 | this.moveToPreviousLine(); |
328 | if (removeComments && this.isCurrentLineComment()) { |
|
328 | break; |
329 | continue; |
|
329 | } |
330 | } |
|
330 | if (this.isCurrentLineBlank()) { |
331 | if (this.isCurrentLineBlank()) { |
|
331 | data.push(this.currentLine.slice(newIndent)); |
332 | data.push(this.currentLine.slice(newIndent)); |
|
332 | continue; |
333 | continue; |
|
333 | } |
334 | } |
|
334 | if (removeComments && this.isCurrentLineComment()) { |
335 | if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine) && indent === newIndent) { |
|
335 | if (indent === newIndent) { |
336 | this.moveToPreviousLine(); |
|
336 | continue; |
- | ||
337 | } |
337 | break; |
|
338 | } |
338 | } |
|
339 | if (indent >= newIndent) { |
339 | if (indent >= newIndent) { |
|
340 | data.push(this.currentLine.slice(newIndent)); |
340 | data.push(this.currentLine.slice(newIndent)); |
|
341 | } else if (Utils.ltrim(this.currentLine).charAt(0) === '#') { |
341 | } else if (Utils.ltrim(this.currentLine).charAt(0) === '#') { |
|
342 | |
342 | |
|
343 | } else if (0 === indent) { |
343 | } else if (0 === indent) { |
|
344 | this.moveToPreviousLine(); |
344 | this.moveToPreviousLine(); |
|
345 | break; |
345 | break; |
|
346 | } else { |
346 | } else { |
|
347 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
347 | throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine); |
|
348 | } |
348 | } |
|
349 | } |
349 | } |
|
350 | return data.join("\n"); |
350 | return data.join("\n"); |
|
351 | }; |
351 | }; |
|
352 | |
352 | |
|
353 | Parser.prototype.moveToNextLine = function() { |
353 | Parser.prototype.moveToNextLine = function() { |
|
354 | if (this.currentLineNb >= this.lines.length - 1) { |
354 | if (this.currentLineNb >= this.lines.length - 1) { |
|
355 | return false; |
355 | return false; |
|
356 | } |
356 | } |
|
357 | this.currentLine = this.lines[++this.currentLineNb]; |
357 | this.currentLine = this.lines[++this.currentLineNb]; |
|
358 | return true; |
358 | return true; |
|
359 | }; |
359 | }; |
|
360 | |
360 | |
|
361 | Parser.prototype.moveToPreviousLine = function() { |
361 | Parser.prototype.moveToPreviousLine = function() { |
|
362 | this.currentLine = this.lines[--this.currentLineNb]; |
362 | this.currentLine = this.lines[--this.currentLineNb]; |
|
363 | }; |
363 | }; |
|
364 | |
364 | |
|
365 | Parser.prototype.parseValue = function(value, exceptionOnInvalidType, objectDecoder) { |
365 | Parser.prototype.parseValue = function(value, exceptionOnInvalidType, objectDecoder) { |
|
366 | var e, error, error1, foldedIndent, matches, modifiers, pos, ref, ref1, val; |
366 | var e, foldedIndent, matches, modifiers, pos, ref, ref1, val; |
|
367 | if (0 === value.indexOf('*')) { |
367 | if (0 === value.indexOf('*')) { |
|
368 | pos = value.indexOf('#'); |
368 | pos = value.indexOf('#'); |
|
369 | if (pos !== -1) { |
369 | if (pos !== -1) { |
|
370 | value = value.substr(1, pos - 2); |
370 | value = value.substr(1, pos - 2); |
|
371 | } else { |
371 | } else { |
|
372 | value = value.slice(1); |
372 | value = value.slice(1); |
|
373 | } |
373 | } |
|
374 | if (this.refs[value] === void 0) { |
374 | if (this.refs[value] === void 0) { |
|
375 | throw new ParseException('Reference "' + value + '" does not exist.', this.currentLine); |
375 | throw new ParseException('Reference "' + value + '" does not exist.', this.currentLine); |
|
376 | } |
376 | } |
|
377 | return this.refs[value]; |
377 | return this.refs[value]; |
|
378 | } |
378 | } |
|
379 | if (matches = this.PATTERN_FOLDED_SCALAR_ALL.exec(value)) { |
379 | if (matches = this.PATTERN_FOLDED_SCALAR_ALL.exec(value)) { |
|
380 | modifiers = (ref = matches.modifiers) != null ? ref : ''; |
380 | modifiers = (ref = matches.modifiers) != null ? ref : ''; |
|
381 | foldedIndent = Math.abs(parseInt(modifiers)); |
381 | foldedIndent = Math.abs(parseInt(modifiers)); |
|
382 | if (isNaN(foldedIndent)) { |
382 | if (isNaN(foldedIndent)) { |
|
383 | foldedIndent = 0; |
383 | foldedIndent = 0; |
|
384 | } |
384 | } |
|
385 | val = this.parseFoldedScalar(matches.separator, this.PATTERN_DECIMAL.replace(modifiers, ''), foldedIndent); |
385 | val = this.parseFoldedScalar(matches.separator, this.PATTERN_DECIMAL.replace(modifiers, ''), foldedIndent); |
|
386 | if (matches.type != null) { |
386 | if (matches.type != null) { |
|
387 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
387 | Inline.configure(exceptionOnInvalidType, objectDecoder); |
|
388 | return Inline.parseScalar(matches.type + ' ' + val); |
388 | return Inline.parseScalar(matches.type + ' ' + val); |
|
389 | } else { |
389 | } else { |
|
390 | return val; |
390 | return val; |
|
391 | } |
391 | } |
|
392 | } |
392 | } |
|
393 | try { |
- | ||
394 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
393 | if ((ref1 = value.charAt(0)) === '[' || ref1 === '{' || ref1 === '"' || ref1 === "'") { |
|
395 | } catch (error) { |
394 | while (true) { |
|
396 | e = error; |
- | ||
397 | if (((ref1 = value.charAt(0)) === '[' || ref1 === '{') && e instanceof ParseException && this.isNextLineIndented()) { |
- | ||
398 | value += "\n" + this.getNextEmbedBlock(); |
- | ||
399 | try { |
395 | try { |
|
400 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
396 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
|
401 | } catch (error1) { |
397 | } catch (error) { |
|
402 | e = error1; |
398 | e = error; |
|
- | 399 | if (e instanceof ParseMore && this.moveToNextLine()) { |
||
- | 400 | value += "\n" + Utils.trim(this.currentLine, ' '); |
||
- | 401 | } else { |
||
403 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
402 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
|
404 | e.snippet = this.currentLine; |
403 | e.snippet = this.currentLine; |
|
405 | throw e; |
404 | throw e; |
|
- | 405 | } |
||
406 | } |
406 | } |
|
407 | } else { |
- | ||
408 | e.parsedLine = this.getRealCurrentLineNb() + 1; |
- | ||
409 | e.snippet = this.currentLine; |
- | ||
410 | throw e; |
- | ||
411 | } |
407 | } |
|
- | 408 | } else { |
||
- | 409 | if (this.isNextLineIndented()) { |
||
- | 410 | value += "\n" + this.getNextEmbedBlock(); |
||
- | 411 | } |
||
- | 412 | return Inline.parse(value, exceptionOnInvalidType, objectDecoder); |
||
412 | } |
413 | } |
|
413 | }; |
414 | }; |
|
414 | |
415 | |
|
415 | Parser.prototype.parseFoldedScalar = function(separator, indicator, indentation) { |
416 | Parser.prototype.parseFoldedScalar = function(separator, indicator, indentation) { |
|
416 | var isCurrentLineBlank, j, len, line, matches, newText, notEOF, pattern, ref, text; |
417 | var isCurrentLineBlank, j, len, line, matches, newText, notEOF, pattern, ref, text; |
|
417 | if (indicator == null) { |
418 | if (indicator == null) { |
|
418 | indicator = ''; |
419 | indicator = ''; |
|
419 | } |
420 | } |
|
420 | if (indentation == null) { |
421 | if (indentation == null) { |
|
421 | indentation = 0; |
422 | indentation = 0; |
|
422 | } |
423 | } |
|
423 | notEOF = this.moveToNextLine(); |
424 | notEOF = this.moveToNextLine(); |
|
424 | if (!notEOF) { |
425 | if (!notEOF) { |
|
425 | return ''; |
426 | return ''; |
|
426 | } |
427 | } |
|
427 | isCurrentLineBlank = this.isCurrentLineBlank(); |
428 | isCurrentLineBlank = this.isCurrentLineBlank(); |
|
428 | text = ''; |
429 | text = ''; |
|
429 | while (notEOF && isCurrentLineBlank) { |
430 | while (notEOF && isCurrentLineBlank) { |
|
430 | if (notEOF = this.moveToNextLine()) { |
431 | if (notEOF = this.moveToNextLine()) { |
|
431 | text += "\n"; |
432 | text += "\n"; |
|
432 | isCurrentLineBlank = this.isCurrentLineBlank(); |
433 | isCurrentLineBlank = this.isCurrentLineBlank(); |
|
433 | } |
434 | } |
|
434 | } |
435 | } |
|
435 | if (0 === indentation) { |
436 | if (0 === indentation) { |
|
436 | if (matches = this.PATTERN_INDENT_SPACES.exec(this.currentLine)) { |
437 | if (matches = this.PATTERN_INDENT_SPACES.exec(this.currentLine)) { |
|
437 | indentation = matches[0].length; |
438 | indentation = matches[0].length; |
|
438 | } |
439 | } |
|
439 | } |
440 | } |
|
440 | if (indentation > 0) { |
441 | if (indentation > 0) { |
|
441 | pattern = this.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation]; |
442 | pattern = this.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation]; |
|
442 | if (pattern == null) { |
443 | if (pattern == null) { |
|
443 | pattern = new Pattern('^ {' + indentation + '}(.*)$'); |
444 | pattern = new Pattern('^ {' + indentation + '}(.*)$'); |
|
444 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation] = pattern; |
445 | Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation] = pattern; |
|
445 | } |
446 | } |
|
446 | while (notEOF && (isCurrentLineBlank || (matches = pattern.exec(this.currentLine)))) { |
447 | while (notEOF && (isCurrentLineBlank || (matches = pattern.exec(this.currentLine)))) { |
|
447 | if (isCurrentLineBlank) { |
448 | if (isCurrentLineBlank) { |
|
448 | text += this.currentLine.slice(indentation); |
449 | text += this.currentLine.slice(indentation); |
|
449 | } else { |
450 | } else { |
|
450 | text += matches[1]; |
451 | text += matches[1]; |
|
451 | } |
452 | } |
|
452 | if (notEOF = this.moveToNextLine()) { |
453 | if (notEOF = this.moveToNextLine()) { |
|
453 | text += "\n"; |
454 | text += "\n"; |
|
454 | isCurrentLineBlank = this.isCurrentLineBlank(); |
455 | isCurrentLineBlank = this.isCurrentLineBlank(); |
|
455 | } |
456 | } |
|
456 | } |
457 | } |
|
457 | } else if (notEOF) { |
458 | } else if (notEOF) { |
|
458 | text += "\n"; |
459 | text += "\n"; |
|
459 | } |
460 | } |
|
460 | if (notEOF) { |
461 | if (notEOF) { |
|
461 | this.moveToPreviousLine(); |
462 | this.moveToPreviousLine(); |
|
462 | } |
463 | } |
|
463 | if ('>' === separator) { |
464 | if ('>' === separator) { |
|
464 | newText = ''; |
465 | newText = ''; |
|
465 | ref = text.split("\n"); |
466 | ref = text.split("\n"); |
|
466 | for (j = 0, len = ref.length; j < len; j++) { |
467 | for (j = 0, len = ref.length; j < len; j++) { |
|
467 | line = ref[j]; |
468 | line = ref[j]; |
|
468 | if (line.length === 0 || line.charAt(0) === ' ') { |
469 | if (line.length === 0 || line.charAt(0) === ' ') { |
|
469 | newText = Utils.rtrim(newText, ' ') + line + "\n"; |
470 | newText = Utils.rtrim(newText, ' ') + line + "\n"; |
|
470 | } else { |
471 | } else { |
|
471 | newText += line + ' '; |
472 | newText += line + ' '; |
|
472 | } |
473 | } |
|
473 | } |
474 | } |
|
474 | text = newText; |
475 | text = newText; |
|
475 | } |
476 | } |
|
476 | if ('+' !== indicator) { |
477 | if ('+' !== indicator) { |
|
477 | text = Utils.rtrim(text); |
478 | text = Utils.rtrim(text); |
|
478 | } |
479 | } |
|
479 | if ('' === indicator) { |
480 | if ('' === indicator) { |
|
480 | text = this.PATTERN_TRAILING_LINES.replace(text, "\n"); |
481 | text = this.PATTERN_TRAILING_LINES.replace(text, "\n"); |
|
481 | } else if ('-' === indicator) { |
482 | } else if ('-' === indicator) { |
|
482 | text = this.PATTERN_TRAILING_LINES.replace(text, ''); |
483 | text = this.PATTERN_TRAILING_LINES.replace(text, ''); |
|
483 | } |
484 | } |
|
484 | return text; |
485 | return text; |
|
485 | }; |
486 | }; |
|
486 | |
487 | |
|
487 | Parser.prototype.isNextLineIndented = function(ignoreComments) { |
488 | Parser.prototype.isNextLineIndented = function(ignoreComments) { |
|
488 | var EOF, currentIndentation, ret; |
489 | var EOF, currentIndentation, ret; |
|
489 | if (ignoreComments == null) { |
490 | if (ignoreComments == null) { |
|
490 | ignoreComments = true; |
491 | ignoreComments = true; |
|
491 | } |
492 | } |
|
492 | currentIndentation = this.getCurrentLineIndentation(); |
493 | currentIndentation = this.getCurrentLineIndentation(); |
|
493 | EOF = !this.moveToNextLine(); |
494 | EOF = !this.moveToNextLine(); |
|
494 | if (ignoreComments) { |
495 | if (ignoreComments) { |
|
495 | while (!EOF && this.isCurrentLineEmpty()) { |
496 | while (!EOF && this.isCurrentLineEmpty()) { |
|
496 | EOF = !this.moveToNextLine(); |
497 | EOF = !this.moveToNextLine(); |
|
497 | } |
498 | } |
|
498 | } else { |
499 | } else { |
|
499 | while (!EOF && this.isCurrentLineBlank()) { |
500 | while (!EOF && this.isCurrentLineBlank()) { |
|
500 | EOF = !this.moveToNextLine(); |
501 | EOF = !this.moveToNextLine(); |
|
501 | } |
502 | } |
|
502 | } |
503 | } |
|
503 | if (EOF) { |
504 | if (EOF) { |
|
504 | return false; |
505 | return false; |
|
505 | } |
506 | } |
|
506 | ret = false; |
507 | ret = false; |
|
507 | if (this.getCurrentLineIndentation() > currentIndentation) { |
508 | if (this.getCurrentLineIndentation() > currentIndentation) { |
|
508 | ret = true; |
509 | ret = true; |
|
509 | } |
510 | } |
|
510 | this.moveToPreviousLine(); |
511 | this.moveToPreviousLine(); |
|
511 | return ret; |
512 | return ret; |
|
512 | }; |
513 | }; |
|
513 | |
514 | |
|
514 | Parser.prototype.isCurrentLineEmpty = function() { |
515 | Parser.prototype.isCurrentLineEmpty = function() { |
|
515 | var trimmedLine; |
516 | var trimmedLine; |
|
516 | trimmedLine = Utils.trim(this.currentLine, ' '); |
517 | trimmedLine = Utils.trim(this.currentLine, ' '); |
|
517 | return trimmedLine.length === 0 || trimmedLine.charAt(0) === '#'; |
518 | return trimmedLine.length === 0 || trimmedLine.charAt(0) === '#'; |
|
518 | }; |
519 | }; |
|
519 | |
520 | |
|
520 | Parser.prototype.isCurrentLineBlank = function() { |
521 | Parser.prototype.isCurrentLineBlank = function() { |
|
521 | return '' === Utils.trim(this.currentLine, ' '); |
522 | return '' === Utils.trim(this.currentLine, ' '); |
|
522 | }; |
523 | }; |
|
523 | |
524 | |
|
524 | Parser.prototype.isCurrentLineComment = function() { |
525 | Parser.prototype.isCurrentLineComment = function() { |
|
525 | var ltrimmedLine; |
526 | var ltrimmedLine; |
|
526 | ltrimmedLine = Utils.ltrim(this.currentLine, ' '); |
527 | ltrimmedLine = Utils.ltrim(this.currentLine, ' '); |
|
527 | return ltrimmedLine.charAt(0) === '#'; |
528 | return ltrimmedLine.charAt(0) === '#'; |
|
528 | }; |
529 | }; |
|
529 | |
530 | |
|
530 | Parser.prototype.cleanup = function(value) { |
531 | Parser.prototype.cleanup = function(value) { |
|
531 | var count, i, indent, j, l, len, len1, line, lines, ref, ref1, ref2, smallestIndent, trimmedValue; |
532 | var count, i, indent, j, l, len, len1, line, lines, ref, ref1, ref2, smallestIndent, trimmedValue; |
|
532 | if (value.indexOf("\r") !== -1) { |
533 | if (value.indexOf("\r") !== -1) { |
|
533 | value = value.split("\r\n").join("\n").split("\r").join("\n"); |
534 | value = value.split("\r\n").join("\n").split("\r").join("\n"); |
|
534 | } |
535 | } |
|
535 | count = 0; |
536 | count = 0; |
|
536 | ref = this.PATTERN_YAML_HEADER.replaceAll(value, ''), value = ref[0], count = ref[1]; |
537 | ref = this.PATTERN_YAML_HEADER.replaceAll(value, ''), value = ref[0], count = ref[1]; |
|
537 | this.offset += count; |
538 | this.offset += count; |
|
538 | ref1 = this.PATTERN_LEADING_COMMENTS.replaceAll(value, '', 1), trimmedValue = ref1[0], count = ref1[1]; |
539 | ref1 = this.PATTERN_LEADING_COMMENTS.replaceAll(value, '', 1), trimmedValue = ref1[0], count = ref1[1]; |
|
539 | if (count === 1) { |
540 | if (count === 1) { |
|
540 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
541 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
|
541 | value = trimmedValue; |
542 | value = trimmedValue; |
|
542 | } |
543 | } |
|
543 | ref2 = this.PATTERN_DOCUMENT_MARKER_START.replaceAll(value, '', 1), trimmedValue = ref2[0], count = ref2[1]; |
544 | ref2 = this.PATTERN_DOCUMENT_MARKER_START.replaceAll(value, '', 1), trimmedValue = ref2[0], count = ref2[1]; |
|
544 | if (count === 1) { |
545 | if (count === 1) { |
|
545 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
546 | this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n"); |
|
546 | value = trimmedValue; |
547 | value = trimmedValue; |
|
547 | value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, ''); |
548 | value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, ''); |
|
548 | } |
549 | } |
|
549 | lines = value.split("\n"); |
550 | lines = value.split("\n"); |
|
550 | smallestIndent = -1; |
551 | smallestIndent = -1; |
|
551 | for (j = 0, len = lines.length; j < len; j++) { |
552 | for (j = 0, len = lines.length; j < len; j++) { |
|
552 | line = lines[j]; |
553 | line = lines[j]; |
|
553 | if (Utils.trim(line, ' ').length === 0) { |
554 | if (Utils.trim(line, ' ').length === 0) { |
|
554 | continue; |
555 | continue; |
|
555 | } |
556 | } |
|
556 | indent = line.length - Utils.ltrim(line).length; |
557 | indent = line.length - Utils.ltrim(line).length; |
|
557 | if (smallestIndent === -1 || indent < smallestIndent) { |
558 | if (smallestIndent === -1 || indent < smallestIndent) { |
|
558 | smallestIndent = indent; |
559 | smallestIndent = indent; |
|
559 | } |
560 | } |
|
560 | } |
561 | } |
|
561 | if (smallestIndent > 0) { |
562 | if (smallestIndent > 0) { |
|
562 | for (i = l = 0, len1 = lines.length; l < len1; i = ++l) { |
563 | for (i = l = 0, len1 = lines.length; l < len1; i = ++l) { |
|
563 | line = lines[i]; |
564 | line = lines[i]; |
|
564 | lines[i] = line.slice(smallestIndent); |
565 | lines[i] = line.slice(smallestIndent); |
|
565 | } |
566 | } |
|
566 | value = lines.join("\n"); |
567 | value = lines.join("\n"); |
|
567 | } |
568 | } |
|
568 | return value; |
569 | return value; |
|
569 | }; |
570 | }; |
|
570 | |
571 | |
|
571 | Parser.prototype.isNextLineUnIndentedCollection = function(currentIndentation) { |
572 | Parser.prototype.isNextLineUnIndentedCollection = function(currentIndentation) { |
|
572 | var notEOF, ret; |
573 | var notEOF, ret; |
|
573 | if (currentIndentation == null) { |
574 | if (currentIndentation == null) { |
|
574 | currentIndentation = null; |
575 | currentIndentation = null; |
|
575 | } |
576 | } |
|
576 | if (currentIndentation == null) { |
577 | if (currentIndentation == null) { |
|
577 | currentIndentation = this.getCurrentLineIndentation(); |
578 | currentIndentation = this.getCurrentLineIndentation(); |
|
578 | } |
579 | } |
|
579 | notEOF = this.moveToNextLine(); |
580 | notEOF = this.moveToNextLine(); |
|
580 | while (notEOF && this.isCurrentLineEmpty()) { |
581 | while (notEOF && this.isCurrentLineEmpty()) { |
|
581 | notEOF = this.moveToNextLine(); |
582 | notEOF = this.moveToNextLine(); |
|
582 | } |
583 | } |
|
583 | if (false === notEOF) { |
584 | if (false === notEOF) { |
|
584 | return false; |
585 | return false; |
|
585 | } |
586 | } |
|
586 | ret = false; |
587 | ret = false; |
|
587 | if (this.getCurrentLineIndentation() === currentIndentation && this.isStringUnIndentedCollectionItem(this.currentLine)) { |
588 | if (this.getCurrentLineIndentation() === currentIndentation && this.isStringUnIndentedCollectionItem(this.currentLine)) { |
|
588 | ret = true; |
589 | ret = true; |
|
589 | } |
590 | } |
|
590 | this.moveToPreviousLine(); |
591 | this.moveToPreviousLine(); |
|
591 | return ret; |
592 | return ret; |
|
592 | }; |
593 | }; |
|
593 | |
594 | |
|
594 | Parser.prototype.isStringUnIndentedCollectionItem = function() { |
595 | Parser.prototype.isStringUnIndentedCollectionItem = function() { |
|
595 | return this.currentLine === '-' || this.currentLine.slice(0, 2) === '- '; |
596 | return this.currentLine === '-' || this.currentLine.slice(0, 2) === '- '; |
|
596 | }; |
597 | }; |
|
597 | |
598 | |
|
598 | return Parser; |
599 | return Parser; |
|
599 | |
600 | |
|
600 | })(); |
601 | })(); |
|
601 | |
602 | |
|
602 | module.exports = Parser; |
603 | module.exports = Parser; |
|
603 | |
604 | |