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) {
64 case "LEFT_PAREN": return "RIGHT_PAREN";
65 case "RIGHT_PAREN": return "LEFT_PAREN";
66 case "LEFT_CURLY": return "RIGHT_CURLY";
67 case "RIGHT_CURLY": return "LEFT_CURLY";
68 case "LEFT_BRACE": return "RIGHT_BRACE";
69 case "RIGHT_BRACE": return "LEFT_BRACE";
74 //return this.matchingNames.get(name);
77 public bool isKeyword(string word) {
78 return this.keywordNames.get("=" + word) != null;
81 public string punc (string ch) {
82 return this.puncNames.get(ch); // ?? does [xxx] work!?
85 public bool isNumber (string str) {
86 return Regex.match_simple("^(\\.[0-9]|[0-9]+\\.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
89 public bool isHexDec (string str) {
90 return Regex.match_simple("^0x[0-9A-F]+$",str);
93 public bool isWordChar (string str) {
94 return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
97 public bool isSpace (string str) {
98 return this.whitespaceNames.get(str) != null;
100 public bool isSpaceC (char str) {
101 var s = str.to_string();
102 return this.whitespaceNames.get(s) != null;
105 public bool isNewline (string str) {
106 return this.newlineNames.get(str) != null;
108 public bool isNewlineC (char str) {
109 var s =str.to_string();
110 return this.newlineNames.get(s) != null;
112 public bool isBoolean (string str) {
114 return ss == "false" || ss == "true";
121 this.coreObjects = new GLib.List<string>();
123 this.whitespaceNames = new Gee.HashMap<string,string>();
124 this.newlineNames = new Gee.HashMap<string,string>();
125 this.keywordNames = new Gee.HashMap<string,string>();
126 this.puncNames = new Gee.HashMap<string,string>();
127 this.matchingNames = new Gee.HashMap<string,string>();
128 this.match_strings = new Gee.ArrayList<string>();
131 string[] co = { "_global_", "Array", "Boolean", "Date", "Error",
132 "Function", "Math", "Number", "Object", "RegExp", "String" };
133 for(var i =0; i< co.length;i++ ) {
134 this.coreObjects.append(co[i]);
135 this.match_strings.add(co[i]);
141 // "\u0009:UNICODE_TAB",
142 // "\u000A:UNICODE_NBR",
143 // "\u0008:VERTICAL_TAB"
145 for(var i =0; i< ws.length;i++ ) {
146 var x = ws[i].split(":");
147 this.whitespaceNames.set(x[0],x[1]);
153 // "\u000A:UNICODE_LF",
154 // "\u000D:UNICODE_CR",
155 // "\u2029:UNICODE_PS",
156 // "\u2028:UNICODE_LS"
158 for(var i =0; i< ws.length;i++ ) {
159 var x = ws[i].split(":");
160 this.newlineNames.set(x[0],x[1]);
167 "=continue:CONTINUE",
175 "=function:FUNCTION",
178 "=instanceof:INSTANCEOF",
193 for(var i =0; i< ws.length;i++ ) {
194 var x = ws[i].split(":");
195 this.keywordNames.set(x[0],x[1]);
196 this.match_strings.add(x[0].substring(1));
239 for(var i =0; i< ws.length;i++ ) {
240 var x = ws[i].split(" ");
241 this.puncNames.set(x[0],x[1]);
245 "LEFT_PAREN:RIGHT_PAREN",
246 "RIGHT_PAREN:LEFT_PAREN",
247 "LEFT_CURLY:RIGHT_CURLY",
248 "RIGHT_CURLY:LEFT_CURLY",
249 "LEFT_BRACE:RIGHT_BRACE",
250 "RIGHT_BRACE:LEFT_BRACE"
252 for(var i =0; i< wsp.length;i++ ) {
253 var x = wsp[i].split(":");
254 this.matchingNames.set(x[0],x[1]);