Generate classic-style tokens for scss and add tests

This commit is contained in:
Alex Dima 2016-12-11 17:46:37 +01:00
parent d62ad052d0
commit f487f4f76d
3 changed files with 2117 additions and 62 deletions

View file

@ -25,11 +25,11 @@ export var conf: LanguageConfiguration = {
] ]
}; };
const TOKEN_SELECTOR = 'entity.name.selector'; const TOKEN_SELECTOR = 'tag';
const TOKEN_SELECTOR_TAG = 'entity.name.tag'; const TOKEN_SELECTOR_TAG = 'tag';
const TOKEN_PROPERTY = 'support.type.property-name'; const TOKEN_PROPERTY = 'attribute.name';
const TOKEN_VALUE = 'support.property-value'; const TOKEN_VALUE = 'attribute.value';
const TOKEN_AT_KEYWORD = 'keyword.control.at-rule'; const TOKEN_AT_KEYWORD = 'keyword';
export var language = <IMonarchLanguage> { export var language = <IMonarchLanguage> {
defaultToken: '', defaultToken: '',
@ -39,10 +39,10 @@ export var language = <IMonarchLanguage> {
identifier: '-?-?([a-zA-Z]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))([\\w\\-]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))*', identifier: '-?-?([a-zA-Z]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))([\\w\\-]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))*',
brackets: [ brackets: [
{ open: '{', close: '}', token: 'punctuation.curly' }, { open: '{', close: '}', token: 'delimiter.curly' },
{ open: '[', close: ']', token: 'punctuation.bracket' }, { open: '[', close: ']', token: 'delimiter.bracket' },
{ open: '(', close: ')', token: 'punctuation.parenthesis' }, { open: '(', close: ')', token: 'delimiter.parenthesis' },
{ open: '<', close: '>', token: 'punctuation.angle' } { open: '<', close: '>', token: 'delimiter.angle' }
], ],
tokenizer: { tokenizer: {
@ -61,13 +61,13 @@ export var language = <IMonarchLanguage> {
['[@](charset|namespace)', { token: TOKEN_AT_KEYWORD, next: '@declarationbody' }], ['[@](charset|namespace)', { token: TOKEN_AT_KEYWORD, next: '@declarationbody' }],
['[@](function)', { token: TOKEN_AT_KEYWORD, next: '@functiondeclaration' }], ['[@](function)', { token: TOKEN_AT_KEYWORD, next: '@functiondeclaration' }],
['[@](mixin)', { token: TOKEN_AT_KEYWORD, next: '@mixindeclaration' }], ['[@](mixin)', { token: TOKEN_AT_KEYWORD, next: '@mixindeclaration' }],
['url(\\-prefix)?\\(', { token: 'support.function.name', bracket: '@open', next: '@urldeclaration' }], ['url(\\-prefix)?\\(', { token: 'meta', bracket: '@open', next: '@urldeclaration' }],
{ include: '@controlstatement' }, // sass control statements { include: '@controlstatement' }, // sass control statements
{ include: '@selectorname' }, { include: '@selectorname' },
['[&\\*]', TOKEN_SELECTOR_TAG], // selector symbols ['[&\\*]', TOKEN_SELECTOR_TAG], // selector symbols
['[>\\+,]', 'punctuation'], // selector operators ['[>\\+,]', 'delimiter'], // selector operators
['\\[', { token: 'punctuation.bracket', bracket: '@open', next: '@selectorattribute' }], ['\\[', { token: 'delimiter.bracket', bracket: '@open', next: '@selectorattribute' }],
['{', { token: 'punctuation.curly', bracket: '@open', next: '@selectorbody' }], ['{', { token: 'delimiter.curly', bracket: '@open', next: '@selectorbody' }],
], ],
selectorbody: [ selectorbody: [
@ -75,46 +75,46 @@ export var language = <IMonarchLanguage> {
{ include: '@selector' }, // sass: nested selectors { include: '@selector' }, // sass: nested selectors
['[@](extend)', { token: TOKEN_AT_KEYWORD, next: '@extendbody' }], // sass: extend other selectors ['[@](extend)', { token: TOKEN_AT_KEYWORD, next: '@extendbody' }], // sass: extend other selectors
['[@](return)', { token: TOKEN_AT_KEYWORD, next: '@declarationbody' }], ['[@](return)', { token: TOKEN_AT_KEYWORD, next: '@declarationbody' }],
['}', { token: 'punctuation.curly', bracket: '@close', next: '@pop' }], ['}', { token: 'delimiter.curly', bracket: '@close', next: '@pop' }],
], ],
selectorname: [ selectorname: [
['#{', { token: 'support.function.interpolation', bracket: '@open', next: '@variableinterpolation' }], // sass: interpolation ['#{', { token: 'meta', bracket: '@open', next: '@variableinterpolation' }], // sass: interpolation
['(\\.|#(?=[^{])|%|(@identifier)|:)+', TOKEN_SELECTOR], // selector (.foo, div, ...) ['(\\.|#(?=[^{])|%|(@identifier)|:)+', TOKEN_SELECTOR], // selector (.foo, div, ...)
], ],
selectorattribute: [ selectorattribute: [
{ include: '@term' }, { include: '@term' },
[']', { token: 'punctuation.bracket', bracket: '@close', next: '@pop' }], [']', { token: 'delimiter.bracket', bracket: '@close', next: '@pop' }],
], ],
term: [ term: [
{ include: '@comments' }, { include: '@comments' },
['url(\\-prefix)?\\(', { token: 'support.function.name', bracket: '@open', next: '@urldeclaration' }], ['url(\\-prefix)?\\(', { token: 'meta', bracket: '@open', next: '@urldeclaration' }],
{ include: '@functioninvocation' }, { include: '@functioninvocation' },
{ include: '@numbers' }, { include: '@numbers' },
{ include: '@strings' }, { include: '@strings' },
{ include: '@variablereference' }, { include: '@variablereference' },
['(and\\b|or\\b|not\\b)', 'keyword.operator'], ['(and\\b|or\\b|not\\b)', 'operator'],
{ include: '@name' }, { include: '@name' },
['([<>=\\+\\-\\*\\/\\^\\|\\~,])', 'keyword.operator'], ['([<>=\\+\\-\\*\\/\\^\\|\\~,])', 'operator'],
[',', 'punctuation'], [',', 'delimiter'],
['!default', 'literal'], ['!default', 'literal'],
['\\(', { token: 'punctuation.parenthesis', bracket: '@open', next: '@parenthizedterm' }], ['\\(', { token: 'delimiter.parenthesis', bracket: '@open', next: '@parenthizedterm' }],
], ],
rulevalue: [ rulevalue: [
{ include: '@term' }, { include: '@term' },
['!important', 'literal'], ['!important', 'literal'],
[';', 'punctuation', '@pop'], [';', 'delimiter', '@pop'],
['{', { token: 'punctuation.curly', bracket: '@open', switchTo: '@nestedproperty' }], // sass: nested properties ['{', { token: 'delimiter.curly', bracket: '@open', switchTo: '@nestedproperty' }], // sass: nested properties
['(?=})', { token: '', next: '@pop' }], // missing semicolon ['(?=})', { token: '', next: '@pop' }], // missing semicolon
], ],
nestedproperty: [ nestedproperty: [
['[*_]?@identifier@ws:', TOKEN_PROPERTY, '@rulevalue'], ['[*_]?@identifier@ws:', TOKEN_PROPERTY, '@rulevalue'],
{ include: '@comments' }, { include: '@comments' },
['}', { token: 'punctuation.curly', bracket: '@close', next: '@pop' }], ['}', { token: 'delimiter.curly', bracket: '@close', next: '@pop' }],
], ],
warndebug: [ warndebug: [
@ -132,36 +132,36 @@ export var language = <IMonarchLanguage> {
urldeclaration: [ urldeclaration: [
{ include: '@strings' }, { include: '@strings' },
['[^)\r\n]+', 'string'], ['[^)\r\n]+', 'string'],
['\\)', { token: 'support.function.name', bracket: '@close', next: '@pop' }], ['\\)', { token: 'meta', bracket: '@close', next: '@pop' }],
], ],
parenthizedterm: [ parenthizedterm: [
{ include: '@term' }, { include: '@term' },
['\\)', { token: 'punctuation.parenthesis', bracket: '@close', next: '@pop' }], ['\\)', { token: 'delimiter.parenthesis', bracket: '@close', next: '@pop' }],
], ],
declarationbody: [ declarationbody: [
{ include: '@term' }, { include: '@term' },
[';', 'punctuation', '@pop'], [';', 'delimiter', '@pop'],
['(?=})', { token: '', next: '@pop' }], // missing semicolon ['(?=})', { token: '', next: '@pop' }], // missing semicolon
], ],
extendbody: [ extendbody: [
{ include: '@selectorname' }, { include: '@selectorname' },
['!optional', 'literal'], ['!optional', 'literal'],
[';', 'punctuation', '@pop'], [';', 'delimiter', '@pop'],
['(?=})', { token: '', next: '@pop' }], // missing semicolon ['(?=})', { token: '', next: '@pop' }], // missing semicolon
], ],
variablereference: [ // sass variable reference variablereference: [ // sass variable reference
['\\$@identifier', 'variable.ref'], ['\\$@identifier', 'variable.ref'],
['\\.\\.\\.', 'keyword.operator'], // var args in reference ['\\.\\.\\.', 'operator'], // var args in reference
['#{', { token: 'support.function.interpolation', bracket: '@open', next: '@variableinterpolation' }], // sass var resolve ['#{', { token: 'meta', bracket: '@open', next: '@variableinterpolation' }], // sass var resolve
], ],
variableinterpolation: [ variableinterpolation: [
{ include: '@variablereference' }, { include: '@variablereference' },
['}', { token: 'support.function.interpolation', bracket: '@close', next: '@pop' }], ['}', { token: 'meta', bracket: '@close', next: '@pop' }],
], ],
comments: [ comments: [
@ -179,62 +179,62 @@ export var language = <IMonarchLanguage> {
], ],
numbers: [ numbers: [
['(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?', { token: 'constant.numeric', next: '@units' }], ['(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?', { token: 'number', next: '@units' }],
['#[0-9a-fA-F_]+(?!\\w)', 'constant.rgb-value'], ['#[0-9a-fA-F_]+(?!\\w)', 'number.hex'],
], ],
units: [ units: [
['(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?', 'constant.numeric', '@pop'] ['(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?', 'number', '@pop']
], ],
functiondeclaration: [ functiondeclaration: [
['@identifier@ws\\(', { token: 'support.function.name', bracket: '@open', next: '@parameterdeclaration' }], ['@identifier@ws\\(', { token: 'meta', bracket: '@open', next: '@parameterdeclaration' }],
['{', { token: 'punctuation.curly', bracket: '@open', switchTo: '@functionbody' }], ['{', { token: 'delimiter.curly', bracket: '@open', switchTo: '@functionbody' }],
], ],
mixindeclaration: [ mixindeclaration: [
// mixin with parameters // mixin with parameters
['@identifier@ws\\(', { token: 'support.function.name', bracket: '@open', next: '@parameterdeclaration' }], ['@identifier@ws\\(', { token: 'meta', bracket: '@open', next: '@parameterdeclaration' }],
// mixin without parameters // mixin without parameters
['@identifier', 'support.function.name'], ['@identifier', 'meta'],
['{', { token: 'punctuation.curly', bracket: '@open', switchTo: '@selectorbody' }], ['{', { token: 'delimiter.curly', bracket: '@open', switchTo: '@selectorbody' }],
], ],
parameterdeclaration: [ parameterdeclaration: [
['\\$@identifier@ws:', 'variable'], ['\\$@identifier@ws:', 'variable.decl'],
['\\.\\.\\.', 'keyword.operator'], // var args in declaration ['\\.\\.\\.', 'operator'], // var args in declaration
[',', 'punctuation'], [',', 'delimiter'],
{ include: '@term' }, { include: '@term' },
['\\)', { token: 'support.function.name', bracket: '@close', next: '@pop' }], ['\\)', { token: 'meta', bracket: '@close', next: '@pop' }],
], ],
includedeclaration: [ includedeclaration: [
{ include: '@functioninvocation' }, { include: '@functioninvocation' },
['@identifier', 'support.function.name'], ['@identifier', 'meta'],
[';', 'punctuation', '@pop'], [';', 'delimiter', '@pop'],
['(?=})', { token: '', next: '@pop' }], // missing semicolon ['(?=})', { token: '', next: '@pop' }], // missing semicolon
['{', { token: 'punctuation.curly', bracket: '@open', switchTo: '@selectorbody' }], ['{', { token: 'delimiter.curly', bracket: '@open', switchTo: '@selectorbody' }],
], ],
keyframedeclaration: [ keyframedeclaration: [
['@identifier', 'support.function.name'], ['@identifier', 'meta'],
['{', { token: 'punctuation.curly', bracket: '@open', switchTo: '@keyframebody' }], ['{', { token: 'delimiter.curly', bracket: '@open', switchTo: '@keyframebody' }],
], ],
keyframebody: [ keyframebody: [
{ include: '@term' }, { include: '@term' },
['{', { token: 'punctuation.curly', bracket: '@open', next: '@selectorbody' }], ['{', { token: 'delimiter.curly', bracket: '@open', next: '@selectorbody' }],
['}', { token: 'punctuation.curly', bracket: '@close', next: '@pop' }], ['}', { token: 'delimiter.curly', bracket: '@close', next: '@pop' }],
], ],
controlstatement: [ controlstatement: [
['[@](if|else|for|while|each|media)', { token: 'keyword.flow.control.at-rule', next: '@controlstatementdeclaration' }], ['[@](if|else|for|while|each|media)', { token: 'keyword.flow', next: '@controlstatementdeclaration' }],
], ],
controlstatementdeclaration: [ controlstatementdeclaration: [
['(in|from|through|if|to)\\b', { token: 'keyword.flow.control.at-rule' }], ['(in|from|through|if|to)\\b', { token: 'keyword.flow' }],
{ include: '@term' }, { include: '@term' },
['{', { token: 'punctuation.curly', bracket: '@open', switchTo: '@selectorbody' }], ['{', { token: 'delimiter.curly', bracket: '@open', switchTo: '@selectorbody' }],
], ],
functionbody: [ functionbody: [
@ -242,35 +242,35 @@ export var language = <IMonarchLanguage> {
{ include: '@variabledeclaration' }, { include: '@variabledeclaration' },
{ include: '@term' }, { include: '@term' },
{ include: '@controlstatement' }, { include: '@controlstatement' },
[';', 'punctuation'], [';', 'delimiter'],
['}', { token: 'punctuation.curly', bracket: '@close', next: '@pop' }], ['}', { token: 'delimiter.curly', bracket: '@close', next: '@pop' }],
], ],
functioninvocation: [ functioninvocation: [
['@identifier\\(', { token: 'support.function.name', bracket: '@open', next: '@functionarguments' }], ['@identifier\\(', { token: 'meta', bracket: '@open', next: '@functionarguments' }],
], ],
functionarguments: [ functionarguments: [
['\\$@identifier@ws:', TOKEN_PROPERTY], ['\\$@identifier@ws:', TOKEN_PROPERTY],
['[,]', 'punctuation'], ['[,]', 'delimiter'],
{ include: '@term' }, { include: '@term' },
['\\)', { token: 'support.function.name', bracket: '@close', next: '@pop' }], ['\\)', { token: 'meta', bracket: '@close', next: '@pop' }],
], ],
strings: [ strings: [
['~?"', { token: 'string.punctuation', bracket: '@open', next: '@stringenddoublequote' }], ['~?"', { token: 'string.delimiter', bracket: '@open', next: '@stringenddoublequote' }],
['~?\'', { token: 'string.punctuation', bracket: '@open', next: '@stringendquote' }] ['~?\'', { token: 'string.delimiter', bracket: '@open', next: '@stringendquote' }]
], ],
stringenddoublequote: [ stringenddoublequote: [
['\\\\.', 'string'], ['\\\\.', 'string'],
['"', { token: 'string.punctuation', next: '@pop', bracket: '@close' }], ['"', { token: 'string.delimiter', next: '@pop', bracket: '@close' }],
['.', 'string'] ['.', 'string']
], ],
stringendquote: [ stringendquote: [
['\\\\.', 'string'], ['\\\\.', 'string'],
['\'', { token: 'string.punctuation', next: '@pop', bracket: '@close' }], ['\'', { token: 'string.delimiter', next: '@pop', bracket: '@close' }],
['.', 'string'] ['.', 'string']
] ]
} }

View file

@ -45,6 +45,7 @@ requirejs([
'out/test/r.test', 'out/test/r.test',
'out/test/razor.test', 'out/test/razor.test',
'out/test/ruby.test', 'out/test/ruby.test',
'out/test/scss.test',
'out/test/swift.test', 'out/test/swift.test',
'out/test/sql.test', 'out/test/sql.test',
'out/test/vb.test', 'out/test/vb.test',

2054
test/scss.test.ts Normal file

File diff suppressed because it is too large Load diff