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");
45 public bool isBuiltin(string name) {
46 return (this.coreObjects.index(name) > -1);
49 public string whitespace (string ch) {
50 return this.whitespaceNames.get(ch);
52 public string newline (string ch) {
53 return this.newlineNames.get(ch);
55 public string keyword(string word) {
56 return this.keywordNames.get("="+word);
59 public string matching(string name) {
60 return this.matchingNames.get(name);
63 public bool isKeyword(string word) {
64 return this.keywordNames.get("=" + word) != null;
67 public string punc (string ch) {
68 return this.puncNames[ch];
71 public bool isNumber (string str) {
72 return Regex.match_simple("^(\\.[0-9]|[0-9]+\\.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
75 public bool isHexDec (string str) {
76 return Regex.match_simple("^0x[0-9A-F]+$",str);
79 public bool isWordChar (string str) {
80 return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
83 public bool isSpace (string str) {
84 return this.whitespaceNames.get(str) != null;
87 public bool isNewline (string str) {
88 return this.newlineNames.get(str) != null;
90 public bool isBoolean (string str) {
92 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]);
113 this.match_strings.add(co[i]);
119 // "\u0009:UNICODE_TAB",
120 // "\u000A:UNICODE_NBR",
121 // "\u0008:VERTICAL_TAB"
123 for(var i =0; i< ws.length;i++ ) {
124 var x = ws[i].split(":");
125 this.whitespaceNames.set(x[0],x[1]);
131 // "\u000A:UNICODE_LF",
132 // "\u000D:UNICODE_CR",
133 // "\u2029:UNICODE_PS",
134 // "\u2028:UNICODE_LS"
136 for(var i =0; i< ws.length;i++ ) {
137 var x = ws[i].split(":");
138 this.newlineNames.set(x[0],x[1]);
145 "=continue:CONTINUE",
153 "=function:FUNCTION",
156 "=instanceof:INSTANCEOF",
171 for(var i =0; i< ws.length;i++ ) {
172 var x = ws[i].split(":");
173 this.keywordNames.set(x[0],x[1]);
174 this.match_strings.add(x[0].substring(1));
217 for(var i =0; i< ws.length;i++ ) {
218 var x = ws[i].split(" ");
219 this.puncNames.set(x[0],x[1]);
223 "LEFT_PAREN:RIGHT_PAREN",
224 "RIGHT_PAREN:LEFT_PAREN",
225 "LEFT_CURLY:RIGHT_CURLY",
226 "RIGHT_CURLY:LEFT_CURLY",
227 "LEFT_BRACE:RIGHT_BRACE",
228 "RIGHT_BRACE:LEFT_BRACE"
230 for(var i =0; i< ws.length;i++ ) {
231 var x = ws[i].split(":");
232 this.matchingNames.set(x[0],x[1]);