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