sync fixes
[app.jsdoc] / JSDOC / Token.js
1 //<Script type="text/javascript">
2
3 XObject = imports.XObject.XObject;
4  
5 console = imports.console.console;
6 /**
7
8  *  
9  *  Token of a JS file eg. a keyword, identifier, punctionaion etc..
10  *  
11  * <PRE>
12  *  Token Types:
13  *     TOKN  (unknown)          - name is UNKNOWN_TOKEN
14  * 
15  *     KEYW  (keyword)          - name is upper case version of keyword
16  *     NAME  (name/identifier)  - name is NAME
17  *     COMM  (comment)          - name is MULTI_LINE_COMM, JSDOC, SINGLE_LINE_COMM
18  *     PUNC  (puctuation)       - name is String description of punctionan (eg LEFTPARAM)
19  *     WHIT  (white space)      - name is SPACE,NEWLINE
20  *     STRN  (string)           - name is DOBULE_QUOTE, SINGLE_QUOTE
21  *     NUMB  (number)           - name is OCTAL,DECIMAL,HEC_DEC
22  *     REGX   (reg.expression)  - name is REGX
23  * 
24  * 
25  * old mappings:
26  * 
27  * Script.TOKidentifier  - type == 'NAME'
28  * Script.TOKassign  = data == '='
29  * Script.TOKsemicolon data == '';
30  * 
31  * </PRE>
32  * 
33  *  @scope JSDOC 
34  *  @class Token
35  *  @param {String} data  raw value of token
36  *  @param {String} type  type of token
37  *  @param {String} name  see type details above
38  *  @param {JSDOC.Identifier} identifier  identifier class if relivant
39 */
40
41 Token = XObject.define(
42     function(data, type, name, line) {
43         this.data = data;
44         this.type = type;
45         this.name = name;
46         this.line = line;
47         this.prefix = '';    
48         this.outData = false; // used by packer/scopeparser
49         this.identifier = false; // used by scope
50         this.id = Token.id++;
51         this.comment = '',
52         this.jsdoc = false
53     }, 
54     Object, 
55     {
56         /** @type {String} The raw text of the token */
57         data : false,
58         /** @type {String} The type of the token */
59         type : false,
60         /** @type {String} name of the token (eg. "MULTI_LINE_COMM" ) - see table above */
61         name : false,
62         /** @type {Number} line the token occurs on. */
63         line : false,
64         /** @type {String} white or comment prefix for rebuilding source*/
65         prefix : false,
66         /** @type {String} used by packer/ scopeparser to store what is actually output for this */
67         outData : false,// used by packer/scopeparser
68         /** @type {String} the identifier refered to (mangled by packer) */
69         identifier : false, // used by scope
70         /** @type {Number} numberic identifier for token */
71         id : false,
72         /** @type {String} the comments that come before the token? (TBC) */
73         comment : false,
74         /** @type {JSDOC.DocTag} assigned in JSDOC.Compiler that relates to this token. */
75         jsdoc : false,
76         
77          toString: function()
78         {
79             return 'line:' + this.line + ', type:' + this.type + 
80                 ', name:' + this.name + ', data:' + this.data + 
81                 ((this.outData === false) ? '' : ( 'outData : ' + this.outData));
82         },
83         
84         
85         toRaw : function(lvl)
86         {
87             lvl = lvl || 0;
88             
89             var ret =  this.data ;
90             
91             
92             if (this.items) {
93                 var ar = [];
94                 this.items.forEach(  function(ai) {
95                     
96                     var str = '';
97                     ai.forEach(  function(it) {
98                         str += it.toRaw(lvl + 1);
99                     })
100                     ar.push(str);
101                     
102                 })
103                 ret +=   ar.join('');
104                 
105             }
106             if (this.props) {
107                 for (var i in this.props) {
108                     ret += this.props[i].key.toRaw(lvl+1) + ' : ';
109                     this.props[i].val.forEach( function(e) {
110                         ret+=e.toRaw(lvl+1);
111                     })
112                     
113                 }
114             }
115             
116             
117             
118             return this.prefix +   ret;
119              
120         },
121
122         toJS : function() {
123             
124             try {
125                 var _tmp = '';
126                 eval( "_tmp = " + this.data);
127                 return _tmp;
128             } catch( e) {
129                 return "ERROR unparsable" + this.data;
130             }
131         },
132          
133                         
134
135         is : function(what) {
136             return this.name === what || this.type === what;
137         }
138 });
139 Token.id = 0;