提交 448e178d 编写于 作者: A Alex Dima

Do not generate brackets when tokenizing handlebars, json, php or razor

上级 3ac30c24
......@@ -137,7 +137,7 @@ export class OnEnterSupport implements IRichEditOnEnter {
}
}
// (4): Open Bracket based logic
// (4): Open bracket based logic
if (beforeEnterText.length > 0) {
for (let i = 0, len = this._brackets.length; i < len; i++) {
let bracket = this._brackets[i];
......
......@@ -52,11 +52,11 @@ export class HandlebarsState extends htmlMode.State {
case States.HTML:
if (stream.advanceIfString('{{{').length > 0) {
this.handlebarsKind = States.UnescapedExpression;
return { type: handlebarsTokenTypes.EMBED_UNESCAPED, bracket: Modes.Bracket.Open };
return { type: handlebarsTokenTypes.EMBED_UNESCAPED };
}
else if (stream.advanceIfString('{{').length > 0) {
this.handlebarsKind = States.Expression;
return { type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open };
return { type: handlebarsTokenTypes.EMBED };
}
break;
......@@ -64,11 +64,11 @@ export class HandlebarsState extends htmlMode.State {
case States.UnescapedExpression:
if (this.handlebarsKind === States.Expression && stream.advanceIfString('}}').length > 0) {
this.handlebarsKind = States.HTML;
return { type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close };
return { type: handlebarsTokenTypes.EMBED };
}
else if (this.handlebarsKind === States.UnescapedExpression &&stream.advanceIfString('}}}').length > 0) {
this.handlebarsKind = States.HTML;
return { type: handlebarsTokenTypes.EMBED_UNESCAPED, bracket: Modes.Bracket.Close };
return { type: handlebarsTokenTypes.EMBED_UNESCAPED };
}
else if(stream.skipWhitespace().length > 0) {
return { type: ''};
......@@ -76,12 +76,12 @@ export class HandlebarsState extends htmlMode.State {
if(stream.peek() === '#') {
stream.advanceWhile(/^[^\s}]/);
return { type: handlebarsTokenTypes.KEYWORD, bracket: Modes.Bracket.Open };
return { type: handlebarsTokenTypes.KEYWORD };
}
if(stream.peek() === '/') {
stream.advanceWhile(/^[^\s}]/);
return { type: handlebarsTokenTypes.KEYWORD, bracket: Modes.Bracket.Close };
return { type: handlebarsTokenTypes.KEYWORD };
}
if(stream.advanceIfString('else')) {
......
......@@ -26,13 +26,13 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<h1>handlebars!</h1>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('h1') },
{ startIndex:3, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:3, type: htmlTokenTypes.DELIM_START },
{ startIndex:4, type: '' },
{ startIndex:15, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:15, type: htmlTokenTypes.DELIM_END },
{ startIndex:17, type: htmlTokenTypes.getTag('h1') },
{ startIndex:19, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:19, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -41,17 +41,17 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<h1>{{ title }}</h1>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('h1') },
{ startIndex:3, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:4, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:3, type: htmlTokenTypes.DELIM_START },
{ startIndex:4, type: handlebarsTokenTypes.EMBED },
{ startIndex:6, type: '' },
{ startIndex:7, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:12, type: '' },
{ startIndex:13, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:15, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:13, type: handlebarsTokenTypes.EMBED },
{ startIndex:15, type: htmlTokenTypes.DELIM_END },
{ startIndex:17, type: htmlTokenTypes.getTag('h1') },
{ startIndex:19, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:19, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -60,15 +60,15 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<h1>{{title}}</h1>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('h1') },
{ startIndex:3, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:4, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:3, type: htmlTokenTypes.DELIM_START },
{ startIndex:4, type: handlebarsTokenTypes.EMBED },
{ startIndex:6, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:11, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:13, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:11, type: handlebarsTokenTypes.EMBED },
{ startIndex:13, type: htmlTokenTypes.DELIM_END },
{ startIndex:15, type: htmlTokenTypes.getTag('h1') },
{ startIndex:17, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:17, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -77,17 +77,17 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<h1>{{{ title }}}</h1>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('h1') },
{ startIndex:3, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:4, type: handlebarsTokenTypes.EMBED_UNESCAPED, bracket: Modes.Bracket.Open },
{ startIndex:3, type: htmlTokenTypes.DELIM_START },
{ startIndex:4, type: handlebarsTokenTypes.EMBED_UNESCAPED },
{ startIndex:7, type: '' },
{ startIndex:8, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:13, type: '' },
{ startIndex:14, type: handlebarsTokenTypes.EMBED_UNESCAPED, bracket: Modes.Bracket.Close },
{ startIndex:17, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:14, type: handlebarsTokenTypes.EMBED_UNESCAPED },
{ startIndex:17, type: htmlTokenTypes.DELIM_END },
{ startIndex:19, type: htmlTokenTypes.getTag('h1') },
{ startIndex:21, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:21, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -96,29 +96,29 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<ul>{{#each items}}<li>{{item}}</li>{{/each}}</ul>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('ul') },
{ startIndex:3, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:4, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:6, type: handlebarsTokenTypes.KEYWORD, bracket: Modes.Bracket.Open },
{ startIndex:3, type: htmlTokenTypes.DELIM_START },
{ startIndex:4, type: handlebarsTokenTypes.EMBED },
{ startIndex:6, type: handlebarsTokenTypes.KEYWORD },
{ startIndex:11, type: '' },
{ startIndex:12, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:17, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:19, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:17, type: handlebarsTokenTypes.EMBED },
{ startIndex:19, type: htmlTokenTypes.DELIM_START },
{ startIndex:20, type: htmlTokenTypes.getTag('li') },
{ startIndex:22, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:23, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:22, type: htmlTokenTypes.DELIM_START },
{ startIndex:23, type: handlebarsTokenTypes.EMBED },
{ startIndex:25, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:29, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:31, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:29, type: handlebarsTokenTypes.EMBED },
{ startIndex:31, type: htmlTokenTypes.DELIM_END },
{ startIndex:33, type: htmlTokenTypes.getTag('li') },
{ startIndex:35, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:36, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:38, type: handlebarsTokenTypes.KEYWORD, bracket: Modes.Bracket.Close },
{ startIndex:43, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:45, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:35, type: htmlTokenTypes.DELIM_END },
{ startIndex:36, type: handlebarsTokenTypes.EMBED },
{ startIndex:38, type: handlebarsTokenTypes.KEYWORD },
{ startIndex:43, type: handlebarsTokenTypes.EMBED },
{ startIndex:45, type: htmlTokenTypes.DELIM_END },
{ startIndex:47, type: htmlTokenTypes.getTag('ul') },
{ startIndex:49, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:49, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -127,29 +127,29 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<div>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('div') },
{ startIndex:4, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close }
{ startIndex:4, type: htmlTokenTypes.DELIM_START }
]}, {
line: '{{#if foo}}',
tokens: [
{ startIndex:0, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:2, type: handlebarsTokenTypes.KEYWORD, bracket: Modes.Bracket.Open },
{ startIndex:0, type: handlebarsTokenTypes.EMBED },
{ startIndex:2, type: handlebarsTokenTypes.KEYWORD },
{ startIndex:5, type: '' },
{ startIndex:6, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:9, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close }
{ startIndex:9, type: handlebarsTokenTypes.EMBED }
]}, {
line: '<span>{{bar}}</span>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('span') },
{ startIndex:5, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:6, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:5, type: htmlTokenTypes.DELIM_START },
{ startIndex:6, type: handlebarsTokenTypes.EMBED },
{ startIndex:8, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:11, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:13, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:11, type: handlebarsTokenTypes.EMBED },
{ startIndex:13, type: htmlTokenTypes.DELIM_END },
{ startIndex:15, type: htmlTokenTypes.getTag('span') },
{ startIndex:19, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:19, type: htmlTokenTypes.DELIM_END }
]}, {
line: '{{/if}}',
tokens: null}
......@@ -160,9 +160,9 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '</div>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_END },
{ startIndex:2, type: htmlTokenTypes.getTag('div') },
{ startIndex:5, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:5, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -172,13 +172,13 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<script type="text/javascript">var i= 10;</script>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: '' },
{ startIndex:8, type: htmlTokenTypes.ATTRIB_NAME },
{ startIndex:12, type: htmlTokenTypes.DELIM_ASSIGN },
{ startIndex:13, type: htmlTokenTypes.ATTRIB_VALUE },
{ startIndex:30, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:30, type: htmlTokenTypes.DELIM_START },
{ startIndex:31, type: 'keyword.js' },
{ startIndex:34, type: '' },
{ startIndex:35, type: 'identifier.js' },
......@@ -186,9 +186,9 @@ suite('Handlebars', () => {
{ startIndex:37, type: '' },
{ startIndex:38, type: 'number.js' },
{ startIndex:40, type: 'delimiter.js' },
{ startIndex:41, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:41, type: htmlTokenTypes.DELIM_END },
{ startIndex:43, type: htmlTokenTypes.getTag('script') },
{ startIndex:49, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:49, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -197,27 +197,27 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<script type="text/x-handlebars-template"><h1>{{ title }}</h1></script>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: '' },
{ startIndex:8, type: htmlTokenTypes.ATTRIB_NAME },
{ startIndex:12, type: htmlTokenTypes.DELIM_ASSIGN },
{ startIndex:13, type: htmlTokenTypes.ATTRIB_VALUE },
{ startIndex:41, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:42, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:41, type: htmlTokenTypes.DELIM_START },
{ startIndex:42, type: htmlTokenTypes.DELIM_START },
{ startIndex:43, type: htmlTokenTypes.getTag('h1') },
{ startIndex:45, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:46, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:45, type: htmlTokenTypes.DELIM_START },
{ startIndex:46, type: handlebarsTokenTypes.EMBED },
{ startIndex:48, type: '' },
{ startIndex:49, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:54, type: '' },
{ startIndex:55, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:57, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:55, type: handlebarsTokenTypes.EMBED },
{ startIndex:57, type: htmlTokenTypes.DELIM_END },
{ startIndex:59, type: htmlTokenTypes.getTag('h1') },
{ startIndex:61, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:62, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:61, type: htmlTokenTypes.DELIM_END },
{ startIndex:62, type: htmlTokenTypes.DELIM_END },
{ startIndex:64, type: htmlTokenTypes.getTag('script') },
{ startIndex:70, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:70, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -226,33 +226,33 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<script type="text/x-handlebars-template">',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: '' },
{ startIndex:8, type: htmlTokenTypes.ATTRIB_NAME },
{ startIndex:12, type: htmlTokenTypes.DELIM_ASSIGN },
{ startIndex:13, type: htmlTokenTypes.ATTRIB_VALUE },
{ startIndex:41, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close }
{ startIndex:41, type: htmlTokenTypes.DELIM_START }
]}, {
line: '<h1>{{ title }}</h1>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('h1') },
{ startIndex:3, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:4, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:3, type: htmlTokenTypes.DELIM_START },
{ startIndex:4, type: handlebarsTokenTypes.EMBED },
{ startIndex:6, type: '' },
{ startIndex:7, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:12, type: '' },
{ startIndex:13, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:15, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:13, type: handlebarsTokenTypes.EMBED },
{ startIndex:15, type: htmlTokenTypes.DELIM_END },
{ startIndex:17, type: htmlTokenTypes.getTag('h1') },
{ startIndex:19, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:19, type: htmlTokenTypes.DELIM_END }
]}, {
line: '</script>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_END },
{ startIndex:2, type: htmlTokenTypes.getTag('script') },
{ startIndex:8, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:8, type: htmlTokenTypes.DELIM_END }
]}
]);
});
......@@ -261,18 +261,18 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '{{foo}}<script></script>{{bar}}',
tokens: [
{ startIndex:0, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:0, type: handlebarsTokenTypes.EMBED },
{ startIndex:2, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:5, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:7, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:5, type: handlebarsTokenTypes.EMBED },
{ startIndex:7, type: htmlTokenTypes.DELIM_START },
{ startIndex:8, type: htmlTokenTypes.getTag('script') },
{ startIndex:14, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:15, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:14, type: htmlTokenTypes.DELIM_START },
{ startIndex:15, type: htmlTokenTypes.DELIM_END },
{ startIndex:17, type: htmlTokenTypes.getTag('script') },
{ startIndex:23, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:24, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:23, type: htmlTokenTypes.DELIM_END },
{ startIndex:24, type: handlebarsTokenTypes.EMBED },
{ startIndex:26, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:29, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close }
{ startIndex:29, type: handlebarsTokenTypes.EMBED }
]}
]);
});
......@@ -281,9 +281,9 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '{{else}}',
tokens: [
{ startIndex:0, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:0, type: handlebarsTokenTypes.EMBED },
{ startIndex:2, type: handlebarsTokenTypes.KEYWORD },
{ startIndex:6, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close }
{ startIndex:6, type: handlebarsTokenTypes.EMBED }
]}
]);
});
......@@ -292,9 +292,9 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '{{elseFoo}}',
tokens: [
{ startIndex:0, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:0, type: handlebarsTokenTypes.EMBED },
{ startIndex:2, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:9, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close }
{ startIndex:9, type: handlebarsTokenTypes.EMBED }
]}
]);
});
......@@ -303,17 +303,17 @@ suite('Handlebars', () => {
modesUtil.assertTokenization(tokenizationSupport, [{
line: '<a href="/posts/{{permalink}}">',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('a') },
{ startIndex:2, type: '' },
{ startIndex:3, type: htmlTokenTypes.ATTRIB_NAME },
{ startIndex:7, type: htmlTokenTypes.DELIM_ASSIGN },
{ startIndex:8, type: htmlTokenTypes.ATTRIB_VALUE },
{ startIndex:16, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Open },
{ startIndex:16, type: handlebarsTokenTypes.EMBED },
{ startIndex:18, type: handlebarsTokenTypes.VARIABLE },
{ startIndex:27, type: handlebarsTokenTypes.EMBED, bracket: Modes.Bracket.Close },
{ startIndex:27, type: handlebarsTokenTypes.EMBED },
{ startIndex:29, type: htmlTokenTypes.ATTRIB_VALUE },
{ startIndex:30, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close }
{ startIndex:30, type: htmlTokenTypes.DELIM_START }
]}
]);
});
......
......@@ -95,7 +95,6 @@ function tokenize(mode:Modes.IMode, comments:boolean, line:string, state:JSONSta
while(true) {
var offset = offsetDelta + scanner.getPosition(),
bracket = Modes.Bracket.None,
type = '';
kind = scanner.scan();
......@@ -119,22 +118,18 @@ function tokenize(mode:Modes.IMode, comments:boolean, line:string, state:JSONSta
// brackets and type
switch(kind) {
case json.SyntaxKind.OpenBraceToken:
bracket = Modes.Bracket.Open;
type = jsonTokenTypes.TOKEN_DELIM_OBJECT;
lastWasColon = false;
break;
case json.SyntaxKind.CloseBraceToken:
bracket = Modes.Bracket.Close;
type = jsonTokenTypes.TOKEN_DELIM_OBJECT;
lastWasColon = false;
break;
case json.SyntaxKind.OpenBracketToken:
bracket = Modes.Bracket.Open;
type = jsonTokenTypes.TOKEN_DELIM_ARRAY;
lastWasColon = false;
break;
case json.SyntaxKind.CloseBracketToken:
bracket = Modes.Bracket.Close;
type = jsonTokenTypes.TOKEN_DELIM_ARRAY;
lastWasColon = false;
break;
......
......@@ -31,25 +31,25 @@ suite('JSON - tokenization', () => {
[{
line: '{',
tokens: [
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_OBJECT, bracket: Modes.Bracket.Open }
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_OBJECT }
]}],
[{
line: '[',
tokens: [
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_ARRAY, bracket: Modes.Bracket.Open }
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_ARRAY }
]}],
[{
line: '}',
tokens: [
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_OBJECT, bracket: Modes.Bracket.Close }
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_OBJECT }
]}],
[{
line: ']',
tokens: [
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_ARRAY, bracket: Modes.Bracket.Close }
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_ARRAY }
]}],
[{
......@@ -145,21 +145,21 @@ suite('JSON - tokenization', () => {
[{
line: '{ "foo": "bar" }',
tokens: [
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_OBJECT, bracket: Modes.Bracket.Open },
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_OBJECT },
{ startIndex:1, type: '' },
{ startIndex:2, type: jsonTokenTypes.TOKEN_PROPERTY_NAME },
{ startIndex:7, type: jsonTokenTypes.TOKEN_DELIM_COLON },
{ startIndex:8, type: '' },
{ startIndex:9, type: jsonTokenTypes.TOKEN_VALUE_STRING },
{ startIndex:14, type: '' },
{ startIndex:15, type: jsonTokenTypes.TOKEN_DELIM_OBJECT, bracket: Modes.Bracket.Close }
{ startIndex:15, type: jsonTokenTypes.TOKEN_DELIM_OBJECT }
]}],
// Arrays, keywords, and numbers
[{
line: '[-1.5e+4, true, false, null]',
tokens: [
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_ARRAY, bracket: Modes.Bracket.Open },
{ startIndex:0, type: jsonTokenTypes.TOKEN_DELIM_ARRAY },
{ startIndex:1, type: jsonTokenTypes.TOKEN_VALUE_NUMBER },
{ startIndex:8, type: jsonTokenTypes.TOKEN_DELIM_COMMA },
{ startIndex:9, type: '' },
......@@ -170,7 +170,7 @@ suite('JSON - tokenization', () => {
{ startIndex:21, type: jsonTokenTypes.TOKEN_DELIM_COMMA },
{ startIndex:22, type: '' },
{ startIndex:23, type: jsonTokenTypes.TOKEN_VALUE_NULL },
{ startIndex:27, type: jsonTokenTypes.TOKEN_DELIM_ARRAY, bracket: Modes.Bracket.Close }
{ startIndex:27, type: jsonTokenTypes.TOKEN_DELIM_ARRAY }
]}]
]);
});
......
......@@ -27,19 +27,16 @@ var brackets = (function() {
let MAP: {
[text:string]:{
tokenType: string;
bracketType: Modes.Bracket
}
} = Object.create(null);
for (let i = 0; i < bracketsSource.length; i++) {
let bracket = bracketsSource[i];
MAP[bracket.open] = {
tokenType: bracket.tokenType,
bracketType: Modes.Bracket.Open
tokenType: bracket.tokenType
};
MAP[bracket.close] = {
tokenType: bracket.tokenType,
bracketType: Modes.Bracket.Close
tokenType: bracket.tokenType
};
}
......@@ -49,9 +46,6 @@ var brackets = (function() {
},
tokenTypeFromString: (text:string): string => {
return MAP[text].tokenType;
},
bracketTypeFromString: (text:string): Modes.Bracket => {
return MAP[text].bracketType;
}
};
})();
......@@ -364,7 +358,7 @@ export class PHPStatement extends PHPState {
return { nextState: new PHPNumber(this.getMode(), this, stream.next()) };
}
if (stream.advanceIfString('?>').length) {
return { type: 'metatag.php', nextState: this.parent, bracket: Modes.Bracket.Close };
return { type: 'metatag.php', nextState: this.parent };
}
var token = stream.nextToken();
......@@ -392,7 +386,6 @@ export class PHPStatement extends PHPState {
return { nextState: new PHPString(this.getMode(), this, token) };
} else if (brackets.stringIsBracket(token)) {
return {
bracket: brackets.bracketTypeFromString(token),
type: brackets.tokenTypeFromString(token)
};
} else if (isDelimiter(token)) {
......@@ -427,8 +420,7 @@ export class PHPPlain extends PHPState {
stream.advanceIfString('<?').length || stream.advanceIfString('<%').length) {
return {
type: 'metatag.php',
nextState: new PHPStatement(this.getMode(), new PHPEnterHTMLState(this.getMode(), this.parent)),
bracket: Modes.Bracket.Open
nextState: new PHPStatement(this.getMode(), new PHPEnterHTMLState(this.getMode(), this.parent))
};
}
stream.next();
......
......@@ -152,12 +152,11 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:5, type: '' },
{ startIndex:6, type: 'keyword.php' },
{ startIndex:14, type: '' },
{ startIndex:21, type: 'delimiter.parenthesis.php', bracket: Modes.Bracket.Open },
{ startIndex:22, type: 'delimiter.parenthesis.php', bracket: Modes.Bracket.Close },
{ startIndex:21, type: 'delimiter.parenthesis.php' },
{ startIndex:23, type: '' },
{ startIndex:24, type: 'delimiter.bracket.php', bracket: Modes.Bracket.Open },
{ startIndex:24, type: 'delimiter.bracket.php' },
{ startIndex:25, type: '' },
{ startIndex:26, type: 'delimiter.bracket.php', bracket: Modes.Bracket.Close },
{ startIndex:26, type: 'delimiter.bracket.php' },
{ startIndex:27, type: '' },
{ startIndex:28, type: 'metatag.php' }
]}],
......@@ -1527,9 +1526,9 @@ suite('Syntax Highlighting - PHP', () => {
tokens: [
{ startIndex:0, type: 'metatag.php' },
{ startIndex:5, type: '' },
{ startIndex:6, type: 'delimiter.bracket.php', bracket: Modes.Bracket.Open },
{ startIndex:6, type: 'delimiter.bracket.php' },
{ startIndex:7, type: '' },
{ startIndex:8, type: 'delimiter.bracket.php', bracket: Modes.Bracket.Close },
{ startIndex:8, type: 'delimiter.bracket.php' },
{ startIndex:9, type: '' },
{ startIndex:10, type: 'metatag.php' }
]}],
......@@ -1539,13 +1538,13 @@ suite('Syntax Highlighting - PHP', () => {
tokens: [
{ startIndex:0, type: 'metatag.php' },
{ startIndex:5, type: '' },
{ startIndex:6, type: 'delimiter.array.php', bracket: Modes.Bracket.Open },
{ startIndex:6, type: 'delimiter.array.php' },
{ startIndex:7, type: 'number.php' },
{ startIndex:8, type: 'delimiter.php' },
{ startIndex:9, type: 'number.php' },
{ startIndex:10, type: 'delimiter.php' },
{ startIndex:11, type: 'number.php' },
{ startIndex:12, type: 'delimiter.array.php', bracket: Modes.Bracket.Close },
{ startIndex:12, type: 'delimiter.array.php' },
{ startIndex:13, type: '' },
{ startIndex:14, type: 'metatag.php' }
]}],
......@@ -1555,9 +1554,9 @@ suite('Syntax Highlighting - PHP', () => {
tokens: [
{ startIndex:0, type: 'metatag.php' },
{ startIndex:5, type: '' },
{ startIndex:9, type: 'delimiter.parenthesis.php', bracket: Modes.Bracket.Open },
{ startIndex:9, type: 'delimiter.parenthesis.php' },
{ startIndex:10, type: 'number.php' },
{ startIndex:13, type: 'delimiter.parenthesis.php', bracket: Modes.Bracket.Close },
{ startIndex:13, type: 'delimiter.parenthesis.php' },
{ startIndex:14, type: 'delimiter.php' }
]}],
......@@ -1653,9 +1652,9 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:6, type: 'delimiter.php' },
{ startIndex:7, type: 'number.php' },
{ startIndex:8, type: 'metatag.php' },
{ startIndex:10, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:10, type: htmlTokenTypes.DELIM_START },
{ startIndex:11, type: htmlTokenTypes.getTag('abc') },
{ startIndex:14, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:14, type: htmlTokenTypes.DELIM_START },
{ startIndex:15, type: 'metatag.php' },
{ startIndex:18, type: 'number.php' },
{ startIndex:19, type: 'metatag.php' }
......@@ -1665,29 +1664,29 @@ suite('Syntax Highlighting - PHP', () => {
[{
line: '<abc><?php5+3?><abc>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('abc') },
{ startIndex:4, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:4, type: htmlTokenTypes.DELIM_START },
{ startIndex:5, type: 'metatag.php' },
{ startIndex:10, type: 'number.php' },
{ startIndex:11, type: 'delimiter.php' },
{ startIndex:12, type: 'number.php' },
{ startIndex:13, type: 'metatag.php' },
{ startIndex:15, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:15, type: htmlTokenTypes.DELIM_START },
{ startIndex:16, type: htmlTokenTypes.getTag('abc') },
{ startIndex:19, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close }
{ startIndex:19, type: htmlTokenTypes.DELIM_START }
]}],
// html/js/php/html
[{
line: '<abc><script>var i= 10;</script><?php5+3?><abc>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('abc') },
{ startIndex:4, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:5, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:4, type: htmlTokenTypes.DELIM_START },
{ startIndex:5, type: htmlTokenTypes.DELIM_START },
{ startIndex:6, type: htmlTokenTypes.getTag('script') },
{ startIndex:12, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:12, type: htmlTokenTypes.DELIM_START },
{ startIndex:13, type: 'keyword.js' },
{ startIndex:16, type: '' },
{ startIndex:17, type: 'identifier.js' },
......@@ -1695,29 +1694,29 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:19, type: '' },
{ startIndex:20, type: 'number.js' },
{ startIndex:22, type: 'delimiter.js' },
{ startIndex:23, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:23, type: htmlTokenTypes.DELIM_END },
{ startIndex:25, type: htmlTokenTypes.getTag('script') },
{ startIndex:31, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:31, type: htmlTokenTypes.DELIM_END },
{ startIndex:32, type: 'metatag.php' },
{ startIndex:37, type: 'number.php' },
{ startIndex:38, type: 'delimiter.php' },
{ startIndex:39, type: 'number.php' },
{ startIndex:40, type: 'metatag.php' },
{ startIndex:42, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:42, type: htmlTokenTypes.DELIM_START },
{ startIndex:43, type: htmlTokenTypes.getTag('abc') },
{ startIndex:46, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close }
{ startIndex:46, type: htmlTokenTypes.DELIM_START }
]}],
// html/js/php/js/
[{
line: '<abc><script>var i= 10;</script><?php5+3?><script>var x= 15;</script>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('abc') },
{ startIndex:4, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:5, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:4, type: htmlTokenTypes.DELIM_START },
{ startIndex:5, type: htmlTokenTypes.DELIM_START },
{ startIndex:6, type: htmlTokenTypes.getTag('script') },
{ startIndex:12, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:12, type: htmlTokenTypes.DELIM_START },
{ startIndex:13, type: 'keyword.js' },
{ startIndex:16, type: '' },
{ startIndex:17, type: 'identifier.js' },
......@@ -1725,17 +1724,17 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:19, type: '' },
{ startIndex:20, type: 'number.js' },
{ startIndex:22, type: 'delimiter.js' },
{ startIndex:23, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:23, type: htmlTokenTypes.DELIM_END },
{ startIndex:25, type: htmlTokenTypes.getTag('script') },
{ startIndex:31, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:31, type: htmlTokenTypes.DELIM_END },
{ startIndex:32, type: 'metatag.php' },
{ startIndex:37, type: 'number.php' },
{ startIndex:38, type: 'delimiter.php' },
{ startIndex:39, type: 'number.php' },
{ startIndex:40, type: 'metatag.php' },
{ startIndex:42, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:42, type: htmlTokenTypes.DELIM_START },
{ startIndex:43, type: htmlTokenTypes.getTag('script') },
{ startIndex:49, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:49, type: htmlTokenTypes.DELIM_START },
{ startIndex:50, type: 'keyword.js' },
{ startIndex:53, type: '' },
{ startIndex:54, type: 'identifier.js' },
......@@ -1743,24 +1742,24 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:56, type: '' },
{ startIndex:57, type: 'number.js' },
{ startIndex:59, type: 'delimiter.js' },
{ startIndex:60, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:60, type: htmlTokenTypes.DELIM_END },
{ startIndex:62, type: htmlTokenTypes.getTag('script') },
{ startIndex:68, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:68, type: htmlTokenTypes.DELIM_END }
]}],
// Multiline test
[{
line: '<html>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('html') },
{ startIndex:5, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close }
{ startIndex:5, type: htmlTokenTypes.DELIM_START }
]}, {
line: '<style><?="div"?>{ color:blue; }</style>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('style') },
{ startIndex:6, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:6, type: htmlTokenTypes.DELIM_START },
{ startIndex:7, type: 'metatag.php' },
{ startIndex:10, type: 'string.php' },
{ startIndex:15, type: 'metatag.php' },
......@@ -1772,15 +1771,15 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:29, type: 'punctuation.css' },
{ startIndex:30, type: '' },
{ startIndex:31, type: 'punctuation.bracket.css' },
{ startIndex:32, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:32, type: htmlTokenTypes.DELIM_END },
{ startIndex:34, type: htmlTokenTypes.getTag('style') },
{ startIndex:39, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:39, type: htmlTokenTypes.DELIM_END }
]}, {
line: '<style><?="div"?>{ color:blue; }</style>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('style') },
{ startIndex:6, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:6, type: htmlTokenTypes.DELIM_START },
{ startIndex:7, type: 'metatag.php' },
{ startIndex:10, type: 'string.php' },
{ startIndex:15, type: 'metatag.php' },
......@@ -1792,21 +1791,21 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:29, type: 'punctuation.css' },
{ startIndex:30, type: '' },
{ startIndex:31, type: 'punctuation.bracket.css' },
{ startIndex:32, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:32, type: htmlTokenTypes.DELIM_END },
{ startIndex:34, type: htmlTokenTypes.getTag('style') },
{ startIndex:39, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close }
{ startIndex:39, type: htmlTokenTypes.DELIM_END }
]}],
// HTML (CSS (PHP)), HTML ( PHP, JS (PHP), PHP)
[{
line: '<html><style><?="div"?> { color:blue; }</style><!--<?="HTML Comment"?>--><script>var x = 3;/* <?="JS Comment"/*</script>*/?> */var y = 4;</script></html><? $x = 3;?>',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('html') },
{ startIndex:5, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:6, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:5, type: htmlTokenTypes.DELIM_START },
{ startIndex:6, type: htmlTokenTypes.DELIM_START },
{ startIndex:7, type: htmlTokenTypes.getTag('style') },
{ startIndex:12, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:12, type: htmlTokenTypes.DELIM_START },
{ startIndex:13, type: 'metatag.php' },
{ startIndex:16, type: 'string.php' },
{ startIndex:21, type: 'metatag.php' },
......@@ -1819,17 +1818,17 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:36, type: 'punctuation.css' },
{ startIndex:37, type: '' },
{ startIndex:38, type: 'punctuation.bracket.css' },
{ startIndex:39, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:39, type: htmlTokenTypes.DELIM_END },
{ startIndex:41, type: htmlTokenTypes.getTag('style') },
{ startIndex:46, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:47, type: htmlTokenTypes.DELIM_COMMENT, bracket: Modes.Bracket.Open },
{ startIndex:46, type: htmlTokenTypes.DELIM_END },
{ startIndex:47, type: htmlTokenTypes.DELIM_COMMENT },
{ startIndex:51, type: 'metatag.php' },
{ startIndex:54, type: 'string.php' },
{ startIndex:68, type: 'metatag.php' },
{ startIndex:70, type: htmlTokenTypes.DELIM_COMMENT, bracket: Modes.Bracket.Close },
{ startIndex:73, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:70, type: htmlTokenTypes.DELIM_COMMENT },
{ startIndex:73, type: htmlTokenTypes.DELIM_START },
{ startIndex:74, type: htmlTokenTypes.getTag('script') },
{ startIndex:80, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:80, type: htmlTokenTypes.DELIM_START },
{ startIndex:81, type: 'keyword.js' },
{ startIndex:84, type: '' },
{ startIndex:85, type: 'identifier.js' },
......@@ -1852,12 +1851,12 @@ suite('Syntax Highlighting - PHP', () => {
{ startIndex:134, type: '' },
{ startIndex:135, type: 'number.js' },
{ startIndex:136, type: 'delimiter.js' },
{ startIndex:137, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:137, type: htmlTokenTypes.DELIM_END },
{ startIndex:139, type: htmlTokenTypes.getTag('script') },
{ startIndex:145, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:146, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex:145, type: htmlTokenTypes.DELIM_END },
{ startIndex:146, type: htmlTokenTypes.DELIM_END },
{ startIndex:148, type: htmlTokenTypes.getTag('html') },
{ startIndex:152, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex:152, type: htmlTokenTypes.DELIM_END },
{ startIndex:153, type: 'metatag.php' },
{ startIndex:155, type: '' },
{ startIndex:156, type: 'variable.php' },
......@@ -1873,18 +1872,18 @@ suite('Syntax Highlighting - PHP', () => {
[{
line: '<!--c--><?',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_COMMENT, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_COMMENT },
{ startIndex:4, type: htmlTokenTypes.COMMENT },
{ startIndex:5, type: htmlTokenTypes.DELIM_COMMENT, bracket: Modes.Bracket.Close },
{ startIndex:5, type: htmlTokenTypes.DELIM_COMMENT },
{ startIndex:8, type: 'metatag.php' }
]}],
[{
line: '<script>//<?',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:7, type: htmlTokenTypes.DELIM_START },
{ startIndex:8, type: 'comment.js' },
{ startIndex:10, type: 'metatag.php' }
]}],
......@@ -1892,9 +1891,9 @@ suite('Syntax Highlighting - PHP', () => {
[{
line: '<script>"<?php5+3?>"',
tokens: [
{ startIndex:0, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex:0, type: htmlTokenTypes.DELIM_START },
{ startIndex:1, type: htmlTokenTypes.getTag('script') },
{ startIndex:7, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex:7, type: htmlTokenTypes.DELIM_START },
{ startIndex:8, type: 'string.js' },
{ startIndex:9, type: 'metatag.php' },
{ startIndex:14, type: 'number.php' },
......@@ -1907,13 +1906,12 @@ suite('Syntax Highlighting - PHP', () => {
[{
line: '<?php toString(); ?>',
tokens: [
{ startIndex:0, type: 'metatag.php', bracket: Modes.Bracket.Open },
{ startIndex:0, type: 'metatag.php' },
{ startIndex:5, type: '' },
{ startIndex:14, type: 'delimiter.parenthesis.php', bracket: Modes.Bracket.Open },
{ startIndex:15, type: 'delimiter.parenthesis.php', bracket: Modes.Bracket.Close },
{ startIndex:14, type: 'delimiter.parenthesis.php' },
{ startIndex:16, type: 'delimiter.php' },
{ startIndex:17, type: '' },
{ startIndex:18, type: 'metatag.php', bracket: Modes.Bracket.Close }
{ startIndex:18, type: 'metatag.php' }
]}]
]);
});
......
......@@ -29,7 +29,6 @@ var brackets = (function() {
let MAP: {
[text:string]:{
tokenType: string;
bracketType: Modes.Bracket
}
} = Object.create(null);
......@@ -37,11 +36,9 @@ var brackets = (function() {
let bracket = bracketsSource[i];
MAP[bracket.open] = {
tokenType: bracket.tokenType,
bracketType: Modes.Bracket.Open
};
MAP[bracket.close] = {
tokenType: bracket.tokenType,
bracketType: Modes.Bracket.Close
};
}
......@@ -51,9 +48,6 @@ var brackets = (function() {
},
tokenTypeFromString: (text:string): string => {
return MAP[text].tokenType;
},
bracketTypeFromString: (text:string): Modes.Bracket => {
return MAP[text].bracketType;
}
};
})();
......@@ -408,7 +402,6 @@ export class CSStatement extends CSState implements VSXML.IVSXMLWrapperState {
if (brackets.stringIsBracket(token)) {
var tr: Modes.ITokenizationResult = {
bracket: brackets.bracketTypeFromString(token),
type: brackets.tokenTypeFromString(token),
nextState: nextStateAtEnd
};
......@@ -468,9 +461,6 @@ export class CSStatement extends CSState implements VSXML.IVSXMLWrapperState {
}
}
// list of empty elements - for performance reasons we won't open a bracket for them
var emptyElements:string[] = ['area','base','basefont','br','col','frame','hr','img','input','isindex','link','meta','param'];
// this state always returns to parent state if it leaves a html tag
class CSSimpleHTML extends CSState {
private state:htmlMode.States;
......@@ -502,7 +492,7 @@ class CSSimpleHTML extends CSState {
}
if (stream.advanceIfString('-->').length > 0) {
this.state = htmlMode.States.Content;
return { type: htmlTokenTypes.DELIM_COMMENT, bracket: Modes.Bracket.Close, nextState: this.parent };
return { type: htmlTokenTypes.DELIM_COMMENT, nextState: this.parent };
}
break;
......@@ -512,37 +502,36 @@ class CSSimpleHTML extends CSState {
}
if (stream.advanceIfString('>').length > 0) {
this.state = htmlMode.States.Content;
return { type: htmlTokenTypes.DELIM_DOCTYPE, bracket: Modes.Bracket.Close, nextState: this.parent };
return { type: htmlTokenTypes.DELIM_DOCTYPE, nextState: this.parent };
}
break;
case htmlMode.States.Content:
if (stream.advanceIfString('!--').length > 0){
this.state = htmlMode.States.WithinComment;
return { type: htmlTokenTypes.DELIM_COMMENT, bracket: Modes.Bracket.Open };
return { type: htmlTokenTypes.DELIM_COMMENT };
}
if (stream.advanceIfRegExp(/!DOCTYPE/i).length > 0) {
this.state = htmlMode.States.WithinDoctype;
return { type: htmlTokenTypes.DELIM_DOCTYPE, bracket: Modes.Bracket.Open };
return { type: htmlTokenTypes.DELIM_DOCTYPE };
}
if (stream.advanceIfString('/').length > 0){
this.state = htmlMode.States.OpeningEndTag;
return { type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open };
return { type: htmlTokenTypes.DELIM_END };
}
this.state = htmlMode.States.OpeningStartTag;
return { type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open };
return { type: htmlTokenTypes.DELIM_START };
case htmlMode.States.OpeningEndTag: {
let tagName = this.nextName(stream);
if (tagName.length > 0) {
return {
type: htmlTokenTypes.getTag(tagName),
bracket: emptyElements.indexOf(tagName) !== -1 ? -1 : Modes.Bracket.Close
type: htmlTokenTypes.getTag(tagName)
};
}
if (stream.advanceIfString('>').length > 0) {
this.state = htmlMode.States.Content;
return { type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close, nextState: this.parent };
return { type: htmlTokenTypes.DELIM_END, nextState: this.parent };
}
stream.advanceUntil('>', false);
return { type: '' };
......@@ -553,8 +542,7 @@ class CSSimpleHTML extends CSState {
if (tagName.length > 0) {
this.state = htmlMode.States.WithinTag;
return {
type: htmlTokenTypes.getTag(tagName),
bracket: emptyElements.indexOf(tagName) !== -1 ? -1 : Modes.Bracket.Open
type: htmlTokenTypes.getTag(tagName)
};
}
break;
......@@ -571,7 +559,7 @@ class CSSimpleHTML extends CSState {
}
if (stream.advanceIfRegExp(/^\/?>/).length > 0) {
this.state = htmlMode.States.Content;
return { type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close, nextState: this.parent };
return { type: htmlTokenTypes.DELIM_START, nextState: this.parent };
}
stream.next();
return { type: '' };
......
......@@ -27,22 +27,21 @@ suite('Syntax Highlighting - Razor', () => {
line: '@{ var x; <b>x</b> }',
tokens: [
{ startIndex: 0, type: razorTokenTypes.EMBED_CS },
{ startIndex: 1, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Open },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'keyword.cs' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'ident.cs' },
{ startIndex: 8, type: 'punctuation.cs' },
{ startIndex: 9, type: '' },
{ startIndex: 10, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Open },
{ startIndex: 10, type: htmlTokenTypes.DELIM_START },
{ startIndex: 11, type: htmlTokenTypes.getTag('b') },
{ startIndex: 12, type: htmlTokenTypes.DELIM_START, bracket: Modes.Bracket.Close },
{ startIndex: 12, type: htmlTokenTypes.DELIM_START },
{ startIndex: 13, type: 'ident.cs' },
{ startIndex: 14, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Open },
{ startIndex: 14, type: htmlTokenTypes.DELIM_END },
{ startIndex: 16, type: htmlTokenTypes.getTag('b') },
{ startIndex: 17, type: htmlTokenTypes.DELIM_END, bracket: Modes.Bracket.Close },
{ startIndex: 17, type: htmlTokenTypes.DELIM_END },
{ startIndex: 18, type: '' },
{ startIndex: 19, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Close }
{ startIndex: 19, type: razorTokenTypes.EMBED_CS }
]}],
// Comments - razor comment inside csharp
......@@ -50,7 +49,6 @@ suite('Syntax Highlighting - Razor', () => {
line: '@{ var x; @* comment *@ x= 0; }',
tokens: [
{ startIndex: 0, type: razorTokenTypes.EMBED_CS },
{ startIndex: 1, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Open },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'keyword.cs' },
{ startIndex: 6, type: '' },
......@@ -65,7 +63,7 @@ suite('Syntax Highlighting - Razor', () => {
{ startIndex: 27, type: 'number.cs' },
{ startIndex: 28, type: 'punctuation.cs' },
{ startIndex: 29, type: '' },
{ startIndex: 30, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Close }
{ startIndex: 30, type: razorTokenTypes.EMBED_CS }
]}],
// Blocks - simple
......@@ -73,7 +71,6 @@ suite('Syntax Highlighting - Razor', () => {
line: '@{ var total = 0; }',
tokens: [
{ startIndex: 0, type: razorTokenTypes.EMBED_CS },
{ startIndex: 1, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Open },
{ startIndex: 2, type: '' },
{ startIndex: 3, type: 'keyword.cs' },
{ startIndex: 6, type: '' },
......@@ -84,7 +81,7 @@ suite('Syntax Highlighting - Razor', () => {
{ startIndex: 15, type: 'number.cs' },
{ startIndex: 16, type: 'punctuation.cs' },
{ startIndex: 17, type: '' },
{ startIndex: 18, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Close }
{ startIndex: 18, type: razorTokenTypes.EMBED_CS }
]}],
[{
......@@ -92,10 +89,10 @@ suite('Syntax Highlighting - Razor', () => {
tokens: [
{ startIndex: 0, type: razorTokenTypes.EMBED_CS },
{ startIndex: 1, type: 'keyword.cs' },
{ startIndex: 3, type: 'punctuation.parenthesis.cs', bracket: Modes.Bracket.Open },
{ startIndex: 3, type: 'punctuation.parenthesis.cs' },
{ startIndex: 4, type: 'keyword.cs' },
{ startIndex: 8, type: 'punctuation.parenthesis.cs', bracket: Modes.Bracket.Close },
{ startIndex: 9, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Open },
{ startIndex: 8, type: 'punctuation.parenthesis.cs' },
{ startIndex: 9, type: razorTokenTypes.EMBED_CS },
{ startIndex: 10, type: '' },
{ startIndex: 11, type: 'keyword.cs' },
{ startIndex: 14, type: '' },
......@@ -106,7 +103,7 @@ suite('Syntax Highlighting - Razor', () => {
{ startIndex: 23, type: 'number.cs' },
{ startIndex: 24, type: 'punctuation.cs' },
{ startIndex: 25, type: '' },
{ startIndex: 26, type: razorTokenTypes.EMBED_CS, bracket: Modes.Bracket.Close }
{ startIndex: 26, type: razorTokenTypes.EMBED_CS }
]}],
// Expressions - csharp expressions in html
......@@ -143,7 +140,6 @@ suite('Syntax Highlighting - Razor', () => {
tokens: [
{ startIndex:0, type: '' },
{ startIndex:5, type: razorTokenTypes.EMBED_CS },
{ startIndex:6, type: razorTokenTypes.EMBED_CS },
{ startIndex:7, type: 'ident.cs' },
{ startIndex:10, type: razorTokenTypes.EMBED_CS },
{ startIndex:11, type: '' }
......@@ -154,7 +150,6 @@ suite('Syntax Highlighting - Razor', () => {
tokens: [
{ startIndex:0, type: '' },
{ startIndex:5, type: razorTokenTypes.EMBED_CS },
{ startIndex:6, type: razorTokenTypes.EMBED_CS },
{ startIndex:7, type: 'ident.cs' },
{ startIndex:10, type: 'punctuation.parenthesis.cs' },
{ startIndex:11, type: 'string.cs' },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册