scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
66 | office | 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 | function assemble(ast) { |
||
3 | var result; |
||
4 | |||
5 | if (!ast) { |
||
6 | return ast; |
||
7 | } |
||
8 | |||
9 | if (!ast.constructor || !ast.constructor.name) { |
||
10 | return ast.value; |
||
11 | } |
||
12 | |||
13 | switch (ast.constructor.name){ |
||
14 | case 'String': |
||
15 | result = ast; |
||
16 | break; |
||
17 | case 'YAMLDoc': |
||
18 | result = assemble(ast.value); |
||
19 | break; |
||
20 | case 'YAMLHash': |
||
21 | result = {}; |
||
22 | ast.keys.forEach(function (key){ |
||
23 | result[key.keyName] = assemble(key.value); |
||
24 | }); |
||
25 | break; |
||
26 | case 'YAMLList': |
||
27 | result = []; |
||
28 | ast.items.forEach(function (item){ |
||
29 | result.push(assemble(item)); |
||
30 | }); |
||
31 | break; |
||
32 | default: |
||
33 | result = ast.value; |
||
34 | |||
35 | } |
||
36 | |||
37 | return result; |
||
38 | } |
||
39 | |||
40 | |||
41 | module.exports = assemble; |
||
42 | },{}],2:[function(require,module,exports){ |
||
43 | var helpers = require('./helpers'); |
||
44 | |||
45 | // --- AST |
||
46 | |||
47 | /** |
||
48 | * Initialize with _tokens_. |
||
49 | */ |
||
50 | |||
51 | function AST(tokens, str) { |
||
52 | this.tokens = tokens; |
||
53 | |||
54 | // Windows new line support (CR+LF, \r\n) |
||
55 | str = str.replace(/\r\n/g, '\n'); |
||
56 | |||
57 | // Use a regex to do this magic |
||
58 | this.lines = str.split(/\n/g).map(function(i){ return i + '\n'}); |
||
59 | this.strLength = str.length; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Look-ahead a single token. |
||
64 | * |
||
65 | * @return {array} |
||
66 | * @api public |
||
67 | */ |
||
68 | |||
69 | AST.prototype.peek = function() { |
||
70 | return this.tokens[0] |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Advance by a single token. |
||
75 | * |
||
76 | * @return {array} |
||
77 | * @api public |
||
78 | */ |
||
79 | |||
80 | AST.prototype.advance = function() { |
||
81 | return this.tokens.shift() |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Advance and return the token's value. |
||
86 | * |
||
87 | * @return {mixed} |
||
88 | * @api private |
||
89 | */ |
||
90 | |||
91 | AST.prototype.advanceValue = function() { |
||
92 | return this.advance()[1][1] |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Accept _type_ and advance or do nothing. |
||
97 | * |
||
98 | * @param {string} type |
||
99 | * @return {bool} |
||
100 | * @api private |
||
101 | */ |
||
102 | |||
103 | AST.prototype.accept = function(type) { |
||
104 | if (this.peekType(type)) |
||
105 | return this.advance() |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Expect _type_ or throw an error _msg_. |
||
110 | * |
||
111 | * @param {string} type |
||
112 | * @param {string} msg |
||
113 | * @api private |
||
114 | */ |
||
115 | |||
116 | AST.prototype.expect = function(type, msg) { |
||
117 | if (this.accept(type)) return |
||
118 | throw new Error(msg + ', ' + helpers.context(this.peek()[1].input)) |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Return the next token type. |
||
123 | * |
||
124 | * @return {string} |
||
125 | * @api private |
||
126 | */ |
||
127 | |||
128 | AST.prototype.peekType = function(val) { |
||
129 | return this.tokens[0] && |
||
130 | this.tokens[0][0] === val |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * space* |
||
135 | */ |
||
136 | |||
137 | AST.prototype.ignoreSpace = function() { |
||
138 | while (this.peekType('space')) |
||
139 | this.advance() |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * (space | indent | dedent)* |
||
144 | */ |
||
145 | |||
146 | AST.prototype.ignoreWhitespace = function() { |
||
147 | while (this.peekType('space') || |
||
148 | this.peekType('indent') || |
||
149 | this.peekType('dedent')) |
||
150 | this.advance() |
||
151 | } |
||
152 | |||
153 | // constructor functions |
||
154 | function YAMLDoc() { |
||
155 | this.node = 'YAMLDoc'; |
||
156 | } |
||
157 | function YAMLHash() { |
||
158 | this.node = 'YAMLHash'; |
||
159 | this.keys = []; |
||
160 | } |
||
161 | function YAMLHashKey(id) { |
||
162 | this.node = 'YAMLHashKey'; |
||
163 | this.keyName = id[1][0] |
||
164 | } |
||
165 | function YAMLList() { |
||
166 | this.node = 'YAMLList'; |
||
167 | this.items = []; |
||
168 | } |
||
169 | function YAMLInt(token){ |
||
170 | this.node = 'YAMLInt'; |
||
171 | this.raw = token[1][0]; |
||
172 | this.value = parseInt(token[1][0]); |
||
173 | } |
||
174 | function YAMLFloat(token) { |
||
175 | this.node = 'YAMLFloat'; |
||
176 | this.raw = token[1][0]; |
||
177 | this.value = parseFloat(token[1][0]); |
||
178 | } |
||
179 | function YAMLString(token) { |
||
180 | var raw = token[1][0]; |
||
181 | |||
182 | this.raw = raw; |
||
183 | this.node = 'YAMLString'; |
||
184 | |||
185 | if (raw[0] === raw[raw.length - 1] && (raw[0] === '"' || raw[0] === '\'')){ |
||
186 | // Remove quotation marks |
||
187 | this.value = raw.substring(1, raw.length - 1); |
||
188 | } else { |
||
189 | this.value = token[1][0]; |
||
190 | } |
||
191 | } |
||
192 | function YAMLTrue(token) { |
||
193 | this.node = 'YAMLTrue'; |
||
194 | this.raw = token[1][0]; |
||
195 | this.value = true |
||
196 | } |
||
197 | function YAMLFalse(token) { |
||
198 | this.node = 'YAMLFalse'; |
||
199 | this.raw = token[1][0]; |
||
200 | this.value = false; |
||
201 | } |
||
202 | function YAMLNull(token) { |
||
203 | this.node = 'YAMLNull'; |
||
204 | this.raw = token[1][0]; |
||
205 | this.value = null; |
||
206 | } |
||
207 | function YAMLDate(token) { |
||
208 | this.node = 'YAMLDate'; |
||
209 | this.raw = token[1][0]; |
||
210 | this.value = helpers.parseTimestamp(token[1]); |
||
211 | } |
||
212 | |||
213 | AST.prototype.parse = function() { |
||
214 | switch (this.peek()[0]) { |
||
215 | case 'doc': |
||
216 | return this.parseDoc(); |
||
217 | case '-': |
||
218 | return this.parseList(); |
||
219 | case '{': |
||
220 | return this.parseInlineHash(); |
||
221 | case '[': |
||
222 | return this.parseInlineList(); |
||
223 | case 'id': |
||
224 | return this.parseHash(); |
||
225 | case 'string': |
||
226 | return this.parseValue(YAMLString); |
||
227 | case 'timestamp': |
||
228 | return this.parseValue(YAMLDate); |
||
229 | case 'float': |
||
230 | return this.parseValue(YAMLFloat); |
||
231 | case 'int': |
||
232 | return this.parseValue(YAMLInt); |
||
233 | case 'true': |
||
234 | return this.parseValue(YAMLTrue); |
||
235 | case 'false': |
||
236 | return this.parseValue(YAMLFalse); |
||
237 | case 'null': |
||
238 | return this.parseValue(YAMLNull); |
||
239 | } |
||
240 | }; |
||
241 | |||
242 | AST.prototype.parseDoc = function() { |
||
243 | this.accept('doc'); |
||
244 | this.expect('indent', 'expected indent after document'); |
||
245 | var val = this.parse(); |
||
246 | this.expect('dedent', 'document not properly dedented'); |
||
247 | var yamlDoc = new YAMLDoc(); |
||
248 | yamlDoc.value = val; |
||
249 | yamlDoc.start = this.indexToRowCol(0); |
||
250 | yamlDoc.end = this.indexToRowCol(this.strLength - 1); |
||
251 | return yamlDoc; |
||
252 | } |
||
253 | |||
254 | AST.prototype.parseHash = function() { |
||
255 | var id, hash = new YAMLHash(); |
||
256 | while (this.peekType('id') && (id = this.advance())) { |
||
257 | this.expect(':', 'expected semi-colon after id'); |
||
258 | this.ignoreSpace(); |
||
259 | var hashKey = new YAMLHashKey(id); |
||
260 | this.assignStartEnd(hashKey, id); |
||
261 | if (this.accept('indent')) { |
||
262 | hashKey.value = this.parse(); |
||
263 | if (this.tokens.length){ |
||
264 | this.expect('dedent', 'hash not properly dedented'); |
||
265 | } |
||
266 | } else { |
||
267 | hashKey.value = this.parse(); |
||
268 | } |
||
269 | hash.keys.push(hashKey); |
||
270 | this.ignoreSpace(); |
||
271 | } |
||
272 | |||
273 | // Add start and end to the hash based on start of the first key |
||
274 | // and end of the last key |
||
275 | hash.start = hash.keys[0].start; |
||
276 | hash.end = hash.keys[hash.keys.length - 1].value.end; |
||
277 | |||
278 | return hash; |
||
279 | } |
||
280 | |||
281 | AST.prototype.parseInlineHash = function() { |
||
282 | var hash = new YAMLHash(), id, i = 0; |
||
283 | this.accept('{'); |
||
284 | |||
285 | while (!this.accept('}')) { |
||
286 | this.ignoreSpace(); |
||
287 | |||
288 | if (i) { |
||
289 | this.expect(',', 'expected comma'); |
||
290 | } |
||
291 | this.ignoreWhitespace(); |
||
292 | |||
293 | if (this.peekType('id') && (id = this.advance())) { |
||
294 | var hashKey = new YAMLHashKey(id); |
||
295 | this.assignStartEnd(hashKey, id); |
||
296 | this.expect(':', 'expected semi-colon after id'); |
||
297 | this.ignoreSpace(); |
||
298 | hashKey.value = this.parse(); |
||
299 | hash.keys.push(hashKey); |
||
300 | this.ignoreWhitespace(); |
||
301 | } |
||
302 | ++i; |
||
303 | } |
||
304 | |||
305 | // Add start and end to the hash based on start of the first key |
||
306 | // and end of the last key |
||
307 | hash.start = hash.keys[0].start; |
||
308 | hash.end = hash.keys[hash.keys.length - 1].value.end; |
||
309 | |||
310 | return hash; |
||
311 | } |
||
312 | |||
313 | AST.prototype.parseList = function() { |
||
314 | var list = new YAMLList(); |
||
315 | var begining, end; |
||
316 | |||
317 | begining = this.accept('-'); |
||
318 | while (true) { |
||
319 | this.ignoreSpace(); |
||
320 | |||
321 | if (this.accept('indent')) { |
||
322 | list.items.push(this.parse()); |
||
323 | this.expect('dedent', 'list item not properly dedented'); |
||
324 | } else{ |
||
325 | list.items.push(this.parse()); |
||
326 | } |
||
327 | |||
328 | this.ignoreSpace(); |
||
329 | |||
330 | end = this.accept('-'); |
||
331 | |||
332 | if (end){ |
||
333 | // Keep a copy of last end to use it for list.end |
||
334 | endBuffer = end; |
||
335 | } else { |
||
336 | end = endBuffer; |
||
337 | break; |
||
338 | } |
||
339 | } |
||
340 | |||
341 | list.start = begining[2]; |
||
342 | list.end = end[3]; |
||
343 | |||
344 | return list; |
||
345 | } |
||
346 | |||
347 | AST.prototype.parseInlineList = function() { |
||
348 | var list = new YAMLList(), i = 0; |
||
349 | var begining = this.accept('['); |
||
350 | var end = this.accept(']'); |
||
351 | |||
352 | while (!end) { |
||
353 | this.ignoreSpace(); |
||
354 | if (i) this.expect(',', 'expected comma'); |
||
355 | this.ignoreSpace(); |
||
356 | list.items.push(this.parse()); |
||
357 | this.ignoreSpace(); |
||
358 | ++i; |
||
359 | end = this.accept(']'); |
||
360 | } |
||
361 | |||
362 | list.start = begining[2]; |
||
363 | list.end = end[3]; |
||
364 | |||
365 | return list |
||
366 | } |
||
367 | |||
368 | AST.prototype.parseValue = function(constructorFn) { |
||
369 | var token = this.advance(); |
||
370 | var value = new constructorFn(token); |
||
371 | this.assignStartEnd(value, token); |
||
372 | return value; |
||
373 | } |
||
374 | |||
375 | |||
376 | AST.prototype.assignStartEnd = function (node, token) { |
||
377 | node.start = this.indexToRowCol(token[2]); |
||
378 | node.end = this.indexToRowCol(token[3]); |
||
379 | } |
||
380 | |||
381 | AST.prototype.indexToRowCol = function (index) { |
||
382 | if (!this.lines) return null; |
||
383 | |||
384 | for (var l = 0; l < this.lines.length; l++) { |
||
385 | if (index >= this.lines[l].length){ |
||
386 | index -= this.lines[l].length; |
||
387 | } else { |
||
388 | break; |
||
389 | } |
||
390 | } |
||
391 | |||
392 | return { |
||
393 | row: l, |
||
394 | column: index |
||
395 | }; |
||
396 | } |
||
397 | |||
398 | module.exports = AST; |
||
399 | |||
400 | },{"./helpers":3}],3:[function(require,module,exports){ |
||
401 | // --- Helpers |
||
402 | |||
403 | /** |
||
404 | * Return 'near "context"' where context |
||
405 | * is replaced by a chunk of _str_. |
||
406 | * |
||
407 | * @param {string} str |
||
408 | * @return {string} |
||
409 | * @api public |
||
410 | */ |
||
411 | |||
412 | function context(str) { |
||
413 | if (typeof str !== 'string') |
||
414 | return ''; |
||
415 | |||
416 | str = str |
||
417 | .slice(0, 25) |
||
418 | .replace(/\n/g, '\\n') |
||
419 | .replace(/"/g, '\\\"'); |
||
420 | |||
421 | return 'near "' + str + '"'; |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Return a UTC time from a time token |
||
426 | * |
||
427 | * @param {mixed} token |
||
428 | * @return {Date} |
||
429 | * @api public |
||
430 | */ |
||
431 | |||
432 | function parseTimestamp(token) { |
||
433 | var date = new Date |
||
434 | var year = token[2], |
||
435 | month = token[3], |
||
436 | day = token[4], |
||
437 | hour = token[5] || 0, |
||
438 | min = token[6] || 0, |
||
439 | sec = token[7] || 0; |
||
440 | |||
441 | date.setUTCFullYear(year, month-1, day); |
||
442 | date.setUTCHours(hour); |
||
443 | date.setUTCMinutes(min); |
||
444 | date.setUTCSeconds(sec); |
||
445 | date.setUTCMilliseconds(0); |
||
446 | |||
447 | return date; |
||
448 | } |
||
449 | |||
450 | |||
451 | module.exports = { |
||
452 | context: context, |
||
453 | parseTimestamp: parseTimestamp |
||
454 | }; |
||
455 | |||
456 | },{}],4:[function(require,module,exports){ |
||
457 | var helpers = require('./helpers'); |
||
458 | // --- Lexer |
||
459 | |||
460 | /** |
||
461 | * YAML grammar tokens. |
||
462 | */ |
||
463 | |||
464 | var tokens = [ |
||
465 | ['comment', /^#[^\n]*/], |
||
466 | ['indent', /^\n( *)/], |
||
467 | ['space', /^ +/], |
||
468 | ['true', /^\b(enabled|true|yes|on)\b/], |
||
469 | ['false', /^\b(disabled|false|no|off)\b/], |
||
470 | ['null', /^\b(null|Null|NULL|~)\b/], |
||
471 | ['string', /^"(.*?)"/], |
||
472 | ['string', /^'(.*?)'/], |
||
473 | ['timestamp', /^((\d{4})-(\d\d?)-(\d\d?)(?:(?:[ \t]+)(\d\d?):(\d\d)(?::(\d\d))?)?)/], |
||
474 | ['float', /^(\d+\.\d+)/], |
||
475 | ['int', /^(\d+)/], |
||
476 | ['doc', /^---/], |
||
477 | [',', /^,/], |
||
478 | ['{', /^\{(?![^\n\}]*\}[^\n]*[^\s\n\}])/], |
||
479 | ['}', /^\}/], |
||
480 | ['[', /^\[(?![^\n\]]*\][^\n]*[^\s\n\]])/], |
||
481 | [']', /^\]/], |
||
482 | ['-', /^\-/], |
||
483 | [':', /^[:]/], |
||
484 | ['string', /^(?![^:\n\s]*:[^\/]{2})(([^:,\]\}\n\s]|(?!\n)\s(?!\s*?\n)|:\/\/|,(?=[^\n]*\s*[^\]\}\s\n]\s*\n)|[\]\}](?=[^\n]*\s*[^\]\}\s\n]\s*\n))*)(?=[,:\]\}\s\n]|$)/], |
||
485 | ['id', /^([\w|\/|\$][\w -]*)/ ] |
||
486 | ] |
||
487 | |||
488 | |||
489 | /** |
||
490 | * Tokenize the given _str_. |
||
491 | * |
||
492 | * @param {string} str |
||
493 | * @return {array} |
||
494 | * @api private |
||
495 | */ |
||
496 | |||
497 | exports.tokenize = function (str) { |
||
498 | var token, captures, ignore, input, |
||
499 | index = 0, |
||
500 | indents = 0, lastIndents = 0, |
||
501 | stack = [], indentAmount = -1 |
||
502 | |||
503 | // Windows new line support (CR+LF, \r\n) |
||
504 | str = str.replace(/\r\n/g, "\n"); |
||
505 | |||
506 | while (str.length) { |
||
507 | for (var i = 0, len = tokens.length; i < len; ++i) |
||
508 | if (captures = tokens[i][1].exec(str)) { |
||
509 | // token format: [tokenType, capturedToken, startIndex, endIndex] |
||
510 | token = [tokens[i][0], captures, index, index + captures[0].length - 1]; |
||
511 | str = str.replace(tokens[i][1], ''); |
||
512 | index += captures[0].length; |
||
513 | switch (token[0]) { |
||
514 | case 'comment': |
||
515 | ignore = true; |
||
516 | break; |
||
517 | case 'indent': |
||
518 | lastIndents = indents; |
||
519 | // determine the indentation amount from the first indent |
||
520 | if (indentAmount == -1) { |
||
521 | indentAmount = token[1][1].length; |
||
522 | } |
||
523 | |||
524 | indents = token[1][1].length / indentAmount; |
||
525 | |||
526 | if (indents === lastIndents || isNaN(indents)) { |
||
527 | ignore = true; |
||
528 | } |
||
529 | else if (indents > lastIndents + 1){ |
||
530 | throw new SyntaxError('invalid indentation, got ' + indents + ' instead of ' + (lastIndents + 1)); |
||
531 | } |
||
532 | else if (indents < lastIndents) {> |
||
533 | < lastIndents) { input = token[1].input;> |
||
534 | < lastIndents) { token = ['dedent'];> |
||
535 | < lastIndents) { token.input = input;> |
||
536 | < lastIndents) { while (--lastIndents > indents){> |
||
537 | < lastIndents) { stack.push(token)> |
||
538 | < lastIndents) { }> |
||
539 | < lastIndents) { }> |
||
540 | < lastIndents) { }> |
||
541 | < lastIndents) { break> |
||
542 | < lastIndents) { }> |
||
543 | < lastIndents) { if (!ignore)> |
||
544 | < lastIndents) { if (token)> |
||
545 | < lastIndents) { stack.push(token),> |
||
546 | < lastIndents) { token = null> |
||
547 | < lastIndents) { else> |
||
548 | < lastIndents) { throw new SyntaxError(helpers.context(str))> |
||
549 | < lastIndents) { ignore = false> |
||
550 | < lastIndents) { }> |
||
551 | < lastIndents) { return stack> |
||
552 | < lastIndents) {}> |
||
553 | |||
554 | < lastIndents) {},{"./helpers":3}],5:[function(require,module,exports){> |
||
555 | < lastIndents) {// YAML - Core -> |
||
556 | < lastIndents) {// Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)> |
||
557 | < lastIndents) {// Copyright Mohsen Azimi <mohsen@mohsenweb.com> (MIT Licensed)> |
||
558 | |||
559 | < lastIndents) {var assemble = require('./assembler');> |
||
560 | < lastIndents) {var AST = require('./ast');> |
||
561 | < lastIndents) {var tokenize = require('./lexer').tokenize;> |
||
562 | |||
563 | < lastIndents) {/**> |
||
564 | < lastIndents) { * Version triplet.> |
||
565 | < lastIndents) { */> |
||
566 | |||
567 | < lastIndents) {exports.version = '0.3.0';> |
||
568 | |||
569 | |||
570 | < lastIndents) {/**> |
||
571 | < lastIndents) { * Evaluate a _str_ of yaml.> |
||
572 | < lastIndents) { *> |
||
573 | < lastIndents) { * @param {string} str> |
||
574 | < lastIndents) { * @return {mixed}> |
||
575 | < lastIndents) { * @api public> |
||
576 | < lastIndents) { */> |
||
577 | |||
578 | < lastIndents) {var eval = function(str) {> |
||
579 | < lastIndents) { return assemble(exports.ast(str));> |
||
580 | < lastIndents) {}> |
||
581 | |||
582 | < lastIndents) {/**> |
||
583 | < lastIndents) { * Evaluate a _str_ of yaml to an Abstract Syntax Tree (AST).> |
||
584 | < lastIndents) { *> |
||
585 | < lastIndents) { * @param {string} str> |
||
586 | < lastIndents) { * @return {mixed}> |
||
587 | < lastIndents) { * @api public> |
||
588 | < lastIndents) { */> |
||
589 | < lastIndents) {var ast = function(str) {> |
||
590 | < lastIndents) { return (new AST(tokenize(str), str)).parse()> |
||
591 | < lastIndents) {}> |
||
592 | |||
593 | < lastIndents) {if (typeof window !== 'undefined') {> |
||
594 | < lastIndents) { window.yaml2 = window.yaml2 || {> |
||
595 | < lastIndents) { eval: eval,> |
||
596 | < lastIndents) { ast: ast> |
||
597 | < lastIndents) { };> |
||
598 | < lastIndents) {}> |
||
599 | |||
600 | < lastIndents) {exports.eval = eval;> |
||
601 | < lastIndents) {exports.ast = ast;> |
||
602 | < lastIndents) {},{"./assembler":1,"./ast":2,"./lexer":4}]},{},[5]);> |