sync fixes
[app.jsdoc] / JSDOC / Lang.js
1 //<script type="text/javscript">
2
3 /**
4 * Language related methods (eg. what's a token...)
5 *
6 * @scope JSDOC
7 * @class Lang
8 * @static
9 */
10 Lang = {
11     
12     
13     isBuiltin : function(name) {
14         return (this.coreObjects.indexOf(name) > -1);
15     }, 
16     coreObjects : ['_global_', 'Array', 'Boolean', 'Date', 'Error', 
17         'Function', 'Math', 'Number', 'Object', 'RegExp', 'String'],
18         
19
20     whitespace : function(ch) {
21         return this.whitespaceNames[ch];
22     },
23     
24     whitespaceNames : {
25         " ":      "SPACE",
26         "\f":     "FORMFEED",
27         "\t":     "TAB",
28         "\u0009": "UNICODE_TAB",
29         "\u000A": "UNICODE_NBR",
30         "\u0008": "VERTICAL_TAB"
31     },
32
33     newline : function(ch) {
34         return this.newlineNames[ch];
35     },
36     newlineNames : {
37         "\n":     "NEWLINE",
38         "\r":     "RETURN",
39         "\u000A": "UNICODE_LF",
40         "\u000D": "UNICODE_CR",
41         "\u2029": "UNICODE_PS",
42         "\u2028": "UNICODE_LS"
43     },
44
45     keyword : function(word) {
46         return this.keywordNames["="+word];
47     },
48     isKeyword: function(word) {
49         return typeof(this.keywordNames["="+word]) == 'undefined' ? false : true;
50     },
51
52     keywordNames : {
53         "=break":      "BREAK",
54         "=case":       "CASE",
55         "=catch":      "CATCH",
56         "=const":      "VAR",
57         "=continue":   "CONTINUE",
58         "=default":    "DEFAULT",
59         "=delete":     "DELETE",
60         "=do":         "DO",
61         "=else":       "ELSE",
62         "=eval":       "EVAL",
63         "=false":      "FALSE",
64         "=finally":    "FINALLY",
65         "=for":        "FOR",
66         "=function":   "FUNCTION",
67         "=if":         "IF",
68         "=in":         "IN",
69         "=instanceof": "INSTANCEOF",
70         "=new":        "NEW",
71         "=null":       "NULL",
72         "=return":     "RETURN",
73         "=switch":     "SWITCH",
74         "=this":       "THIS",
75         "=throw":      "THROW",
76         "=true":       "TRUE",
77         "=try":        "TRY",
78         "=typeof":     "TYPEOF",
79         "=void":       "VOID",
80         "=while":      "WHILE",
81         "=with":       "WITH",
82         "=var":        "VAR"
83     },
84
85     punc : function(ch) {
86         return this.puncNames[ch];
87     },
88     puncNames : {
89         ";":   "SEMICOLON",
90         ",":   "COMMA",
91         "?":   "HOOK",
92         ":":   "COLON",
93         "||":  "OR", 
94         "&&":  "AND",
95         "|":   "BITWISE_OR",
96         "^":   "BITWISE_XOR",
97         "&":   "BITWISE_AND",
98         "===": "STRICT_EQ", 
99         "==":  "EQ",
100         "=":   "ASSIGN",
101         "!==": "STRICT_NE",
102         "!=":  "NE",
103         "<<":  "LSH",
104         "<=":  "LE", 
105         "<":   "LT",
106         ">>>": "URSH",
107         ">>":  "RSH",
108         ">=":  "GE",
109         ">":   "GT", 
110         "++":  "INCREMENT",
111         "--":  "DECREMENT",
112         "+":   "PLUS",
113         "-":   "MINUS",
114         "*":   "MUL",
115         "/":   "DIV", 
116         "%":   "MOD",
117         "!":   "NOT",
118         "~":   "BITWISE_NOT",
119         ".":   "DOT",
120         "[":   "LEFT_BRACE",
121         "]":   "RIGHT_BRACE",
122         "{":   "LEFT_CURLY",
123         "}":   "RIGHT_CURLY",
124         "(":   "LEFT_PAREN",
125         ")":   "RIGHT_PAREN"
126     },
127
128     matching : function(name) {
129         name = typeof(this.puncNames[name]) == 'undefined' ? name : this.puncNames[name];
130         
131         return this.matchingNames[name];
132     },
133     matchingNames : {
134         "LEFT_PAREN": "RIGHT_PAREN",
135         "RIGHT_PAREN": "LEFT_PAREN",
136         "LEFT_CURLY": "RIGHT_CURLY",
137         "RIGHT_CURLY": "LEFT_CURLY",
138         "LEFT_BRACE": "RIGHT_BRACE",
139         "RIGHT_BRACE": "LEFT_BRACE"
140     },
141
142     isNumber : function(str) {
143         return /^(\.[0-9]|[0-9]+\.|[0-9])[0-9]*([eE][+-][0-9]+)?$/i.test(str);
144     },
145
146     isHexDec : function(str) {
147         return /^0x[0-9A-F]+$/i.test(str);
148     },
149
150     isWordChar : function(str) {
151         return /^[a-zA-Z0-9$_.]+$/.test(str);
152     },
153
154     isSpace : function(str) {
155         return (typeof this.whitespace(str) != "undefined");
156     },
157
158     isNewline : function(str) {
159         return (typeof this.newline(str) != "undefined");
160     }
161     
162 };