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  *     COMM  (comment)          - name is MULTI_LINE_COMM, JSDOC, SINGLE_LINE_COMM
14  *     NAME  (name/identifier)  - name is NAME
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.identifier = false; // used by scope
32     }, 
33     Object, 
34     {
35         
36         toRaw : function(lvl)
37         {
38             lvl = lvl || 0;
39             
40             var ret =  this.data ;
41             if (this.items) {
42                 var ar = [];
43                 Roo.each(this.items, function(ai) {
44                     
45                     var str = '';
46                     Roo.each(ai, function(it) {
47                         str += it.toRaw(lvl + 1);
48                     })
49                     ar.push(str);
50                     
51                 })
52                 ret +=   ar.join('');
53                 
54             }
55             if (this.props) {
56                 for (var i in this.props) {
57                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
58                     Roo.each(this.props[i].val, function(e) {
59                         ret+=e.toRaw(lvl+1);
60                     })
61                     
62                 }
63             }
64             
65             
66             
67             return this.prefix +   ret;
68              
69         },
70
71         toJS : function() {
72             
73             try {
74                 var _tmp = '';
75                 eval( "_tmp = " + this.data);
76                 return _tmp;
77             } catch( e) {
78                 return "ERROR unparsable" + this.data;
79             }
80         },
81          
82                         
83
84         is : function(what) {
85             return this.name === what || this.type === what;
86         }
87 });
88