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