aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/highlight/languages/pygments/javascript.js
blob: d6c0a6b7d2c9f94482fb81f680f7703f68a6fa5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
if(!dojo._hasResource["dojox.highlight.languages.pygments.javascript"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.highlight.languages.pygments.javascript"] = true;
dojo.provide("dojox.highlight.languages.pygments.javascript");

dojo.require("dojox.highlight._base");

(function(){
	var dh = dojox.highlight, dhc = dh.constants;
	dh.languages.javascript = {
		defaultMode: {
			lexems: ["\\b[a-zA-Z]+"],
			keywords: {
				"keyword": {
					"for": 1, "in": 1, "while": 1, "do": 1, "break": 1, "return": 1,
					"continue": 1, "if": 1, "else": 1, "throw": 1, "try": 1,
		            "catch": 1, "var": 1, "with": 1, "const": 1, "label": 1,
					"function": 1, "new": 1, "typeof": 1, "instanceof": 1
				},
				"keyword constant": {
					"true": 1, "false": 1, "null": 1, "NaN": 1, "Infinity": 1, "undefined": 1
				},
				"name builtin": {
					"Array": 1, "Boolean": 1, "Date": 1, "Error": 1, "Function": 1, "Math": 1,
					"netscape": 1, "Number": 1, "Object": 1, "Packages": 1, "RegExp": 1,
					"String": 1, "sun": 1, "decodeURI": 1, "decodeURIComponent": 1, 
					"encodeURI": 1, "encodeURIComponent": 1, "Error": 1, "eval": 1, 
					"isFinite": 1, "isNaN": 1, "parseFloat": 1, "parseInt": 1, "document": 1,
					"window": 1
				},
				"name builtin pseudo": {
					"this": 1
				}
			},
			contains: [
				"comment single", "comment multiline", 
				"number integer", "number oct", "number hex", "number float",
				"string single", "string double", "string regex",
				"operator",
				"punctuation",
				//"name variable",
				"_function"
			]
		},
		modes: [
			// comments
			{
				className: "comment single",
				begin: "//", end: "$",
				relevance: 0
			},
			{
				className: "comment multiline",
				begin: "/\\*", end: "\\*/"
			},

			// numbers
			{
				className: "number integer",
				begin: "0|([1-9][0-9]*)", end: "^",
				relevance: 0
			},
			{
				className: "number oct",
				begin: "0[0-9]+", end: "^",
				relevance: 0
			},
			{
				className: "number hex",
				begin: "0x[0-9a-fA-F]+", end: "^",
				relevance: 0
			},
			{
				className: "number float",
				begin: "([1-9][0-9]*\\.[0-9]*([eE][\\+-]?[0-9]+)?)|(\\.[0-9]+([eE][\\+-]?[0-9]+)?)|([0-9]+[eE][\\+-]?[0-9]+)", end: "^",
				relevance: 0
			},

			// strings
			{
				className: "string single",
				begin: "'", end: "'",
				illegal: "\\n",
				contains: ["string escape"],
				relevance: 0
			},
			{
				className: "string double",
				begin: '"', 
				end: '"',
				illegal: "\\n",
				contains: ["string escape"],
				relevance: 0
			},
			{
				className: "string escape",
				begin: "\\\\.", end: "^",
				relevance: 0
			},
			{
				className: "string regex",
				begin: "/.*?[^\\\\/]/[gim]*", end: "^"
			},
			
			// operators
			{
				className: "operator",
				begin: "\\|\\||&&|\\+\\+|--|-=|\\+=|/=|\\*=|==|[-\\+\\*/=\\?:~\\^]", end: "^",
				relevance: 0
			},

			// punctuations
			{
				className: "punctuation",
				begin: "[{}\\(\\)\\[\\]\\.;]", end: "^",
				relevance: 0
			},
			
			// functions
			{
				className: "_function",
				begin: "function\\b", end: "{",
				lexems: [dhc.UNDERSCORE_IDENT_RE],
				keywords: {
					keyword: {
						"function": 1
					}
				},
				contains: ["name function", "_params"],
				relevance: 5
			},
			{
				className: "name function",
				begin: dhc.UNDERSCORE_IDENT_RE, end: '^'
			},
			{
				className: "_params",
				begin: "\\(", end: "\\)",
				contains: ["comment single", "comment multiline"]
			}
			/*
			// names
			{
				className: "name variable",
				begin: "\\b[$a-zA-Z_][$a-zA-Z0-9_]*", end: "^",
				relevance: 0
			}
			*/
		]
	};
})();

}