From 3ac30c24fb2e280344db758aac3aecb030cfccea Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 3 Mar 2016 14:04:49 +0100 Subject: [PATCH] Do not generate brackets when tokenizing CSS --- src/vs/languages/css/common/css.ts | 22 +++--- src/vs/languages/css/test/common/css.test.ts | 71 +++++++++----------- 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/vs/languages/css/common/css.ts b/src/vs/languages/css/common/css.ts index 5e5ba43f1fc..62d55d79017 100644 --- a/src/vs/languages/css/common/css.ts +++ b/src/vs/languages/css/common/css.ts @@ -136,13 +136,13 @@ export class State extends AbstractState { switch (this.kind) { case States.ValuePostUrl: if (ch === '(') { - return this.nextState(States.ValueInUrlFunction, { type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }); + return this.nextState(States.ValueInUrlFunction, { type: 'punctuation.parenthesis.css' }); } this.kind = States.Value; break; case States.MetaPostUrl: if (ch === '(') { - return this.nextState(States.MetaInUrlFunction, { type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }); + return this.nextState(States.MetaInUrlFunction, { type: 'punctuation.parenthesis.css' }); } this.kind = States.Meta; break; @@ -160,10 +160,10 @@ export class State extends AbstractState { switch (this.kind) { case States.Selector: if (ch === '{') { - return this.nextState(States.Rule, { type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }); + return this.nextState(States.Rule, { type: 'punctuation.bracket.css' }); } if (ch === '(' || ch === ')') { - return { type: 'punctuation.parenthesis.css', bracket: ch === '(' ? Modes.Bracket.Open : Modes.Bracket.Close }; + return { type: 'punctuation.parenthesis.css' }; } if (ch === '@' && !this.inMeta) { //@import, @media, @key-word-animation stream.advanceIfRegExp2(identRegEx); @@ -171,7 +171,7 @@ export class State extends AbstractState { } if (ch === '}' && this.inMeta) { //@import, @media, @key-word-animation this.inMeta = false; - return this.nextState(States.Selector, { type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close }); + return this.nextState(States.Selector, { type: 'punctuation.bracket.css' }); } if (/[\*\(\)\[\]\+>=\~\|;]/.test(ch)) { return { type: 'punctuation.css' }; @@ -193,10 +193,10 @@ export class State extends AbstractState { if (this.inMeta) { nextState = States.Selector; } - return this.nextState(nextState, { type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }); + return this.nextState(nextState, { type: 'punctuation.bracket.css' }); } if (ch === '(' || ch === ')') { - return { type: 'punctuation.parenthesis.css', bracket: ch === '(' ? Modes.Bracket.Open : Modes.Bracket.Close }; + return { type: 'punctuation.parenthesis.css' }; } if (ch === ';') { if (this.metaBraceCount === 0) { @@ -217,20 +217,20 @@ export class State extends AbstractState { case States.Rule: if (ch === '}') { - return this.nextState(States.Selector, { type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close }); + return this.nextState(States.Selector, { type: 'punctuation.bracket.css' }); } if (ch === ':') { return this.nextState(States.Value, { type: 'punctuation.css' }); } if (ch === '(' || ch === ')') { - return { type: 'punctuation.parenthesis.css', bracket: ch === '(' ? Modes.Bracket.Open : Modes.Bracket.Close }; + return { type: 'punctuation.parenthesis.css' }; } this.consumeIdent(stream); return { type: cssTokenTypes.TOKEN_PROPERTY + '.css' }; case States.Value: if (ch === '}') { - return this.nextState(States.Selector, { type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close }); + return this.nextState(States.Selector, { type: 'punctuation.bracket.css' }); } if (ch === ';') { return this.nextState(States.Rule, { type: 'punctuation.css' }); @@ -240,7 +240,7 @@ export class State extends AbstractState { } if (ch === '(' || ch === ')') { - return { type: 'punctuation.parenthesis.css', bracket: ch === '(' ? Modes.Bracket.Open : Modes.Bracket.Close }; + return { type: 'punctuation.parenthesis.css' }; } if (ch === ',') { return { type: 'punctuation.css' }; diff --git a/src/vs/languages/css/test/common/css.test.ts b/src/vs/languages/css/test/common/css.test.ts index 886b3d2c738..22b425ceedb 100644 --- a/src/vs/languages/css/test/common/css.test.ts +++ b/src/vs/languages/css/test/common/css.test.ts @@ -52,7 +52,7 @@ suite('CSS Colorizing', () => { tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR_TAG + '.css' }, { startIndex:4, type: '' }, - { startIndex:5, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open } + { startIndex:5, type: 'punctuation.bracket.css' } ]}, { line: ' margin: 0;', tokens: [ @@ -113,7 +113,7 @@ suite('CSS Colorizing', () => { line: ' }', tokens: [ { startIndex:0, type: '' }, - { startIndex:2, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:2, type: 'punctuation.bracket.css' } ]} ]); }); @@ -169,7 +169,7 @@ suite('CSS Colorizing', () => { { startIndex:14, type: '' }, { startIndex:15, type: cssTokenTypes.TOKEN_SELECTOR_TAG + '.css' }, { startIndex:16, type: '' }, - { startIndex:17, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open } + { startIndex:17, type: 'punctuation.bracket.css' } ]} ]); }); @@ -197,7 +197,7 @@ suite('CSS Colorizing', () => { tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.id.css' }, { startIndex:5, type: '' }, - { startIndex:6, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open } + { startIndex:6, type: 'punctuation.bracket.css' } ]} ]); }); @@ -208,7 +208,7 @@ suite('CSS Colorizing', () => { tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, { startIndex:5, type: '' }, - { startIndex:6, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open } + { startIndex:6, type: 'punctuation.bracket.css' } ]} ]); }); @@ -220,9 +220,9 @@ suite('CSS Colorizing', () => { { startIndex:0, type: cssTokenTypes.TOKEN_AT_KEYWORD + '.css' }, { startIndex:7, type: '' }, { startIndex:8, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:11, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, + { startIndex:11, type: 'punctuation.parenthesis.css' }, { startIndex:12, type: 'string.css' }, - { startIndex:27, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, + { startIndex:27, type: 'punctuation.parenthesis.css' }, { startIndex:28, type: 'punctuation.css' } ]} ]); @@ -250,7 +250,7 @@ suite('CSS Colorizing', () => { tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_AT_KEYWORD + '.css' }, { startIndex:10, type: '' }, - { startIndex:11, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open } + { startIndex:11, type: 'punctuation.bracket.css' } ]}, { line: ' font-family: "Opificio";', tokens: [ @@ -282,7 +282,7 @@ suite('CSS Colorizing', () => { { startIndex:18, type: '' }, { startIndex:19, type: cssTokenTypes.TOKEN_VALUE + '.css' }, { startIndex:36, type: '' }, - { startIndex:37, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open } + { startIndex:37, type: 'punctuation.bracket.css' } ]}, { line: ' from {', tokens: [ @@ -348,22 +348,20 @@ suite('CSS Colorizing', () => { { startIndex:0, type: cssTokenTypes.TOKEN_AT_KEYWORD + '.css' }, { startIndex:7, type: '' }, { startIndex:8, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:11, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, + { startIndex:11, type: 'punctuation.parenthesis.css' }, { startIndex:12, type: 'string.css' }, - { startIndex:27, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, + { startIndex:27, type: 'punctuation.parenthesis.css' }, { startIndex:28, type: 'punctuation.css' } ]}, { line: '.rule1{}', tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, - { startIndex:6, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, - { startIndex:7, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:6, type: 'punctuation.bracket.css' } ]}, { line: '.rule2{}', tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, - { startIndex:6, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, - { startIndex:7, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:6, type: 'punctuation.bracket.css' } ]} ]); }); @@ -397,16 +395,16 @@ suite('CSS Colorizing', () => { { startIndex:0, type: cssTokenTypes.TOKEN_AT_KEYWORD + '.css' }, { startIndex:7, type: '' }, { startIndex:8, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:11, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, + { startIndex:11, type: 'punctuation.parenthesis.css' }, { startIndex:12, type: 'string.css' }, - { startIndex:27, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, + { startIndex:27, type: 'punctuation.parenthesis.css' }, { startIndex:28, type: 'punctuation.css' }, { startIndex:29, type: cssTokenTypes.TOKEN_AT_KEYWORD + '.css' }, { startIndex:36, type: '' }, { startIndex:37, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:40, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, + { startIndex:40, type: 'punctuation.parenthesis.css' }, { startIndex:41, type: 'string.css' }, - { startIndex:56, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, + { startIndex:56, type: 'punctuation.parenthesis.css' }, { startIndex:57, type: 'punctuation.css' } ]} ]); @@ -418,15 +416,15 @@ suite('CSS Colorizing', () => { line: '.a{background:#f5f9fc !important}.b{font-family:"Helvetica Neue", Helvetica;height:31px;}', tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, - { startIndex:2, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, + { startIndex:2, type: 'punctuation.bracket.css' }, { startIndex:3, type: cssTokenTypes.TOKEN_PROPERTY + '.css' }, { startIndex:13, type: 'punctuation.css' }, { startIndex:14, type: cssTokenTypes.TOKEN_VALUE + '.hex.css' }, { startIndex:21, type: '' }, { startIndex:22, type: cssTokenTypes.TOKEN_VALUE + '.keyword.css' }, - { startIndex:32, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close }, + { startIndex:32, type: 'punctuation.bracket.css' }, { startIndex:33, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, - { startIndex:35, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, + { startIndex:35, type: 'punctuation.bracket.css' }, { startIndex:36, type: cssTokenTypes.TOKEN_PROPERTY + '.css' }, { startIndex:47, type: 'punctuation.css' }, { startIndex:48, type: 'string.css' }, @@ -439,7 +437,7 @@ suite('CSS Colorizing', () => { { startIndex:83, type: cssTokenTypes.TOKEN_VALUE + '.numeric.css' }, { startIndex:85, type: cssTokenTypes.TOKEN_VALUE + '.unit.css' }, { startIndex:87, type: 'punctuation.css' }, - { startIndex:88, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:88, type: 'punctuation.bracket.css' } ]} ]); }); @@ -451,7 +449,7 @@ suite('CSS Colorizing', () => { tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, { startIndex:5, type: '' }, - { startIndex:6, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, + { startIndex:6, type: 'punctuation.bracket.css' }, { startIndex:7, type: '' }, { startIndex:8, type: cssTokenTypes.TOKEN_PROPERTY + '.css' }, { startIndex:18, type: 'punctuation.css' }, @@ -459,14 +457,14 @@ suite('CSS Colorizing', () => { { startIndex:20, type: cssTokenTypes.TOKEN_VALUE + '.hex.css' }, { startIndex:24, type: '' }, { startIndex:25, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:28, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, + { startIndex:28, type: 'punctuation.parenthesis.css' }, { startIndex:29, type: 'string.css' }, - { startIndex:215, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, + { startIndex:215, type: 'punctuation.parenthesis.css' }, { startIndex:216, type: '' }, { startIndex:217, type: cssTokenTypes.TOKEN_VALUE + '.css' }, { startIndex:225, type: '' }, { startIndex:226, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:232, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:232, type: 'punctuation.bracket.css' } ]} ]); }); @@ -477,14 +475,14 @@ suite('CSS Colorizing', () => { line: '.a{background:url(/a.jpg)}', tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, - { startIndex:2, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, + { startIndex:2, type: 'punctuation.bracket.css' }, { startIndex:3, type: cssTokenTypes.TOKEN_PROPERTY + '.css' }, { startIndex:13, type: 'punctuation.css' }, { startIndex:14, type: cssTokenTypes.TOKEN_VALUE + '.css' }, - { startIndex:17, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, + { startIndex:17, type: 'punctuation.parenthesis.css' }, { startIndex:18, type: 'string.css' }, - { startIndex:24, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, - { startIndex:25, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:24, type: 'punctuation.parenthesis.css' }, + { startIndex:25, type: 'punctuation.bracket.css' } ]} ]); }); @@ -494,8 +492,7 @@ suite('CSS Colorizing', () => { line: 'p{}', tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR_TAG + '.css' }, - { startIndex:1, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, - { startIndex:2, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:1, type: 'punctuation.bracket.css' } ]} ]); }); @@ -505,11 +502,9 @@ suite('CSS Colorizing', () => { line: 'p:nth() {}', tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR_TAG + '.css' }, - { startIndex:5, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Open }, - { startIndex:6, type: 'punctuation.parenthesis.css', bracket: Modes.Bracket.Close }, + { startIndex:5, type: 'punctuation.parenthesis.css' }, { startIndex:7, type: '' }, - { startIndex:8, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, - { startIndex:9, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Close } + { startIndex:8, type: 'punctuation.bracket.css' } ]} ]); }); @@ -555,7 +550,7 @@ suite('CSS Colorizing', () => { tokens: [ { startIndex:0, type: cssTokenTypes.TOKEN_SELECTOR + '.class.css' }, { startIndex:5, type: ''}, - { startIndex:6, type: 'punctuation.bracket.css', bracket: Modes.Bracket.Open }, + { startIndex:6, type: 'punctuation.bracket.css' }, { startIndex:7, type: cssTokenTypes.TOKEN_PROPERTY + '.css'} ]} ]);