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");
16 public Lang_Class Lang = null;
18 public class Lang_Class : Object {
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;
29 //print("lang not null\n");
40 public bool isBuiltin(string name) {
41 return (this.coreObjects.index(name) > -1);
44 public string whitespace (string ch) {
45 return this.whitespaceNames.get(ch);
47 public string newline (string ch) {
48 return this.newlineNames.get(ch);
50 public string keyword(string word) {
51 return this.keywordNames.get("="+word);
54 public string matching(string name) {
55 return this.matchingNames.get(name);
58 public bool isKeyword(string word) {
59 return this.keywordNames.get("=" + word) != null;
62 public string punc (string ch) {
63 return this.puncNames[ch];
66 public bool isNumber (string str) {
67 return Regex.match_simple("^(\\.[0-9]|[0-9]+\\.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
70 public bool isHexDec (string str) {
71 return Regex.match_simple("^0x[0-9A-F]+$",str);
74 public bool isWordChar (string str) {
75 return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
78 public bool isSpace (string str) {
79 return this.whitespaceNames.get(str) != null;
82 public bool isNewline (string str) {
83 return this.newlineNames.get(str) != null;
85 public bool isBoolean (string str) {
87 return ss == "false" || ss == "true";
93 this.coreObjects = new GLib.List<string>();
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>();
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]);
112 // "\u0009:UNICODE_TAB",
113 // "\u000A:UNICODE_NBR",
114 // "\u0008:VERTICAL_TAB"
116 for(var i =0; i< ws.length;i++ ) {
117 var x = ws[i].split(":");
118 this.whitespaceNames.set(x[0],x[1]);
124 // "\u000A:UNICODE_LF",
125 // "\u000D:UNICODE_CR",
126 // "\u2029:UNICODE_PS",
127 // "\u2028:UNICODE_LS"
129 for(var i =0; i< ws.length;i++ ) {
130 var x = ws[i].split(":");
131 this.newlineNames.set(x[0],x[1]);
138 "=continue:CONTINUE",
146 "=function:FUNCTION",
149 "=instanceof:INSTANCEOF",
164 for(var i =0; i< ws.length;i++ ) {
165 var x = ws[i].split(":");
166 this.keywordNames.set(x[0],x[1]);
209 for(var i =0; i< ws.length;i++ ) {
210 var x = ws[i].split(" ");
211 this.puncNames.set(x[0],x[1]);
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"
222 for(var i =0; i< ws.length;i++ ) {
223 var x = ws[i].split(":");
224 this.matchingNames.set(x[0],x[1]);