28f5867df94b3a1fe9c9725a2035c997f1eec8ed
[gnome.introspection-doc-generator] / JSDOC / Lang.vala
1 //<script type="text/javscript">
2
3 /**
4         @namespace
5 */
6 // test
7 // valac gitlive/app.Builder.js/JsRender/Lang.vala --pkg gee-1.0 -o /tmp/Lang ;/tmp/Lang
8
9 /*
10 void main () {
11     new JsRender.Lang_Class();
12     print(JsRender.Lang.keyword("delete") + "\n");
13 }
14 */
15  
16
17 namespace JSDOC {
18
19     public Lang_Class Lang = null;
20     
21     public class Lang_Class : Object {
22         
23         GLib.List<string> coreObjects;
24         Gee.HashMap<string,string> whitespaceNames;
25         Gee.HashMap<string,string> newlineNames;
26         Gee.HashMap<string,string> keywordNames;
27         Gee.HashMap<string,string> puncNames;
28         Gee.HashMap<string,string> matchingNames;
29         public Gee.ArrayList<string> match_strings;
30         
31         public Lang_Class ()
32         {
33             if (Lang != null) {
34                 //print("lang not null\n");
35                 return;
36             }
37             //print("init\n");
38             this.init();
39             //print("init Lang");
40             Lang = this;
41             Lang.ref();
42             
43         }
44         
45         
46         public bool isBuiltin(string  name) {
47             return (this.coreObjects.index(name) > -1);
48         }
49         
50         public string whitespace (string ch) {
51             return this.whitespaceNames.get(ch);
52         }
53         public string  newline (string ch) {
54             return this.newlineNames.get(ch);
55         }
56         public string keyword(string word) {
57             return this.keywordNames.get("="+word);
58         }
59         
60         public string matching(string name) {
61             return this.matchingNames.get(name);
62         }
63         
64         public bool isKeyword(string word) {
65             return this.keywordNames.get("=" + word) != null;
66             
67         }
68         public string punc (string ch) {
69             return this.puncNames.get(ch); // ?? does [xxx] work!?
70         }
71         
72         public bool isNumber (string str) {
73             return Regex.match_simple("^(\\.[0-9]|[0-9]+\\.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
74         }
75     
76         public bool  isHexDec (string str) {
77             return Regex.match_simple("^0x[0-9A-F]+$",str);
78         }
79     
80         public bool isWordChar (string str) {
81             return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
82         }
83     
84         public bool isSpace (string str) {
85             return this.whitespaceNames.get(str) != null;
86         }
87             public bool isSpaceC (char str) {
88                         var s = str.to_string();
89             return this.whitespaceNames.get(s) != null;
90         }
91         
92         public bool isNewline (string str) {
93             return this.newlineNames.get(str) != null;
94                 }          
95         public bool isNewlineC (char str) {
96                 var s =str.to_string();
97             return this.newlineNames.get(s) != null;
98         }
99             public bool isBoolean (string str) {
100                         var ss = str.down();
101             return ss == "false" || ss == "true";
102         }
103         
104          
105         
106         void init() {
107             
108             this.coreObjects = new GLib.List<string>();
109             
110             this.whitespaceNames = new Gee.HashMap<string,string>();
111             this.newlineNames = new Gee.HashMap<string,string>();
112             this.keywordNames = new Gee.HashMap<string,string>();
113             this.puncNames = new Gee.HashMap<string,string>();
114             this.matchingNames = new Gee.HashMap<string,string>();
115             this.match_strings = new Gee.ArrayList<string>();
116             
117             
118             string[] co = { "_global_", "Array", "Boolean", "Date", "Error", 
119                 "Function", "Math", "Number", "Object", "RegExp", "String" };
120             for(var i =0; i< co.length;i++ ) {
121                 this.coreObjects.append(co[i]);
122                 this.match_strings.add(co[i]);
123             }
124             string[] ws =  {
125                 " :SPACE",
126                 "\f:FORMFEED",
127                 "\t:TAB" //,
128               //  "\u0009:UNICODE_TAB",
129               //  "\u000A:UNICODE_NBR",
130               //  "\u0008:VERTICAL_TAB"
131             };
132             for(var i =0; i< ws.length;i++ ) {
133                 var x = ws[i].split(":");
134                 this.whitespaceNames.set(x[0],x[1]);
135             }
136             
137             ws = {
138                 "\n:NEWLINE",
139                 "\r:RETURN" //,
140     //            "\u000A:UNICODE_LF",
141       //          "\u000D:UNICODE_CR",
142         //        "\u2029:UNICODE_PS",
143           //      "\u2028:UNICODE_LS"
144             };
145             for(var i =0; i< ws.length;i++ ) {
146                 var x = ws[i].split(":");
147                 this.newlineNames.set(x[0],x[1]);
148             }
149             ws = {
150                 "=break:BREAK",
151                 "=case:CASE",
152                 "=catch:CATCH",
153                 "=const:VAR",
154                 "=continue:CONTINUE",
155                 "=default:DEFAULT",
156                 "=delete:DELETE",
157                 "=do:DO",
158                 "=else:ELSE",
159                 "=false:FALSE",
160                 "=finally:FINALLY",
161                 "=for:FOR",
162                 "=function:FUNCTION",
163                 "=if:IF",
164                 "=in:IN",
165                 "=instanceof:INSTANCEOF",
166                 "=new:NEW",
167                 "=null:NULL",
168                 "=return:RETURN",
169                 "=switch:SWITCH",
170                 "=this:THIS",
171                 "=throw:THROW",
172                 "=true:TRUE",
173                 "=try:TRY",
174                 "=typeof:TYPEOF",
175                 "=void:VOID",
176                 "=while:WHILE",
177                 "=with:WITH",
178                 "=var:VAR"
179              };
180             for(var i =0; i< ws.length;i++ ) {
181                 var x = ws[i].split(":");
182                 this.keywordNames.set(x[0],x[1]);
183                 this.match_strings.add(x[0].substring(1));
184             }
185         
186       
187             ws={
188                 "; SEMICOLON",
189                 ", COMMA",
190                 "? HOOK",
191                 ": COLON",
192                 "|| OR", 
193                 "&& AND",
194                 "| BITWISE_OR",
195                 "^ BITWISE_XOR",
196                 "& BITWISE_AND",
197                 "=== STRICT_EQ", 
198                 "== EQ",
199                 "= ASSIGN",
200                 "!== STRICT_NE",
201                 "!= NE",
202                 "<< LSH",
203                 "<= LE", 
204                 "< LT",
205                 ">>> URSH",
206                 ">> RSH",
207                 ">= GE",
208                 "> GT", 
209                 "++ INCREMENT",
210                 "-- DECREMENT",
211                 "+ PLUS",
212                 "- MINUS",
213                 "* MUL",
214                 "/ DIV", 
215                 "% MOD",
216                 "! NOT",
217                 "~ BITWISE_NOT",
218                 ". DOT",
219                 "[ LEFT_BRACE",
220                 "] RIGHT_BRACE",
221                 "{ LEFT_CURLY",
222                 "} RIGHT_CURLY",
223                 "( LEFT_PAREN",
224                 ") RIGHT_PAREN"
225             };
226             for(var i =0; i< ws.length;i++ ) {
227                 var x = ws[i].split(" ");
228                 this.puncNames.set(x[0],x[1]);
229             }
230         
231            string[] wsp = {
232                "LEFT_PAREN:RIGHT_PAREN",
233                "RIGHT_PAREN:LEFT_PAREN",
234                "LEFT_CURLY:RIGHT_CURLY",
235                "RIGHT_CURLY:LEFT_CURLY",
236                "LEFT_BRACE:RIGHT_BRACE",
237                "RIGHT_BRACE:LEFT_BRACE"
238            };
239            for(var i =0; i< wsp.length;i++ ) {
240                var x = wsp[i].split(":");
241                this.matchingNames.set(x[0],x[1]);
242            }
243            
244            
245            
246            
247         }
248         
249         
250     }
251 }