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