Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / optionator / lib / parse-type.js
1 // Generated by LiveScript 1.2.0
2 (function(){
3   var reject, tokenRegex;
4   reject = require('prelude-ls').reject;
5   function consumeWord(tokens){
6     var token;
7     token = tokens[0];
8     if (!(token != null && /^[a-zA-Z]+$/.test(token))) {
9       throw new Error("Exected textual string.");
10     }
11     return tokens.shift();
12   }
13   function consumeOp(tokens, op){
14     var token;
15     token = tokens[0];
16     if (token !== op) {
17       throw new Error("Expected " + op);
18     }
19     return tokens.shift();
20   }
21   function maybeConsumeOp(tokens, op){
22     var token;
23     token = tokens[0];
24     if (token === op) {
25       return tokens.shift();
26     } else {
27       return null;
28     }
29   }
30   function consumeArray(tokens){
31     var contentType;
32     consumeOp(tokens, '[');
33     contentType = consumeTypes(tokens);
34     if (!contentType) {
35       throw new Error("Must specify content type for Array.");
36     }
37     consumeOp(tokens, ']');
38     return {
39       type: 'Array',
40       contentType: contentType
41     };
42   }
43   function consumeTuple(tokens){
44     var contentTypes, that;
45     contentTypes = [];
46     consumeOp(tokens, '(');
47     while (that = consumeTypes(tokens)) {
48       contentTypes.push(that);
49       if (!maybeConsumeOp(tokens, ',')) {
50         break;
51       }
52     }
53     consumeOp(tokens, ')');
54     return {
55       type: 'Tuple',
56       contentTypes: contentTypes
57     };
58   }
59   function consumeProperty(tokens){
60     var key, type;
61     key = consumeWord(tokens);
62     consumeOp(tokens, ':');
63     type = consumeTypes(tokens);
64     return {
65       key: key,
66       type: type
67     };
68   }
69   function consumeObject(tokens){
70     var properties, that;
71     properties = [];
72     consumeOp(tokens, '{');
73     while (that = consumeProperty(tokens)) {
74       properties.push(that);
75       if (!maybeConsumeOp(tokens, ',')) {
76         break;
77       }
78     }
79     consumeOp(tokens, '}');
80     return {
81       type: 'Object',
82       properties: properties
83     };
84   }
85   function consumeType(tokens){
86     switch (tokens[0]) {
87     case '[':
88       return consumeArray(tokens);
89     case '{':
90       return consumeObject(tokens);
91     case '(':
92       return consumeTuple(tokens);
93     default:
94       return {
95         type: consumeWord(tokens)
96       };
97     }
98   }
99   function consumeMaybe(tokens){
100     var maybe, type;
101     if (tokens[0] === 'Maybe') {
102       tokens.shift();
103       maybe = true;
104     }
105     type = consumeType(tokens);
106     if (maybe) {
107       return {
108         type: 'Maybe',
109         contentType: type
110       };
111     } else {
112       return type;
113     }
114   }
115   function consumeTypes(tokens){
116     var types;
117     types = [];
118     for (;;) {
119       types.push(consumeMaybe(tokens));
120       if (!maybeConsumeOp('|')) {
121         break;
122       }
123     }
124     if (!types.length) {
125       throw new Error("Expected type(s).");
126     }
127     return types;
128   }
129   tokenRegex = /[:,\[\]\(\)}{]|[a-zA-Z]+/g;
130   module.exports = function(input){
131     var tokens, e;
132     tokens = reject(function(it){
133       return /^\s*$/.test(it);
134     })(
135     input.match(tokenRegex));
136     try {
137       return consumeTypes(tokens);
138     } catch (e$) {
139       e = e$;
140       throw new Error(e.message + " - '" + tokens.join('#') + "' - '" + input + "'");
141     }
142   };
143 }).call(this);