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 Token = Object.define(
23     function(data, type, name) {
24         this.data = data;
25         this.type = type;
26         this.name = name;
27         this.prefix = '';
28     }, 
29     Object, 
30     {
31         
32         toRaw : function(lvl)
33         {
34             lvl = lvl || 0;
35             
36             var ret =  this.data ;
37             if (this.items) {
38                 var ar = [];
39                 Roo.each(this.items, function(ai) {
40                     
41                     var str = '';
42                     Roo.each(ai, function(it) {
43                         str += it.toRaw(lvl + 1);
44                     })
45                     ar.push(str);
46                     
47                 })
48                 ret +=   ar.join('');
49                 
50             }
51             if (this.props) {
52                 for (var i in this.props) {
53                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
54                     Roo.each(this.props[i].val, function(e) {
55                         ret+=e.toRaw(lvl+1);
56                     })
57                     
58                 }
59             }
60             
61             
62             
63             return this.prefix +   ret;
64              
65         },
66
67         toJS : function() {
68             
69             try {
70                 var _tmp = '';
71                 eval( "_tmp = " + this.data);
72                 return _tmp;
73             } catch( e) {
74                 return "ERROR unparsable" + this.data;
75             }
76         },
77          
78                         
79
80         is : function(what) {
81             return this.name === what || this.type === what;
82         }
83 });
84