JSDOC/BuildDocs.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         this.id = Token.id++;
46     }, 
47     Object, 
48     {
49          toString: function()
50         {
51             return 'line:' + this.line + ', type:' + this.type + 
52                 ', name:' + this.name + ', data:' + this.data + 
53                 ((this.outData === false) ? '' : ( 'outData : ' + this.outData));
54         },
55         
56         
57         toRaw : function(lvl)
58         {
59             lvl = lvl || 0;
60             
61             var ret =  this.data ;
62             if (this.items) {
63                 var ar = [];
64                 Roo.each(this.items, function(ai) {
65                     
66                     var str = '';
67                     Roo.each(ai, function(it) {
68                         str += it.toRaw(lvl + 1);
69                     })
70                     ar.push(str);
71                     
72                 })
73                 ret +=   ar.join('');
74                 
75             }
76             if (this.props) {
77                 for (var i in this.props) {
78                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
79                     Roo.each(this.props[i].val, function(e) {
80                         ret+=e.toRaw(lvl+1);
81                     })
82                     
83                 }
84             }
85             
86             
87             
88             return this.prefix +   ret;
89              
90         },
91
92         toJS : function() {
93             
94             try {
95                 var _tmp = '';
96                 eval( "_tmp = " + this.data);
97                 return _tmp;
98             } catch( e) {
99                 return "ERROR unparsable" + this.data;
100             }
101         },
102          
103                         
104
105         is : function(what) {
106             return this.name === what || this.type === what;
107         }
108 });
109 Token.id = 0;