F1e3ab214a976a39cfd713bc93deb10f

obviously not a full implementation. I just need some basic list support etc. Everything is fine, but im retarded and cant get a list item, followed by another list to return the stack. only the first list will output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;(function(){
  YAML = {
    valueOf: function(token) {
      return eval('(' + token + ')')
    },
    
    tokenize: function(str) {
      return str.match(/(---|true|false|null|#(.*)|\[(.*?)\]|\{(.*?)\}|[\w\-]+:|-(.+)|\d+\.\d+|\d+|\n+)/g)
    },
    
    strip: function(str) {
      return str.replace(/^\s*|\s*$/, '')
    },
    
    parse: function(tokens) {
      var token, list = /^-(.*)/, key = /^([\w\-]+):/, stack = {}
      while (token = tokens.shift())
        if (token[0] == '#' || token == '---' || token == "\n") 
          continue
        else if (key.exec(token) && tokens[0] == "\n")
          stack[RegExp.$1] = this.parse(tokens)
        else if (key.exec(token))
          stack[RegExp.$1] = this.valueOf(tokens.shift())
        else if (list.exec(token))
          (stack.constructor == Array ?
            stack : (stack = [])).push(this.strip(RegExp.$1))
      return stack
    },
    
    eval: function(str) {
      return this.parse(this.tokenize(str))
    }
  }
})()

print(YAML.eval(readFile('config.yml')).toSource())




// config.yml

---
  # just a comment
  list: ['foo', 'bar']
  hash: { foo: "bar", n: 1 }
  lib:
    - lib/cart.js
    - lib/cart.foo.js
  specs:
    - spec/cart.spec.js
    - spec/cart.foo.spec.js
    # - Commented out
  environments:
    all:
      options:
        failuresOnly: true
        verbose: false

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel