1 //<script type="text/javscript">
7 // valac gitlive/app.Builder.js/JsRender/Lang.vala --pkg gee-1.0 -o /tmp/Lang ;/tmp/Lang
11 new JsRender.Lang_Class();
12 print(JsRender.Lang.keyword("delete") + "\n");
19 public Lang_Class Lang = null;
21 public class Lang_Class : Object {
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;
34 //print("lang not null\n");
46 public bool isBuiltin(string name) {
47 return (this.coreObjects.index(name) > -1);
50 public string whitespace (string ch) {
51 return this.whitespaceNames.get(ch);
53 public string newline (string ch) {
54 return this.newlineNames.get(ch);
56 public string keyword(string word) {
57 return this.keywordNames.get("="+word);
60 public string matching(string name) {
61 return this.matchingNames.get(name);
64 public bool isKeyword(string word) {
65 return this.keywordNames.get("=" + word) != null;
68 public string punc (string ch) {
69 return this.puncNames.get(ch); // ?? does [xxx] work!?
72 public bool isNumber (string str) {
73 return Regex.match_simple("^(\\.[0-9]|[0-9]+\\.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
76 public bool isHexDec (string str) {
77 return Regex.match_simple("^0x[0-9A-F]+$",str);
80 public bool isWordChar (string str) {
81 return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
84 public bool isSpace (string str) {
85 return this.whitespaceNames.get(str) != null;
87 public bool isSpaceC (char str) {
88 var s = str.to_string();
89 return this.whitespaceNames.get(s) != null;
92 public bool isNewline (string str) {
93 return this.newlineNames.get(str) != null;
95 public bool isNewlineC (char str) {
96 var s =str.to_string();
97 return this.newlineNames.get(s) != null;
99 public bool isBoolean (string str) {
101 return ss == "false" || ss == "true";
108 this.coreObjects = new GLib.List<string>();
110 this.whitespaceNames = new Gee.HashMap<string,string>();
111 this.newlineNames = new Gee.HashMap<string,string>();
112 this.keywordNames = new Gee.HashMap<string,string>();
113 this.puncNames = new Gee.HashMap<string,string>();
114 this.matchingNames = new Gee.HashMap<string,string>();
115 this.match_strings = new Gee.ArrayList<string>();
118 string[] co = { "_global_", "Array", "Boolean", "Date", "Error",
119 "Function", "Math", "Number", "Object", "RegExp", "String" };
120 for(var i =0; i< co.length;i++ ) {
121 this.coreObjects.append(co[i]);
122 this.match_strings.add(co[i]);
128 // "\u0009:UNICODE_TAB",
129 // "\u000A:UNICODE_NBR",
130 // "\u0008:VERTICAL_TAB"
132 for(var i =0; i< ws.length;i++ ) {
133 var x = ws[i].split(":");
134 this.whitespaceNames.set(x[0],x[1]);
140 // "\u000A:UNICODE_LF",
141 // "\u000D:UNICODE_CR",
142 // "\u2029:UNICODE_PS",
143 // "\u2028:UNICODE_LS"
145 for(var i =0; i< ws.length;i++ ) {
146 var x = ws[i].split(":");
147 this.newlineNames.set(x[0],x[1]);
154 "=continue:CONTINUE",
162 "=function:FUNCTION",
165 "=instanceof:INSTANCEOF",
180 for(var i =0; i< ws.length;i++ ) {
181 var x = ws[i].split(":");
182 this.keywordNames.set(x[0],x[1]);
183 this.match_strings.add(x[0].substring(1));
226 for(var i =0; i< ws.length;i++ ) {
227 var x = ws[i].split(" ");
228 this.puncNames.set(x[0],x[1]);
232 "LEFT_PAREN:RIGHT_PAREN",
233 "RIGHT_PAREN:LEFT_PAREN",
234 "LEFT_CURLY:RIGHT_CURLY",
235 "RIGHT_CURLY:LEFT_CURLY",
236 "LEFT_BRACE:RIGHT_BRACE",
237 "RIGHT_BRACE:LEFT_BRACE"
239 for(var i =0; i< wsp.length;i++ ) {
240 var x = wsp[i].split(":");
241 this.matchingNames.set(x[0],x[1]);