Add Javascript Compressor, and new XObject base util class (will replace Object.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, line) {
27         this.data = data;
28         this.type = type;
29         this.name = name;
30         this.line = line;
31         this.prefix = '';    
32         this.outData = false; // used by packer/scopeparser
33         this.identifier = false; // used by scope
34     }, 
35     Object, 
36     {
37          toString: function()
38         {
39             return 'line:' + this.line + ', type:' + this.type + ', name:' + this.name + ', data:' + this.data;
40         },
41         
42         
43         toRaw : function(lvl)
44         {
45             lvl = lvl || 0;
46             
47             var ret =  this.data ;
48             if (this.items) {
49                 var ar = [];
50                 Roo.each(this.items, function(ai) {
51                     
52                     var str = '';
53                     Roo.each(ai, function(it) {
54                         str += it.toRaw(lvl + 1);
55                     })
56                     ar.push(str);
57                     
58                 })
59                 ret +=   ar.join('');
60                 
61             }
62             if (this.props) {
63                 for (var i in this.props) {
64                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
65                     Roo.each(this.props[i].val, function(e) {
66                         ret+=e.toRaw(lvl+1);
67                     })
68                     
69                 }
70             }
71             
72             
73             
74             return this.prefix +   ret;
75              
76         },
77
78         toJS : function() {
79             
80             try {
81                 var _tmp = '';
82                 eval( "_tmp = " + this.data);
83                 return _tmp;
84             } catch( e) {
85                 return "ERROR unparsable" + this.data;
86             }
87         },
88          
89                         
90
91         is : function(what) {
92             return this.name === what || this.type === what;
93         }
94 });
95