OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @param {string} content | 7 * @param {string} content |
8 */ | 8 */ |
9 FormatterWorker.AcornTokenizer = function(content) | 9 WebInspector.AcornTokenizer = function(content) |
10 { | 10 { |
11 this._content = content; | 11 this._content = content; |
12 this._comments = []; | 12 this._comments = []; |
13 this._tokenizer = acorn.tokenizer(this._content, { ecmaVersion: 6, onComment
: this._comments }); | 13 this._tokenizer = acorn.tokenizer(this._content, { ecmaVersion: 6, onComment
: this._comments }); |
14 this._lineEndings = this._content.lineEndings(); | 14 this._lineEndings = this._content.lineEndings(); |
15 this._lineNumber = 0; | 15 this._lineNumber = 0; |
16 this._tokenLineStart = 0; | 16 this._tokenLineStart = 0; |
17 this._tokenLineEnd = 0; | 17 this._tokenLineEnd = 0; |
18 this._nextTokenInternal(); | 18 this._nextTokenInternal(); |
19 } | 19 } |
20 | 20 |
21 /** | 21 /** |
22 * @param {!Acorn.TokenOrComment} token | 22 * @param {!Acorn.TokenOrComment} token |
23 * @param {string=} values | 23 * @param {string=} values |
24 * @return {boolean} | 24 * @return {boolean} |
25 */ | 25 */ |
26 FormatterWorker.AcornTokenizer.punctuator = function(token, values) | 26 WebInspector.AcornTokenizer.punctuator = function(token, values) |
27 { | 27 { |
28 return token.type !== acorn.tokTypes.num && | 28 return token.type !== acorn.tokTypes.num && |
29 token.type !== acorn.tokTypes.regexp && | 29 token.type !== acorn.tokTypes.regexp && |
30 token.type !== acorn.tokTypes.string && | 30 token.type !== acorn.tokTypes.string && |
31 token.type !== acorn.tokTypes.name && | 31 token.type !== acorn.tokTypes.name && |
| 32 !token.type.keyword && |
32 (!values || (token.type.label.length === 1 && values.indexOf(token.type.
label) !== -1)); | 33 (!values || (token.type.label.length === 1 && values.indexOf(token.type.
label) !== -1)); |
33 } | 34 } |
34 | 35 |
35 /** | 36 /** |
36 * @param {!Acorn.TokenOrComment} token | 37 * @param {!Acorn.TokenOrComment} token |
37 * @param {string=} keyword | 38 * @param {string=} keyword |
38 * @return {boolean} | 39 * @return {boolean} |
39 */ | 40 */ |
40 FormatterWorker.AcornTokenizer.keyword = function(token, keyword) | 41 WebInspector.AcornTokenizer.keyword = function(token, keyword) |
41 { | 42 { |
42 return !!token.type.keyword && token.type !== acorn.tokTypes._true && token.
type !== acorn.tokTypes._false && | 43 return !!token.type.keyword && token.type !== acorn.tokTypes._true && token.
type !== acorn.tokTypes._false && |
43 (!keyword || token.type.keyword === keyword); | 44 (!keyword || token.type.keyword === keyword); |
44 } | 45 } |
45 | 46 |
46 /** | 47 /** |
47 * @param {!Acorn.TokenOrComment} token | 48 * @param {!Acorn.TokenOrComment} token |
48 * @param {string=} identifier | 49 * @param {string=} identifier |
49 * @return {boolean} | 50 * @return {boolean} |
50 */ | 51 */ |
51 FormatterWorker.AcornTokenizer.identifier = function(token, identifier) | 52 WebInspector.AcornTokenizer.identifier = function(token, identifier) |
52 { | 53 { |
53 return token.type === acorn.tokTypes.name && (!identifier || token.value ===
identifier); | 54 return token.type === acorn.tokTypes.name && (!identifier || token.value ===
identifier); |
54 } | 55 } |
55 | 56 |
56 /** | 57 /** |
57 * @param {!Acorn.TokenOrComment} token | 58 * @param {!Acorn.TokenOrComment} token |
58 * @return {boolean} | 59 * @return {boolean} |
59 */ | 60 */ |
60 FormatterWorker.AcornTokenizer.lineComment = function(token) | 61 WebInspector.AcornTokenizer.lineComment = function(token) |
61 { | 62 { |
62 return token.type === "Line"; | 63 return token.type === "Line"; |
63 } | 64 } |
64 | 65 |
65 /** | 66 /** |
66 * @param {!Acorn.TokenOrComment} token | 67 * @param {!Acorn.TokenOrComment} token |
67 * @return {boolean} | 68 * @return {boolean} |
68 */ | 69 */ |
69 FormatterWorker.AcornTokenizer.blockComment = function(token) | 70 WebInspector.AcornTokenizer.blockComment = function(token) |
70 { | 71 { |
71 return token.type === "Block"; | 72 return token.type === "Block"; |
72 } | 73 } |
73 | 74 |
74 FormatterWorker.AcornTokenizer.prototype = { | 75 WebInspector.AcornTokenizer.prototype = { |
75 /** | 76 /** |
76 * @return {!Acorn.TokenOrComment} | 77 * @return {!Acorn.TokenOrComment} |
77 */ | 78 */ |
78 _nextTokenInternal: function() | 79 _nextTokenInternal: function() |
79 { | 80 { |
80 if (this._comments.length) | 81 if (this._comments.length) |
81 return this._comments.shift(); | 82 return this._comments.shift(); |
82 var token = this._bufferedToken; | 83 var token = this._bufferedToken; |
83 | 84 |
84 this._bufferedToken = this._tokenizer.getToken(); | 85 this._bufferedToken = this._tokenizer.getToken(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 }, | 139 }, |
139 | 140 |
140 /** | 141 /** |
141 * @return {number} | 142 * @return {number} |
142 */ | 143 */ |
143 tokenColumnStart: function() | 144 tokenColumnStart: function() |
144 { | 145 { |
145 return this._tokenColumnStart; | 146 return this._tokenColumnStart; |
146 } | 147 } |
147 } | 148 } |
148 | |
149 // A dummy javascript mode which is used only by htmlmixed mode to advance | |
150 // stream until a </script> is found. | |
151 CodeMirror.defineMode("javascript", function(config, parserConfig) { | |
152 return { | |
153 token: function(stream, state) | |
154 { | |
155 return stream.next(); | |
156 } | |
157 } | |
158 }); | |
OLD | NEW |