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  *      @class Token
8  * 
9  *  @prop data {String} raw value of token
10  *  @prop type {String} type of token
11  *     TOKN  (unknown)          - name is UNKNOWN_TOKEN
12  *     KEYW  (keyword)          - name is upper case version of keyword
13  *     NAME  (name/identifier)  - name is NAME
14  *     COMM  (comment)          - name is MULTI_LINE_COMM, JSDOC, SINGLE_LINE_COMM
15  *     PUNC  (puctuation)       - name is String description of punctionan (eg LEFTPARAM)
16  *     WHIT  (white space)      - name is SPACE,NEWLINE
17  *     STRN  (string)           - name is DOBULE_QUOTE, SINGLE_QUOTE
18  *     NUMB  (number)           - name is OCTAL,DECIMAL,HEC_DEC
19  *     REGX   (reg.expression)  - name is REGX
20  *  @prop name {String} see type details above
21  *  @prop indentifier {Identifier} identifier class if relivant
22  * 
23 */
24
25 Token = Object.define(
26     function(data, type, name) {
27         this.data = data;
28         this.type = type;
29         this.name = name;
30         this.prefix = '';    
31         this.outData = false; // used by packer/scopeparser
32         this.identifier = false; // used by scope
33     }, 
34     Object, 
35     {
36         function toString()
37         {
38             return 'type:' + this.type+ ', name:' + this.name + ', data:' + this.data;
39         },
40         
41         
42         toRaw : function(lvl)
43         {
44             lvl = lvl || 0;
45             
46             var ret =  this.data ;
47             if (this.items) {
48                 var ar = [];
49                 Roo.each(this.items, function(ai) {
50                     
51                     var str = '';
52                     Roo.each(ai, function(it) {
53                         str += it.toRaw(lvl + 1);
54                     })
55                     ar.push(str);
56                     
57                 })
58                 ret +=   ar.join('');
59                 
60             }
61             if (this.props) {
62                 for (var i in this.props) {
63                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
64                     Roo.each(this.props[i].val, function(e) {
65                         ret+=e.toRaw(lvl+1);
66                     })
67                     
68                 }
69             }
70             
71             
72             
73             return this.prefix +   ret;
74              
75         },
76
77         toJS : function() {
78             
79             try {
80                 var _tmp = '';
81                 eval( "_tmp = " + this.data);
82                 return _tmp;
83             } catch( e) {
84                 return "ERROR unparsable" + this.data;
85             }
86         },
87          
88                         
89
90         is : function(what) {
91             return this.name === what || this.type === what;
92         }
93 });
94