Adding syntax generation

This commit is contained in:
Tom MacWright 2011-02-07 15:10:58 -05:00
parent b84def6df1
commit c41e5061fd
2 changed files with 154 additions and 0 deletions

29
build/syntaxgenerate Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
_ = require('underscore')._,
sys = require('sys');
var carto = require('../lib/carto');
var tm_tmpl = fs.readFileSync(path.join(__dirname, 'tmlanguage_template.js'), 'utf-8');
var color_names = _.keys(carto.tree.Reference.data.colors);
var property_names = carto.tree.Reference.selectors;
var keyword_names = _.reduce(carto.tree.Reference.data.symbolizers,
function(memo, s) {
for (var i in s) {
if (_.isArray(s[i].type)) {
memo = memo.concat(s[i].type);
}
}
return memo;
}, []);
fs.writeFile('carto.tmLanguage', _.template(tm_tmpl, {
color_names: color_names.join('|'),
keyword_names: keyword_names.join('|'),
property_names: property_names.join('|')
}), function(err) {
if (!err) console.log('tmLanguage created');
});

View File

@ -0,0 +1,125 @@
{ scopeName = 'source.css.carto';
comment = 'Carto';
fileTypes = ( 'mss' );
foldingStartMarker = '/\*\*(?!\*)|\{\s*($|/\*(?!.*?\*/.*\S))';
foldingStopMarker = '(?<!\*)\*\*/|^\s*\}';
patterns = (
{ name = 'keyword.control.mss.elements';
match = '\b(Map)\b';
},
{ name = 'string.quoted.double.mss';
begin = '"';
end = '"';
patterns = (
{ name = 'constant.character.escaped.css';
match = '\\.';
},
);
},
{ name = 'string.quoted.single.mss';
begin = "'";
end = "'";
patterns = (
{ name = 'constant.character.escaped.mss';
match = '\\.';
},
);
},
{ match = '(\.[a-zA-Z0-9_-]+)[\s,{;]';
captures = { 1 = { name = 'entity.other.attribute-name.class.mss'; }; };
},
{ name = 'support.function.any-method.builtin.css';
contentName = 'variable.parameter.url';
begin = 'url\(';
end = '\)';
},
{ name = 'constant.other.rgb-value.css';
match = '(#)([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b';
},
{ name = 'meta.selector.css';
match = '#[a-zA-Z0-9_-]+';
captures = { 0 = { name = 'entity.other.attribute-name.id'; }; };
},
{ name = 'comment.block.css';
begin = '/\*';
end = '\*/';
},
{ name = 'constant.numeric.css';
match = '(-|\+)?\s*[0-9]+(\.[0-9]+)?';
},
{ name = 'keyword.unit.css';
match = '(?<=[\d])(px|pt|cm|mm|in|em|ex|pc)\b|%';
},
{ name = 'entity.other.attribute-name.pseudo-element.css';
match = '(:+)\b(after|before|first-child|first-letter|first-line|selection)\b';
captures = { 1 = { name = 'punctuation.definition.entity.css'; }; };
},
{ name = 'entity.other.attribute-name.pseudo-class.css';
match = '(:)\b(active|hover|link|visited|focus)\b';
captures = { 1 = { name = 'punctuation.definition.entity.css'; }; };
},
{ name = 'meta.attribute-selector.css';
match = '(?i)(\[)\s*(-?[_a-z\\[[:^ascii:]]][_a-z0-9\-\\[[:^ascii:]]]*)(?:\s*([~|^$*]?=)\s*(?:(-?[_a-z\\[[:^ascii:]]][_a-z0-9\-\\[[:^ascii:]]]*)|((?>([''"])(?:[^\\]|\\.)*?(\6)))))?\s*(\])';
captures = {
1 = { name = 'punctuation.definition.entity.css'; };
2 = { name = 'entity.other.attribute-name.attribute.css'; };
3 = { name = 'punctuation.separator.operator.css'; };
4 = { name = 'string.unquoted.attribute-value.css'; };
5 = { name = 'string.quoted.double.attribute-value.css'; };
6 = { name = 'punctuation.definition.string.begin.css'; };
7 = { name = 'punctuation.definition.string.end.css'; };
};
},
{ name = 'meta.at-rule.import.css';
match = '^\s*((@)import\b)';
captures = {
1 = { name = 'keyword.control.at-rule.import.css'; };
2 = { name = 'punctuation.definition.keyword.css'; };
};
},
{ match = '\b(<%= property_names %>)\s*:';
captures = { 1 = { name = 'support.type.property-name.css'; }; };
},
{ name = 'support.constant.property-value.css';
match = '\b(<%= keyword_names %>)\b';
},
{ name = 'support.constant.color.w3c-standard-color-name.css';
comment = 'http://www.w3.org/TR/CSS21/syndata.html#value-def-color';
match = '\b(<%= color_names %>)\b';
},
{ name = 'support.function.any-method.builtin.less';
match = '\b(saturate|desaturate|lighten|darken|grayscale)\b';
},
{ name = 'support.function.any-method.builtin.css';
match = '\b(rgb|rgba|hsl|hsla|url)\b';
},
{ match = '(-(?:webkit|moz|khtml|o|icab)-(?:gradient|linear-gradient))';
captures = { 1 = { name = 'support.function.any-method.vendor.css'; }; };
},
{ name = 'support.function.any-method.webkit.gradient.css';
match = '\b(color-stop|from|to)\b';
},
{ match = '(\.[a-zA-Z0-9_-]+)\s*(;|\()';
captures = { 1 = { name = 'support.function.less'; }; };
},
{ name = 'comment.line.double-slash.less';
begin = '//';
end = '$\n?';
},
{ name = 'variable.other.less';
match = '@[a-zA-Z0-9_-][\w-]*';
},
{ name = 'keyword.operator.less';
match = '\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\/\b';
},
{ name = 'meta.brace.curly.js';
match = '\{|\}';
},
{ name = 'meta.brace.round.js';
match = '\(|\)';
},
{ name = 'meta.brace.square.js';
match = '\[|\]';
},
);
}