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