From c41e5061fd2a58ef7930f88479b8d9ef0f135399 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 7 Feb 2011 15:10:58 -0500 Subject: [PATCH] Adding syntax generation --- build/syntaxgenerate | 29 ++++++++ build/tmlanguage_template.js | 125 +++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100755 build/syntaxgenerate create mode 100644 build/tmlanguage_template.js diff --git a/build/syntaxgenerate b/build/syntaxgenerate new file mode 100755 index 0000000..1ac3c3c --- /dev/null +++ b/build/syntaxgenerate @@ -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'); +}); diff --git a/build/tmlanguage_template.js b/build/tmlanguage_template.js new file mode 100644 index 0000000..1dd25ad --- /dev/null +++ b/build/tmlanguage_template.js @@ -0,0 +1,125 @@ +{ scopeName = 'source.css.carto'; + comment = 'Carto'; + fileTypes = ( 'mss' ); + foldingStartMarker = '/\*\*(?!\*)|\{\s*($|/\*(?!.*?\*/.*\S))'; + foldingStopMarker = '(?([''"])(?:[^\\]|\\.)*?(\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 = '\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|(?