JSDOC/Token.js
[gnome.introspection-doc-generator] / JSDOC / Token.js
1 //<Script type="text/javascript">
2
3 imports['Object.js'].load(Object);
4 JSDOC   = imports['JSDOC.js'].JSDOC;
5 console = imports['console.js'].console;
6 /**
7  *      @constructor
8  * 
9  *  types: 
10  *     TOKN  (unknown)
11  *     KEYW  (keyword)
12  *     COMM  (comment)
13  *     NAME  (name / identifier)
14  *     PUNC  (puctuation)
15  *     WHIT  (white space)
16  *     STRN  (string)
17  *     NUMB  (number)
18  *     REGX   (regular expression)
19  * 
20     
21 */
22
23 Token = Object.define(
24     function(data, type, name) {
25         this.data = data;
26         this.type = type;
27         this.name = name;
28         this.prefix = '';
29     }, 
30     Object, 
31     {
32         
33         toRaw : function(lvl)
34         {
35             lvl = lvl || 0;
36             
37             var ret =  this.data ;
38             if (this.items) {
39                 var ar = [];
40                 Roo.each(this.items, function(ai) {
41                     
42                     var str = '';
43                     Roo.each(ai, function(it) {
44                         str += it.toRaw(lvl + 1);
45                     })
46                     ar.push(str);
47                     
48                 })
49                 ret +=   ar.join('');
50                 
51             }
52             if (this.props) {
53                 for (var i in this.props) {
54                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
55                     Roo.each(this.props[i].val, function(e) {
56                         ret+=e.toRaw(lvl+1);
57                     })
58                     
59                 }
60             }
61             
62             
63             
64             return this.prefix +   ret;
65              
66         },
67
68         toJS : function() {
69             
70             try {
71                 var _tmp = '';
72                 eval( "_tmp = " + this.data);
73                 return _tmp;
74             } catch( e) {
75                 return "ERROR unparsable" + this.data;
76             }
77         },
78          
79                         
80
81         is : function(what) {
82             return this.name === what || this.type === what;
83         }
84 });
85