From ebcaaa6a085b214342725826edab598279172be8 Mon Sep 17 00:00:00 2001 From: Wliu Date: Wed, 20 Apr 2016 22:49:54 -0400 Subject: [PATCH 1/3] :bug: Tokenize brackets in nested property lists Also fixed an issue where property-value was overreaching its bounds --- grammars/scss.cson | 19 ++++++--------- spec/scss-spec.coffee | 54 ++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/grammars/scss.cson b/grammars/scss.cson index a570709..08f15c4 100644 --- a/grammars/scss.cson +++ b/grammars/scss.cson @@ -848,13 +848,11 @@ '1': 'name': 'punctuation.separator.key-value.scss' 'comment': 'Kuroir: fixed nested elements for sass.' - 'end': '\\s*(;)|(\\})' + 'end': ';|(?=})' 'endCaptures': - '1': + '0': 'name': 'punctuation.terminator.rule.scss' - '2': - 'name': 'punctuation.section.property-list.end.scss' - 'name': 'meta.property-value.scss' + 'contentName': 'meta.property-value.scss' 'patterns': [ { 'include': '#general' @@ -866,17 +864,14 @@ } ] 'property_list': - 'begin': '\\{' + 'begin': '{' 'beginCaptures': '0': - 'name': 'punctuation.section.property-list.begin.scss' - 'captures': - '0': - 'name': 'punctuation.section.property-list.scss' - 'end': '(\\})|(?<=\\})' + 'name': 'punctuation.section.property-list.begin.bracket.curly.scss' + 'end': '}' 'endCaptures': '0': - 'name': 'punctuation.section.property-list.end.scss' + 'name': 'punctuation.section.property-list.end.bracket.curly.scss' 'name': 'meta.property-list.scss' 'patterns': [ { diff --git a/spec/scss-spec.coffee b/spec/scss-spec.coffee index fa22c0d..b4a0397 100644 --- a/spec/scss-spec.coffee +++ b/spec/scss-spec.coffee @@ -42,8 +42,8 @@ describe 'SCSS grammar', -> expect(tokens[0][1]).toEqual value: 'page', scopes: ['source.css.scss', 'meta.at-rule.page.scss', 'keyword.control.at-rule.page.scss'] expect(tokens[1][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][1]).toEqual value: 'text-align', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] - expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][4]).toEqual value: 'center', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] tokens = grammar.tokenizeLines """ @@ -58,8 +58,8 @@ describe 'SCSS grammar', -> expect(tokens[0][3]).toEqual value: ':left', scopes: ['source.css.scss', 'meta.at-rule.page.scss', 'entity.name.function.scss'] expect(tokens[1][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][1]).toEqual value: 'text-align', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] - expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][4]).toEqual value: 'center', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] tokens = grammar.tokenizeLines """ @@ -73,8 +73,8 @@ describe 'SCSS grammar', -> expect(tokens[0][2]).toEqual value: ':left', scopes: ['source.css.scss', 'meta.at-rule.page.scss', 'entity.name.function.scss'] expect(tokens[1][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][1]).toEqual value: 'text-align', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] - expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][4]).toEqual value: 'center', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] describe 'property-list', -> @@ -83,15 +83,27 @@ describe 'SCSS grammar', -> expect(tokens[4]).toEqual value: 'color', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] expect(tokens[7]).toEqual value: 'inherit', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] - expect(tokens[8]).toEqual value: ';', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.terminator.rule.scss'] - expect(tokens[10]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.scss'] + expect(tokens[8]).toEqual value: ';', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.terminator.rule.scss'] + expect(tokens[10]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] + + it 'tokenizes nested property-lists', -> + {tokens} = grammar.tokenizeLine 'very-custom { very-very-custom { color: inherit; } }' + + expect(tokens[2]).toEqual value: '{', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.begin.bracket.curly.scss'] + expect(tokens[4]).toEqual value: 'very-very-custom', scopes: ['source.css.scss', 'meta.property-list.scss', 'entity.name.tag.custom.scss'] + expect(tokens[6]).toEqual value: '{', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'punctuation.section.property-list.begin.bracket.curly.scss'] + expect(tokens[8]).toEqual value: 'color', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] + expect(tokens[11]).toEqual value: 'inherit', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] + expect(tokens[12]).toEqual value: ';', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'punctuation.terminator.rule.scss'] + expect(tokens[14]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] + expect(tokens[16]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] it 'tokenizes an incomplete inline property-list', -> {tokens} = grammar.tokenizeLine 'very-custom { color: inherit}' expect(tokens[4]).toEqual value: 'color', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] expect(tokens[7]).toEqual value: 'inherit', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] - expect(tokens[8]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.section.property-list.end.scss'] + expect(tokens[8]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] it 'tokenizes multiple lines of incomplete property-list', -> tokens = grammar.tokenizeLines """ @@ -102,9 +114,9 @@ describe 'SCSS grammar', -> expect(tokens[0][0]).toEqual value: 'very-custom', scopes: ['source.css.scss', 'entity.name.tag.custom.scss'] expect(tokens[0][4]).toEqual value: 'color', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] expect(tokens[0][7]).toEqual value: 'inherit', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] - expect(tokens[0][9]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.section.property-list.end.scss'] + expect(tokens[0][9]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] expect(tokens[1][0]).toEqual value: 'another-one', scopes: ['source.css.scss', 'entity.name.tag.custom.scss'] - expect(tokens[1][10]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.scss'] + expect(tokens[1][10]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] describe 'property names with a prefix that matches an element name', -> it 'does not confuse them with properties', -> @@ -117,8 +129,8 @@ describe 'SCSS grammar', -> expect(tokens[0][0]).toEqual value: 'text', scopes: ['source.css.scss', 'entity.name.tag.scss'] expect(tokens[1][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][1]).toEqual value: 'text-align', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] - expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][4]).toEqual value: 'center', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] tokens = grammar.tokenizeLines """ @@ -130,8 +142,8 @@ describe 'SCSS grammar', -> expect(tokens[0][0]).toEqual value: 'table', scopes: ['source.css.scss', 'entity.name.tag.scss'] expect(tokens[1][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][1]).toEqual value: 'table-layout', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] - expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][4]).toEqual value: 'fixed', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] describe 'vendor properties', -> @@ -176,20 +188,20 @@ describe 'SCSS grammar', -> expect(tokens[1][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][1]).toEqual value: 'border-width', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] - expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[1][2]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[1][3]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[1][4]).toEqual value: '2', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'constant.numeric.scss'] expect(tokens[2][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[2][1]).toEqual value: 'font-size', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] expect(tokens[2][2]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] - expect(tokens[2][3]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[2][4]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[2][3]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[2][4]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[2][5]).toEqual value: '2', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'constant.numeric.scss'] expect(tokens[3][0]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[3][1]).toEqual value: 'background-image', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] expect(tokens[3][2]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] - expect(tokens[3][3]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'punctuation.separator.key-value.scss'] - expect(tokens[3][4]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss'] + expect(tokens[3][3]).toEqual value: ':', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.separator.key-value.scss'] + expect(tokens[3][4]).toEqual value: ' ', scopes: ['source.css.scss', 'meta.property-list.scss'] expect(tokens[3][5]).toEqual value: 'none', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] describe "pseudo selectors", -> From e2c2e329e93c7cc73f5752e816ffdc0a3c5b86b5 Mon Sep 17 00:00:00 2001 From: Wliu Date: Thu, 21 Apr 2016 20:06:37 -0400 Subject: [PATCH 2/3] Test for properties after a nested selector --- spec/scss-spec.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/scss-spec.coffee b/spec/scss-spec.coffee index b4a0397..2781dd2 100644 --- a/spec/scss-spec.coffee +++ b/spec/scss-spec.coffee @@ -87,7 +87,7 @@ describe 'SCSS grammar', -> expect(tokens[10]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] it 'tokenizes nested property-lists', -> - {tokens} = grammar.tokenizeLine 'very-custom { very-very-custom { color: inherit; } }' + {tokens} = grammar.tokenizeLine 'very-custom { very-very-custom { color: inherit; } margin: top; }' expect(tokens[2]).toEqual value: '{', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.begin.bracket.curly.scss'] expect(tokens[4]).toEqual value: 'very-very-custom', scopes: ['source.css.scss', 'meta.property-list.scss', 'entity.name.tag.custom.scss'] @@ -96,7 +96,9 @@ describe 'SCSS grammar', -> expect(tokens[11]).toEqual value: 'inherit', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] expect(tokens[12]).toEqual value: ';', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'punctuation.terminator.rule.scss'] expect(tokens[14]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] - expect(tokens[16]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] + expect(tokens[16]).toEqual value: 'margin', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-name.scss', 'support.type.property-name.scss'] + expect(tokens[19]).toEqual value: 'top', scopes: ['source.css.scss', 'meta.property-list.scss', 'meta.property-value.scss', 'support.constant.property-value.scss'] + expect(tokens[22]).toEqual value: '}', scopes: ['source.css.scss', 'meta.property-list.scss', 'punctuation.section.property-list.end.bracket.curly.scss'] it 'tokenizes an incomplete inline property-list', -> {tokens} = grammar.tokenizeLine 'very-custom { color: inherit}' From 3f87f9b06f39d0277be6ceddd21ec5b2fa054381 Mon Sep 17 00:00:00 2001 From: Wliu Date: Thu, 21 Apr 2016 20:09:50 -0400 Subject: [PATCH 3/3] Don't tokenize extra whitespace as a property value --- grammars/scss.cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/scss.cson b/grammars/scss.cson index 08f15c4..1c1418a 100644 --- a/grammars/scss.cson +++ b/grammars/scss.cson @@ -848,9 +848,9 @@ '1': 'name': 'punctuation.separator.key-value.scss' 'comment': 'Kuroir: fixed nested elements for sass.' - 'end': ';|(?=})' + 'end': '\\s*(;|(?=}))' 'endCaptures': - '0': + '1': 'name': 'punctuation.terminator.rule.scss' 'contentName': 'meta.property-value.scss' 'patterns': [