liquid_cms 0.2.1.1 → 0.2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +7 -0
- data/README.rdoc +15 -1
- data/TODO.rdoc +0 -2
- data/app/controllers/cms/assets_controller.rb +20 -6
- data/app/controllers/cms/components_controller.rb +11 -3
- data/app/controllers/cms/pages_controller.rb +15 -4
- data/app/helpers/cms/common_helper.rb +31 -31
- data/app/liquid/cms_paperclip_extension.rb +75 -3
- data/app/models/cms/asset.rb +1 -1
- data/app/models/cms/component.rb +3 -3
- data/app/views/cms/assets/_form.html.erb +1 -1
- data/app/views/cms/assets/update.js.rjs +1 -0
- data/app/views/cms/components/update.js.rjs +1 -0
- data/app/views/cms/pages/_form.html.erb +1 -1
- data/app/views/cms/pages/update.js.rjs +1 -0
- data/app/views/layouts/cms.html.erb +4 -3
- data/generators/liquid_cms/liquid_cms_generator.rb +1 -0
- data/generators/liquid_cms/templates/config/locales/cms/en.yml +4 -0
- data/generators/liquid_cms/templates/migration_rev2.rb +13 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/LICENSE +16 -20
- data/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.css +68 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.js +2197 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/lib/overlay.js +51 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/lib/runmode.js +27 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/clike.js +247 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/index.html +102 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/clojure.js +207 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/index.html +85 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/LICENSE +22 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/coffeescript.js +325 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/index.html +722 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/css/css.js +124 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/css/index.html +56 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.css +3 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.js +13 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/index.html +99 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/haskell.js +242 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/index.html +60 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/index.html +52 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/index.html +78 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/javascript.js +352 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/index.html +38 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/jinja2.js +42 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/index.html +72 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/lua.js +140 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/index.html +340 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.css +10 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.js +230 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/index.html +33 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/ntriples.js +172 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/LICENSE +7 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/index.html +49 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/pascal.js +138 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/php/index.html +49 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/php/php.js +116 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/index.html +63 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/plsql.js +217 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/LICENSE.txt +21 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/index.html +123 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/python.js +320 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/LICENSE +24 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/index.html +74 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/r.js +141 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/index.html +526 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.css +75 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.js +333 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/LICENSE +24 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/index.html +172 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/ruby.js +195 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/index.html +65 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/scheme.js +202 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/index.html +56 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/smalltalk.js +122 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/index.html +41 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/sparql.js +143 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/index.html +96 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/stex.js +167 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/index.html +103 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/velocity.js +146 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/index.html +42 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/xml.js +231 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/index.html +60 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/xmlpure.js +481 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/index.html +68 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/yaml.js +95 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/theme/cobalt.css +17 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/theme/default.css +19 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/theme/eclipse.css +24 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/theme/elegant.css +9 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/theme/neat.css +8 -0
- data/generators/liquid_cms/templates/public/cms/codemirror/theme/night.css +20 -0
- data/generators/liquid_cms/templates/public/cms/javascripts/cms.js +1 -1
- data/generators/liquid_cms/templates/public/cms/javascripts/codemirror_custom.js +96 -0
- data/generators/liquid_cms/templates/public/cms/stylesheets/codemirror_changes.css +26 -0
- data/generators/liquid_cms/templates/public/cms/stylesheets/liquid.css +7 -0
- data/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +0 -8
- data/lib/liquid_cms/version.rb +1 -1
- data/liquid_cms.gemspec +0 -1
- data/test/functional/assets_controller_test.rb +35 -20
- data/test/functional/components_controller_test.rb +15 -5
- data/test/functional/pages_controller_test.rb +19 -6
- data/test/rails_app/config/environment.rb +1 -1
- data/test/rails_app/config/locales/cms/en.yml +19 -4
- data/test/rails_app/db/migrate/20110511161859_create_liquid_cms_upgrade_rev2.rb +13 -0
- data/test/unit/asset_test.rb +1 -1
- metadata +100 -58
- data/generators/liquid_cms/templates/public/cms/codemirror/css/csscolors.css +0 -55
- data/generators/liquid_cms/templates/public/cms/codemirror/css/docs.css +0 -158
- data/generators/liquid_cms/templates/public/cms/codemirror/css/font.js +0 -15
- data/generators/liquid_cms/templates/public/cms/codemirror/css/jscolors.css +0 -59
- data/generators/liquid_cms/templates/public/cms/codemirror/css/sparqlcolors.css +0 -43
- data/generators/liquid_cms/templates/public/cms/codemirror/css/xmlcolors.css +0 -55
- data/generators/liquid_cms/templates/public/cms/codemirror/js/codemirror.js +0 -582
- data/generators/liquid_cms/templates/public/cms/codemirror/js/editor.js +0 -1671
- data/generators/liquid_cms/templates/public/cms/codemirror/js/highlight.js +0 -68
- data/generators/liquid_cms/templates/public/cms/codemirror/js/mirrorframe.js +0 -81
- data/generators/liquid_cms/templates/public/cms/codemirror/js/parsecss.js +0 -161
- data/generators/liquid_cms/templates/public/cms/codemirror/js/parsedummy.js +0 -32
- data/generators/liquid_cms/templates/public/cms/codemirror/js/parsehtmlmixed.js +0 -93
- data/generators/liquid_cms/templates/public/cms/codemirror/js/parsejavascript.js +0 -359
- data/generators/liquid_cms/templates/public/cms/codemirror/js/parsesparql.js +0 -162
- data/generators/liquid_cms/templates/public/cms/codemirror/js/parsexml.js +0 -291
- data/generators/liquid_cms/templates/public/cms/codemirror/js/select.js +0 -699
- data/generators/liquid_cms/templates/public/cms/codemirror/js/stringstream.js +0 -159
- data/generators/liquid_cms/templates/public/cms/codemirror/js/tokenize.js +0 -57
- data/generators/liquid_cms/templates/public/cms/codemirror/js/tokenizejavascript.js +0 -174
- data/generators/liquid_cms/templates/public/cms/codemirror/js/undo.js +0 -413
- data/generators/liquid_cms/templates/public/cms/codemirror/js/unittests.js +0 -44
- data/generators/liquid_cms/templates/public/cms/codemirror/js/util.js +0 -133
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/* String streams are the things fed to parsers (which can feed them
|
|
2
|
-
* to a tokenizer if they want). They provide peek and next methods
|
|
3
|
-
* for looking at the current character (next 'consumes' this
|
|
4
|
-
* character, peek does not), and a get method for retrieving all the
|
|
5
|
-
* text that was consumed since the last time get was called.
|
|
6
|
-
*
|
|
7
|
-
* An easy mistake to make is to let a StopIteration exception finish
|
|
8
|
-
* the token stream while there are still characters pending in the
|
|
9
|
-
* string stream (hitting the end of the buffer while parsing a
|
|
10
|
-
* token). To make it easier to detect such errors, the stringstreams
|
|
11
|
-
* throw an exception when this happens.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// Make a stringstream stream out of an iterator that returns strings.
|
|
15
|
-
// This is applied to the result of traverseDOM (see codemirror.js),
|
|
16
|
-
// and the resulting stream is fed to the parser.
|
|
17
|
-
var stringStream = function(source){
|
|
18
|
-
// String that's currently being iterated over.
|
|
19
|
-
var current = "";
|
|
20
|
-
// Position in that string.
|
|
21
|
-
var pos = 0;
|
|
22
|
-
// Accumulator for strings that have been iterated over but not
|
|
23
|
-
// get()-ed yet.
|
|
24
|
-
var accum = "";
|
|
25
|
-
// Make sure there are more characters ready, or throw
|
|
26
|
-
// StopIteration.
|
|
27
|
-
function ensureChars() {
|
|
28
|
-
while (pos == current.length) {
|
|
29
|
-
accum += current;
|
|
30
|
-
current = ""; // In case source.next() throws
|
|
31
|
-
pos = 0;
|
|
32
|
-
try {current = source.next();}
|
|
33
|
-
catch (e) {
|
|
34
|
-
if (e != StopIteration) throw e;
|
|
35
|
-
else return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
// peek: -> character
|
|
43
|
-
// Return the next character in the stream.
|
|
44
|
-
peek: function() {
|
|
45
|
-
if (!ensureChars()) return null;
|
|
46
|
-
return current.charAt(pos);
|
|
47
|
-
},
|
|
48
|
-
// next: -> character
|
|
49
|
-
// Get the next character, throw StopIteration if at end, check
|
|
50
|
-
// for unused content.
|
|
51
|
-
next: function() {
|
|
52
|
-
if (!ensureChars()) {
|
|
53
|
-
if (accum.length > 0)
|
|
54
|
-
throw "End of stringstream reached without emptying buffer ('" + accum + "').";
|
|
55
|
-
else
|
|
56
|
-
throw StopIteration;
|
|
57
|
-
}
|
|
58
|
-
return current.charAt(pos++);
|
|
59
|
-
},
|
|
60
|
-
// get(): -> string
|
|
61
|
-
// Return the characters iterated over since the last call to
|
|
62
|
-
// .get().
|
|
63
|
-
get: function() {
|
|
64
|
-
var temp = accum;
|
|
65
|
-
accum = "";
|
|
66
|
-
if (pos > 0){
|
|
67
|
-
temp += current.slice(0, pos);
|
|
68
|
-
current = current.slice(pos);
|
|
69
|
-
pos = 0;
|
|
70
|
-
}
|
|
71
|
-
return temp;
|
|
72
|
-
},
|
|
73
|
-
// Push a string back into the stream.
|
|
74
|
-
push: function(str) {
|
|
75
|
-
current = current.slice(0, pos) + str + current.slice(pos);
|
|
76
|
-
},
|
|
77
|
-
lookAhead: function(str, consume, skipSpaces, caseInsensitive) {
|
|
78
|
-
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
|
79
|
-
str = cased(str);
|
|
80
|
-
var found = false;
|
|
81
|
-
|
|
82
|
-
var _accum = accum, _pos = pos;
|
|
83
|
-
if (skipSpaces) this.nextWhileMatches(/[\s\u00a0]/);
|
|
84
|
-
|
|
85
|
-
while (true) {
|
|
86
|
-
var end = pos + str.length, left = current.length - pos;
|
|
87
|
-
if (end <= current.length) {
|
|
88
|
-
found = str == cased(current.slice(pos, end));
|
|
89
|
-
pos = end;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
else if (str.slice(0, left) == cased(current.slice(pos))) {
|
|
93
|
-
accum += current; current = "";
|
|
94
|
-
try {current = source.next();}
|
|
95
|
-
catch (e) {if (e != StopIteration) throw e; break;}
|
|
96
|
-
pos = 0;
|
|
97
|
-
str = str.slice(left);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!(found && consume)) {
|
|
105
|
-
current = accum.slice(_accum.length) + current;
|
|
106
|
-
pos = _pos;
|
|
107
|
-
accum = _accum;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return found;
|
|
111
|
-
},
|
|
112
|
-
// Wont't match past end of line.
|
|
113
|
-
lookAheadRegex: function(regex, consume) {
|
|
114
|
-
if (regex.source.charAt(0) != "^")
|
|
115
|
-
throw new Error("Regexps passed to lookAheadRegex must start with ^");
|
|
116
|
-
|
|
117
|
-
// Fetch the rest of the line
|
|
118
|
-
while (current.indexOf("\n", pos) == -1) {
|
|
119
|
-
try {current += source.next();}
|
|
120
|
-
catch (e) {if (e != StopIteration) throw e; break;}
|
|
121
|
-
}
|
|
122
|
-
var matched = current.slice(pos).match(regex);
|
|
123
|
-
if (matched && consume) pos += matched[0].length;
|
|
124
|
-
return matched;
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
// Utils built on top of the above
|
|
128
|
-
// more: -> boolean
|
|
129
|
-
// Produce true if the stream isn't empty.
|
|
130
|
-
more: function() {
|
|
131
|
-
return this.peek() !== null;
|
|
132
|
-
},
|
|
133
|
-
applies: function(test) {
|
|
134
|
-
var next = this.peek();
|
|
135
|
-
return (next !== null && test(next));
|
|
136
|
-
},
|
|
137
|
-
nextWhile: function(test) {
|
|
138
|
-
var next;
|
|
139
|
-
while ((next = this.peek()) !== null && test(next))
|
|
140
|
-
this.next();
|
|
141
|
-
},
|
|
142
|
-
matches: function(re) {
|
|
143
|
-
var next = this.peek();
|
|
144
|
-
return (next !== null && re.test(next));
|
|
145
|
-
},
|
|
146
|
-
nextWhileMatches: function(re) {
|
|
147
|
-
var next;
|
|
148
|
-
while ((next = this.peek()) !== null && re.test(next))
|
|
149
|
-
this.next();
|
|
150
|
-
},
|
|
151
|
-
equals: function(ch) {
|
|
152
|
-
return ch === this.peek();
|
|
153
|
-
},
|
|
154
|
-
endOfLine: function() {
|
|
155
|
-
var next = this.peek();
|
|
156
|
-
return next == null || next == "\n";
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// A framework for simple tokenizers. Takes care of newlines and
|
|
2
|
-
// white-space, and of getting the text from the source stream into
|
|
3
|
-
// the token object. A state is a function of two arguments -- a
|
|
4
|
-
// string stream and a setState function. The second can be used to
|
|
5
|
-
// change the tokenizer's state, and can be ignored for stateless
|
|
6
|
-
// tokenizers. This function should advance the stream over a token
|
|
7
|
-
// and return a string or object containing information about the next
|
|
8
|
-
// token, or null to pass and have the (new) state be called to finish
|
|
9
|
-
// the token. When a string is given, it is wrapped in a {style, type}
|
|
10
|
-
// object. In the resulting object, the characters consumed are stored
|
|
11
|
-
// under the content property. Any whitespace following them is also
|
|
12
|
-
// automatically consumed, and added to the value property. (Thus,
|
|
13
|
-
// content is the actual meaningful part of the token, while value
|
|
14
|
-
// contains all the text it spans.)
|
|
15
|
-
|
|
16
|
-
function tokenizer(source, state) {
|
|
17
|
-
// Newlines are always a separate token.
|
|
18
|
-
function isWhiteSpace(ch) {
|
|
19
|
-
// The messy regexp is because IE's regexp matcher is of the
|
|
20
|
-
// opinion that non-breaking spaces are no whitespace.
|
|
21
|
-
return ch != "\n" && /^[\s\u00a0]*$/.test(ch);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var tokenizer = {
|
|
25
|
-
state: state,
|
|
26
|
-
|
|
27
|
-
take: function(type) {
|
|
28
|
-
if (typeof(type) == "string")
|
|
29
|
-
type = {style: type, type: type};
|
|
30
|
-
|
|
31
|
-
type.content = (type.content || "") + source.get();
|
|
32
|
-
if (!/\n$/.test(type.content))
|
|
33
|
-
source.nextWhile(isWhiteSpace);
|
|
34
|
-
type.value = type.content + source.get();
|
|
35
|
-
return type;
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
next: function () {
|
|
39
|
-
if (!source.more()) throw StopIteration;
|
|
40
|
-
|
|
41
|
-
var type;
|
|
42
|
-
if (source.equals("\n")) {
|
|
43
|
-
source.next();
|
|
44
|
-
return this.take("whitespace");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (source.applies(isWhiteSpace))
|
|
48
|
-
type = "whitespace";
|
|
49
|
-
else
|
|
50
|
-
while (!type)
|
|
51
|
-
type = this.state(source, function(s) {tokenizer.state = s;});
|
|
52
|
-
|
|
53
|
-
return this.take(type);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
return tokenizer;
|
|
57
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/* Tokenizer for JavaScript code */
|
|
2
|
-
|
|
3
|
-
var tokenizeJavaScript = (function() {
|
|
4
|
-
// Advance the stream until the given character (not preceded by a
|
|
5
|
-
// backslash) is encountered, or the end of the line is reached.
|
|
6
|
-
function nextUntilUnescaped(source, end) {
|
|
7
|
-
var escaped = false;
|
|
8
|
-
while (!source.endOfLine()) {
|
|
9
|
-
var next = source.next();
|
|
10
|
-
if (next == end && !escaped)
|
|
11
|
-
return false;
|
|
12
|
-
escaped = !escaped && next == "\\";
|
|
13
|
-
}
|
|
14
|
-
return escaped;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// A map of JavaScript's keywords. The a/b/c keyword distinction is
|
|
18
|
-
// very rough, but it gives the parser enough information to parse
|
|
19
|
-
// correct code correctly (we don't care that much how we parse
|
|
20
|
-
// incorrect code). The style information included in these objects
|
|
21
|
-
// is used by the highlighter to pick the correct CSS style for a
|
|
22
|
-
// token.
|
|
23
|
-
var keywords = function(){
|
|
24
|
-
function result(type, style){
|
|
25
|
-
return {type: type, style: "js-" + style};
|
|
26
|
-
}
|
|
27
|
-
// keywords that take a parenthised expression, and then a
|
|
28
|
-
// statement (if)
|
|
29
|
-
var keywordA = result("keyword a", "keyword");
|
|
30
|
-
// keywords that take just a statement (else)
|
|
31
|
-
var keywordB = result("keyword b", "keyword");
|
|
32
|
-
// keywords that optionally take an expression, and form a
|
|
33
|
-
// statement (return)
|
|
34
|
-
var keywordC = result("keyword c", "keyword");
|
|
35
|
-
var operator = result("operator", "keyword");
|
|
36
|
-
var atom = result("atom", "atom");
|
|
37
|
-
return {
|
|
38
|
-
"if": keywordA, "while": keywordA, "with": keywordA,
|
|
39
|
-
"else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB,
|
|
40
|
-
"return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC,
|
|
41
|
-
"in": operator, "typeof": operator, "instanceof": operator,
|
|
42
|
-
"var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"),
|
|
43
|
-
"for": result("for", "keyword"), "switch": result("switch", "keyword"),
|
|
44
|
-
"case": result("case", "keyword"), "default": result("default", "keyword"),
|
|
45
|
-
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
|
46
|
-
};
|
|
47
|
-
}();
|
|
48
|
-
|
|
49
|
-
// Some helper regexps
|
|
50
|
-
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
|
51
|
-
var isHexDigit = /[0-9A-Fa-f]/;
|
|
52
|
-
var isWordChar = /[\w\$_]/;
|
|
53
|
-
|
|
54
|
-
// Wrapper around jsToken that helps maintain parser state (whether
|
|
55
|
-
// we are inside of a multi-line comment and whether the next token
|
|
56
|
-
// could be a regular expression).
|
|
57
|
-
function jsTokenState(inside, regexp) {
|
|
58
|
-
return function(source, setState) {
|
|
59
|
-
var newInside = inside;
|
|
60
|
-
var type = jsToken(inside, regexp, source, function(c) {newInside = c;});
|
|
61
|
-
var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/);
|
|
62
|
-
if (newRegexp != regexp || newInside != inside)
|
|
63
|
-
setState(jsTokenState(newInside, newRegexp));
|
|
64
|
-
return type;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// The token reader, intended to be used by the tokenizer from
|
|
69
|
-
// tokenize.js (through jsTokenState). Advances the source stream
|
|
70
|
-
// over a token, and returns an object containing the type and style
|
|
71
|
-
// of that token.
|
|
72
|
-
function jsToken(inside, regexp, source, setInside) {
|
|
73
|
-
function readHexNumber(){
|
|
74
|
-
source.next(); // skip the 'x'
|
|
75
|
-
source.nextWhileMatches(isHexDigit);
|
|
76
|
-
return {type: "number", style: "js-atom"};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function readNumber() {
|
|
80
|
-
source.nextWhileMatches(/[0-9]/);
|
|
81
|
-
if (source.equals(".")){
|
|
82
|
-
source.next();
|
|
83
|
-
source.nextWhileMatches(/[0-9]/);
|
|
84
|
-
}
|
|
85
|
-
if (source.equals("e") || source.equals("E")){
|
|
86
|
-
source.next();
|
|
87
|
-
if (source.equals("-"))
|
|
88
|
-
source.next();
|
|
89
|
-
source.nextWhileMatches(/[0-9]/);
|
|
90
|
-
}
|
|
91
|
-
return {type: "number", style: "js-atom"};
|
|
92
|
-
}
|
|
93
|
-
// Read a word, look it up in keywords. If not found, it is a
|
|
94
|
-
// variable, otherwise it is a keyword of the type found.
|
|
95
|
-
function readWord() {
|
|
96
|
-
source.nextWhileMatches(isWordChar);
|
|
97
|
-
var word = source.get();
|
|
98
|
-
var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word];
|
|
99
|
-
return known ? {type: known.type, style: known.style, content: word} :
|
|
100
|
-
{type: "variable", style: "js-variable", content: word};
|
|
101
|
-
}
|
|
102
|
-
function readRegexp() {
|
|
103
|
-
nextUntilUnescaped(source, "/");
|
|
104
|
-
source.nextWhileMatches(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
|
105
|
-
return {type: "regexp", style: "js-string"};
|
|
106
|
-
}
|
|
107
|
-
// Mutli-line comments are tricky. We want to return the newlines
|
|
108
|
-
// embedded in them as regular newline tokens, and then continue
|
|
109
|
-
// returning a comment token for every line of the comment. So
|
|
110
|
-
// some state has to be saved (inside) to indicate whether we are
|
|
111
|
-
// inside a /* */ sequence.
|
|
112
|
-
function readMultilineComment(start){
|
|
113
|
-
var newInside = "/*";
|
|
114
|
-
var maybeEnd = (start == "*");
|
|
115
|
-
while (true) {
|
|
116
|
-
if (source.endOfLine())
|
|
117
|
-
break;
|
|
118
|
-
var next = source.next();
|
|
119
|
-
if (next == "/" && maybeEnd){
|
|
120
|
-
newInside = null;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
maybeEnd = (next == "*");
|
|
124
|
-
}
|
|
125
|
-
setInside(newInside);
|
|
126
|
-
return {type: "comment", style: "js-comment"};
|
|
127
|
-
}
|
|
128
|
-
function readOperator() {
|
|
129
|
-
source.nextWhileMatches(isOperatorChar);
|
|
130
|
-
return {type: "operator", style: "js-operator"};
|
|
131
|
-
}
|
|
132
|
-
function readString(quote) {
|
|
133
|
-
var endBackSlash = nextUntilUnescaped(source, quote);
|
|
134
|
-
setInside(endBackSlash ? quote : null);
|
|
135
|
-
return {type: "string", style: "js-string"};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Fetch the next token. Dispatches on first character in the
|
|
139
|
-
// stream, or first two characters when the first is a slash.
|
|
140
|
-
if (inside == "\"" || inside == "'")
|
|
141
|
-
return readString(inside);
|
|
142
|
-
var ch = source.next();
|
|
143
|
-
if (inside == "/*")
|
|
144
|
-
return readMultilineComment(ch);
|
|
145
|
-
else if (ch == "\"" || ch == "'")
|
|
146
|
-
return readString(ch);
|
|
147
|
-
// with punctuation, the type of the token is the symbol itself
|
|
148
|
-
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
|
149
|
-
return {type: ch, style: "js-punctuation"};
|
|
150
|
-
else if (ch == "0" && (source.equals("x") || source.equals("X")))
|
|
151
|
-
return readHexNumber();
|
|
152
|
-
else if (/[0-9]/.test(ch))
|
|
153
|
-
return readNumber();
|
|
154
|
-
else if (ch == "/"){
|
|
155
|
-
if (source.equals("*"))
|
|
156
|
-
{ source.next(); return readMultilineComment(ch); }
|
|
157
|
-
else if (source.equals("/"))
|
|
158
|
-
{ nextUntilUnescaped(source, null); return {type: "comment", style: "js-comment"};}
|
|
159
|
-
else if (regexp)
|
|
160
|
-
return readRegexp();
|
|
161
|
-
else
|
|
162
|
-
return readOperator();
|
|
163
|
-
}
|
|
164
|
-
else if (isOperatorChar.test(ch))
|
|
165
|
-
return readOperator();
|
|
166
|
-
else
|
|
167
|
-
return readWord();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// The external interface to the tokenizer.
|
|
171
|
-
return function(source, startState) {
|
|
172
|
-
return tokenizer(source, startState || jsTokenState(false, true));
|
|
173
|
-
};
|
|
174
|
-
})();
|