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");
18 public Lang_Class Lang = null;
20 public class Lang_Class : Object {
22 GLib.List<string> coreObjects;
23 Gee.HashMap<string,string> whitespaceNames;
24 Gee.HashMap<string,string> newlineNames;
25 Gee.HashMap<string,string> keywordNames;
26 Gee.HashMap<string,string> puncNames;
27 Gee.HashMap<string,string> matchingNames;
28 public Gee.ArrayList<string> match_strings;
33 //print("lang not null\n");
44 public bool isBuiltin(string name) {
45 return (this.coreObjects.index(name) > -1);
48 public string whitespace (string ch) {
49 return this.whitespaceNames.get(ch);
51 public string newline (string ch) {
52 return this.newlineNames.get(ch);
54 public string keyword(string word) {
55 return this.keywordNames.get("="+word);
58 public string matching(string name) {
59 return this.matchingNames.get(name);
62 public bool isKeyword(string word) {
63 return this.keywordNames.get("=" + word) != null;
66 public string punc (string ch) {
67 return this.puncNames[ch];
70 public bool isNumber (string str) {
71 return Regex.match_simple("^(\\.[0-9]|[0-9]+\\.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
74 public bool isHexDec (string str) {
75 return Regex.match_simple("^0x[0-9A-F]+$",str);
78 public bool isWordChar (string str) {
79 return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
82 public bool isSpace (string str) {
83 return this.whitespaceNames.get(str) != null;
86 public bool isNewline (string str) {
87 return this.newlineNames.get(str) != null;
89 public bool isBoolean (string str) {
91 return ss == "false" || ss == "true";
99 this.coreObjects = new GLib.List<string>();
101 this.whitespaceNames = new Gee.HashMap<string,string>();
102 this.newlineNames = new Gee.HashMap<string,string>();
103 this.keywordNames = new Gee.HashMap<string,string>();
104 this.puncNames = new Gee.HashMap<string,string>();
105 this.matchingNames = new Gee.HashMap<string,string>();
106 this.match_strings = new Gee.ArrayList<string>();
109 string[] co = { "_global_", "Array", "Boolean", "Date", "Error",
110 "Function", "Math", "Number", "Object", "RegExp", "String" };
111 for(var i =0; i< co.length;i++ ) {
112 this.coreObjects.append(co[i]);
118 // "\u0009:UNICODE_TAB",
119 // "\u000A:UNICODE_NBR",
120 // "\u0008:VERTICAL_TAB"
122 for(var i =0; i< ws.length;i++ ) {
123 var x = ws[i].split(":");
124 this.whitespaceNames.set(x[0],x[1]);
130 // "\u000A:UNICODE_LF",
131 // "\u000D:UNICODE_CR",
132 // "\u2029:UNICODE_PS",
133 // "\u2028:UNICODE_LS"
135 for(var i =0; i< ws.length;i++ ) {
136 var x = ws[i].split(":");
137 this.newlineNames.set(x[0],x[1]);
144 "=continue:CONTINUE",
152 "=function:FUNCTION",
155 "=instanceof:INSTANCEOF",
170 for(var i =0; i< ws.length;i++ ) {
171 var x = ws[i].split(":");
172 this.keywordNames.set(x[0],x[1]);
215 for(var i =0; i< ws.length;i++ ) {
216 var x = ws[i].split(" ");
217 this.puncNames.set(x[0],x[1]);
221 "LEFT_PAREN:RIGHT_PAREN",
222 "RIGHT_PAREN:LEFT_PAREN",
223 "LEFT_CURLY:RIGHT_CURLY",
224 "RIGHT_CURLY:LEFT_CURLY",
225 "LEFT_BRACE:RIGHT_BRACE",
226 "RIGHT_BRACE:LEFT_BRACE"
228 for(var i =0; i< ws.length;i++ ) {
229 var x = ws[i].split(":");
230 this.matchingNames.set(x[0],x[1]);