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