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