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