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         
91         public bool isNewline (string str) {
92             return this.newlineNames.get(str) != null;
93                 }          
94         public bool isNewlineC (char str) {
95                 var s = (string) str;
96             return this.newlineNames.get(s) != null;
97         }
98             public bool isBoolean (string str) {
99                         var ss = str.down();
100             return ss == "false" || ss == "true";
101         }
102         
103          
104         
105         void init() {
106             
107             this.coreObjects = new GLib.List<string>();
108             
109             this.whitespaceNames = new Gee.HashMap<string,string>();
110             this.newlineNames = new Gee.HashMap<string,string>();
111             this.keywordNames = new Gee.HashMap<string,string>();
112             this.puncNames = new Gee.HashMap<string,string>();
113             this.matchingNames = new Gee.HashMap<string,string>();
114             this.match_strings = new Gee.ArrayList<string>();
115             
116             
117             string[] co = { "_global_", "Array", "Boolean", "Date", "Error", 
118                 "Function", "Math", "Number", "Object", "RegExp", "String" };
119             for(var i =0; i< co.length;i++ ) {
120                 this.coreObjects.append(co[i]);
121                 this.match_strings.add(co[i]);
122             }
123             string[] ws =  {
124                 " :SPACE",
125                 "\f:FORMFEED",
126                 "\t:TAB" //,
127               //  "\u0009:UNICODE_TAB",
128               //  "\u000A:UNICODE_NBR",
129               //  "\u0008:VERTICAL_TAB"
130             };
131             for(var i =0; i< ws.length;i++ ) {
132                 var x = ws[i].split(":");
133                 this.whitespaceNames.set(x[0],x[1]);
134             }
135             
136             ws = {
137                 "\n:NEWLINE",
138                 "\r:RETURN" //,
139     //            "\u000A:UNICODE_LF",
140       //          "\u000D:UNICODE_CR",
141         //        "\u2029:UNICODE_PS",
142           //      "\u2028:UNICODE_LS"
143             };
144             for(var i =0; i< ws.length;i++ ) {
145                 var x = ws[i].split(":");
146                 this.newlineNames.set(x[0],x[1]);
147             }
148             ws = {
149                 "=break:BREAK",
150                 "=case:CASE",
151                 "=catch:CATCH",
152                 "=const:VAR",
153                 "=continue:CONTINUE",
154                 "=default:DEFAULT",
155                 "=delete:DELETE",
156                 "=do:DO",
157                 "=else:ELSE",
158                 "=false:FALSE",
159                 "=finally:FINALLY",
160                 "=for:FOR",
161                 "=function:FUNCTION",
162                 "=if:IF",
163                 "=in:IN",
164                 "=instanceof:INSTANCEOF",
165                 "=new:NEW",
166                 "=null:NULL",
167                 "=return:RETURN",
168                 "=switch:SWITCH",
169                 "=this:THIS",
170                 "=throw:THROW",
171                 "=true:TRUE",
172                 "=try:TRY",
173                 "=typeof:TYPEOF",
174                 "=void:VOID",
175                 "=while:WHILE",
176                 "=with:WITH",
177                 "=var:VAR"
178              };
179             for(var i =0; i< ws.length;i++ ) {
180                 var x = ws[i].split(":");
181                 this.keywordNames.set(x[0],x[1]);
182                 this.match_strings.add(x[0].substring(1));
183             }
184         
185       
186             ws={
187                 "; SEMICOLON",
188                 ", COMMA",
189                 "? HOOK",
190                 ": COLON",
191                 "|| OR", 
192                 "&& AND",
193                 "| BITWISE_OR",
194                 "^ BITWISE_XOR",
195                 "& BITWISE_AND",
196                 "=== STRICT_EQ", 
197                 "== EQ",
198                 "= ASSIGN",
199                 "!== STRICT_NE",
200                 "!= NE",
201                 "<< LSH",
202                 "<= LE", 
203                 "< LT",
204                 ">>> URSH",
205                 ">> RSH",
206                 ">= GE",
207                 "> GT", 
208                 "++ INCREMENT",
209                 "-- DECREMENT",
210                 "+ PLUS",
211                 "- MINUS",
212                 "* MUL",
213                 "/ DIV", 
214                 "% MOD",
215                 "! NOT",
216                 "~ BITWISE_NOT",
217                 ". DOT",
218                 "[ LEFT_BRACE",
219                 "] RIGHT_BRACE",
220                 "{ LEFT_CURLY",
221                 "} RIGHT_CURLY",
222                 "( LEFT_PAREN",
223                 ") RIGHT_PAREN"
224             };
225             for(var i =0; i< ws.length;i++ ) {
226                 var x = ws[i].split(" ");
227                 this.puncNames.set(x[0],x[1]);
228             }
229         
230            ws = {
231                "LEFT_PAREN:RIGHT_PAREN",
232                "RIGHT_PAREN:LEFT_PAREN",
233                "LEFT_CURLY:RIGHT_CURLY",
234                "RIGHT_CURLY:LEFT_CURLY",
235                "LEFT_BRACE:RIGHT_BRACE",
236                "RIGHT_BRACE:LEFT_BRACE"
237            };
238            for(var i =0; i< ws.length;i++ ) {
239                var x = ws[i].split(":");
240                this.matchingNames.set(x[0],x[1]);
241            }
242            
243            
244            
245            
246         }
247         
248         
249     }
250 }