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