diff --git a/README.md b/README.md index 1a18dd1..99f66da 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Sublime syntax highlighting for CJSX +## Version Support + +This package uses the `.sublime-syntax` syntax definition for rich highlighting and improved performance. As a consequence, only Sublime Text 3, Build 3103 and newer is supported. If you're using Sublime Text 2 or an older version of Sublime Text 3, you can retrieve the old `.tmLanguage` file from [this commit](https://github.com/Guidebook/sublime-cjsx/tree/b23f7cd2fbad387f904a8ead2cb3a79f983c9897) -- however, only the master `.sublime-syntax` definition will receive future updates. + ## Installation ### Install via Package Control diff --git a/syntax/CJSX.sublime-syntax b/syntax/CJSX.sublime-syntax new file mode 100644 index 0000000..a7d2ba6 --- /dev/null +++ b/syntax/CJSX.sublime-syntax @@ -0,0 +1,377 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: CJSX +comment: CJSX Syntax +file_extensions: + - cjsx + - coffee + - Cakefile + - coffee.erb + - cson +first_line_match: ^#!.*\bcoffee +scope: source.coffee +contexts: + main: + - include: jsx + - match: '(\([^()]*?\))\s*([=-]>)' + comment: "match stuff like: a -> …" + scope: meta.inline.function.coffee + captures: + 1: variable.parameter.function.coffee + 2: storage.type.function.coffee + - match: (new)\s+(\w+(?:\.\w*)*) + scope: meta.class.instance.constructor + captures: + 1: keyword.operator.new.coffee + 2: support.class.coffee + - match: "'''" + captures: + 0: punctuation.definition.string.begin.coffee + push: + - meta_scope: string.quoted.heredoc.coffee + - match: "'''" + captures: + 0: punctuation.definition.string.end.coffee + pop: true + - match: '"""' + captures: + 0: punctuation.definition.string.begin.coffee + push: + - meta_scope: string.quoted.double.heredoc.coffee + - match: '"""' + captures: + 0: punctuation.definition.string.end.coffee + pop: true + - match: \\. + scope: constant.character.escape.coffee + - include: interpolated_coffee + - match: "`" + captures: + 0: punctuation.definition.string.begin.coffee + push: + - meta_scope: string.quoted.script.coffee + - match: "`" + captures: + 0: punctuation.definition.string.end.coffee + pop: true + - match: '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)' + scope: constant.character.escape.coffee + - match: (?)|\+\+|\+|~|==|=(?!>)|!=|<=|>=|<<=|>>=| + >>>=|<>|<|>|!|&&|\.\.(\.)?|\?|\||\|\||\:|\*=|(?)))' + scope: variable.assignment.coffee + captures: + 1: variable.assignment.coffee + 4: punctuation.separator.key-value + 5: keyword.operator.coffee + - match: '(?<=\s|^)([\[\{])(?=.*?[\]\}]\s+[:=])' + captures: + 0: keyword.operator.coffee + push: + - meta_scope: meta.variable.assignment.destructured.coffee + - match: '([\]\}]\s*[:=])' + captures: + 0: keyword.operator.coffee + pop: true + - include: variable_name + - include: instance_variable + - include: jsx-single-quoted-prop + - include: jsx-double-quoted-prop + - include: numeric + - match: |- + (?x) + (\s*) + (?=[a-zA-Z\$_]) + ( + [a-zA-Z\$_](\w|\$|:|\.)*\s* + (?=[:=](\s*\(.*\))?\s*([=-]>)) + ) + scope: meta.function.coffee + captures: + 2: entity.name.function.coffee + 3: entity.name.function.coffee + 4: variable.parameter.function.coffee + 5: storage.type.function.coffee + - match: ^\s*(describe|it|app\.(get|post|put|all|del|delete)) + comment: Show well-known functions from Express and Mocha in Go To Symbol view + push: + - meta_scope: meta.function.symbols.coffee + - match: $ + pop: true + - include: main + - match: "[=-]>" + scope: storage.type.function.coffee + - match: '\b(?) + captures: + 1: punctuation.definition.tag.begin.coffee + 2: entity.name.tag.coffee + push: + - meta_scope: jsx.tag-area.coffee + - match: '(]*>)|(\/>)' + captures: + 1: punctuation.definition.tag.begin.coffee + 2: entity.name.tag.coffee + 4: punctuation.definition.tag.end.coffee + pop: true + - include: jsx-tag-attributes + - include: jsx + jsx-tag-attribute-name: + - match: '\b([a-zA-Z_:][a-zA-Z_:0-9\-\.]*)' + scope: meta.tag.attribute-name.html + captures: + 1: entity.other.attribute-name.html + jsx-tag-attributes: + - include: jsx-tag-attribute-name + - include: jsx-double-quoted-prop + - include: jsx-single-quoted-prop + - include: jsx-evaluated-code + jsx-tag-close: + - match: '(]+)(>)|(\/>)' + scope: tag.close.coffee + captures: + 1: punctuation.definition.tag.begin.coffee + 2: entity.name.tag.coffee + 3: punctuation.definition.tag.end.coffee + jsx-tag-invalid: + - match: <\s*> + scope: invalid.illegal.tag.incomplete.coffee + jsx-tag-open: + - match: "(<)([a-zA-Z0-9:.]+)" + captures: + 1: punctuation.definition.tag.begin.coffee + 2: entity.name.tag.coffee + push: + - meta_scope: tag.open.coffee + - match: (/?>) + captures: + 1: punctuation.definition.tag.end.coffee + pop: true + - include: jsx-tag-attributes + numeric: + - match: '(? - - - - comment - CJSX Syntax - fileTypes - - cjsx - coffee - Cakefile - coffee.erb - cson - - firstLineMatch - ^#!.*\bcoffee - foldingStartMarker - ^\s*class\s+\S.*$|.*(->|=>)\s*$|.*[\[{]\s*$ - foldingStopMarker - ^\s*$|^\s*[}\]]\s*$ - keyEquivalent - ^~C - name - CJSX - patterns - - - include - #jsx - - - captures - - 1 - - name - variable.parameter.function.coffee - - 2 - - name - storage.type.function.coffee - - - comment - match stuff like: a -> … - match - (\([^()]*?\))\s*([=-]>) - name - meta.inline.function.coffee - - - captures - - 1 - - name - keyword.operator.new.coffee - - 2 - - name - support.class.coffee - - - match - (new)\s+(\w+(?:\.\w*)*) - name - meta.class.instance.constructor - - - begin - ''' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.coffee - - - end - ''' - endCaptures - - 0 - - name - punctuation.definition.string.end.coffee - - - name - string.quoted.heredoc.coffee - - - begin - """ - beginCaptures - - 0 - - name - punctuation.definition.string.begin.coffee - - - end - """ - endCaptures - - 0 - - name - punctuation.definition.string.end.coffee - - - name - string.quoted.double.heredoc.coffee - patterns - - - match - \\. - name - constant.character.escape.coffee - - - include - #interpolated_coffee - - - - - begin - ` - beginCaptures - - 0 - - name - punctuation.definition.string.begin.coffee - - - end - ` - endCaptures - - 0 - - name - punctuation.definition.string.end.coffee - - - name - string.quoted.script.coffee - patterns - - - match - \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.) - name - constant.character.escape.coffee - - - - - begin - (?<!#)###(?!#) - captures - - 0 - - name - punctuation.definition.comment.coffee - - - end - ### - name - comment.block.coffee - patterns - - - match - @\w* - name - storage.type.annotation.coffeescript - - - - - captures - - 1 - - name - punctuation.definition.comment.coffee - - - match - (#)(?!\{).*$\n? - name - comment.line.number-sign.coffee - - - begin - /{3} - end - /{3}[imgy]{0,4} - name - string.regexp.coffee - patterns - - - include - #interpolated_coffee - - - include - #embedded_comment - - - - - match - /(?![\s=/*+{}?]).*?[^\\]/[igmy]{0,4}(?![a-zA-Z0-9]) - name - string.regexp.coffee - - - match - (?x) - \b(?<![\.\$])( - break|by|catch|continue|else|finally|for|in|of|if|return|switch| - then|throw|try|unless|when|while|until|loop|do|(?<=for)\s+own - )(?!\s*:)\b - - name - keyword.control.coffee - - - match - (?x) - and=|or=|!|%|&|\^|\*|\/|(\-)?\-(?!>)|\+\+|\+|~|==|=(?!>)|!=|<=|>=|<<=|>>=| - >>>=|<>|<|>|!|&&|\.\.(\.)?|\?|\||\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=| - \^=|\b(?<![\.\$])(instanceof|new|delete|typeof|and|or|is|isnt|not|super)\b - - name - keyword.operator.coffee - - - captures - - 1 - - name - variable.assignment.coffee - - 4 - - name - punctuation.separator.key-value - - 5 - - name - keyword.operator.coffee - - - match - ([a-zA-Z\$_](\w|\$|\.)*\s*(?!\::)((:)|(=[^=]))(?!(\s*\(.*\))?\s*((=|-)>))) - name - variable.assignment.coffee - - - begin - (?<=\s|^)([\[\{])(?=.*?[\]\}]\s+[:=]) - beginCaptures - - 0 - - name - keyword.operator.coffee - - - end - ([\]\}]\s*[:=]) - endCaptures - - 0 - - name - keyword.operator.coffee - - - name - meta.variable.assignment.destructured.coffee - patterns - - - include - #variable_name - - - include - #instance_variable - - - include - #jsx-single-quoted-prop - - - include - #jsx-double-quoted-prop - - - include - #numeric - - - - - captures - - 2 - - name - entity.name.function.coffee - - 3 - - name - entity.name.function.coffee - - 4 - - name - variable.parameter.function.coffee - - 5 - - name - storage.type.function.coffee - - - match - (?x) - (\s*) - (?=[a-zA-Z\$_]) - ( - [a-zA-Z\$_](\w|\$|:|\.)*\s* - (?=[:=](\s*\(.*\))?\s*([=-]>)) - ) - - name - meta.function.coffee - - - begin - ^\s*(describe|it|app\.(get|post|put|all|del|delete)) - comment - Show well-known functions from Express and Mocha in Go To Symbol view - end - $ - name - meta.function.symbols.coffee - patterns - - - include - $self - - - - - match - [=-]> - name - storage.type.function.coffee - - - match - \b(?<!\.)(true|on|yes)(?!\s*[:=])\b - name - constant.language.boolean.true.coffee - - - match - \b(?<!\.)(false|off|no)(?!\s*[:=])\b - name - constant.language.boolean.false.coffee - - - match - \b(?<!\.)null(?!\s*[:=])\b - name - constant.language.null.coffee - - - match - \b(?<!\.)(this|extends)(?!\s*[:=])\b - name - variable.language.coffee - - - captures - - 1 - - name - storage.type.class.coffee - - 2 - - name - entity.name.type.class.coffee - - 3 - - name - keyword.control.inheritance.coffee - - 4 - - name - entity.other.inherited-class.coffee - - - match - (class\b)\s+(@?[a-zA-Z\$_][\w\.]*)?(?:\s+(extends)\s+(@?[a-zA-Z\$\._][\w\.]*))? - name - meta.class.coffee - - - match - \b(debugger|\\)\b - name - keyword.other.coffee - - - match - (?x)\b( - Array|ArrayBuffer|Blob|Boolean|Date|document|event|Function| - Int(8|16|32|64)Array|Math|Map|Number| - Object|Proxy|RegExp|Set|String|WeakMap| - window|Uint(8|16|32|64)Array|XMLHttpRequest - )\b - name - support.class.coffee - - - match - ((?<=console\.)(debug|warn|info|log|error|time|timeEnd|assert))\b - name - support.function.console.coffee - - - match - (?x)\b( - decodeURI(Component)?|encodeURI(Component)?|eval|parse(Float|Int)|require - )\b - name - support.function.coffee - - - match - (?x)((?<=\.)( - apply|call|concat|every|filter|forEach|from|hasOwnProperty|indexOf| - isPrototypeOf|join|lastIndexOf|map|of|pop|propertyIsEnumerable|push| - reduce(Right)?|reverse|shift|slice|some|sort|splice|to(Locale)?String| - unshift|valueOf - ))\b - name - support.function.method.array.coffee - - - match - (?x)((?<=Array\.)( - isArray - ))\b - name - support.function.static.array.coffee - - - match - (?x)((?<=Object\.)( - create|definePropert(ies|y)|freeze|getOwnProperty(Descriptors?|Names)| - getProperty(Descriptor|Names)|getPrototypeOf|is(Extensible|Frozen|Sealed)?| - isnt|keys|preventExtensions|seal - ))\b - name - support.function.static.object.coffee - - - match - (?x)((?<=Math\.)( - abs|acos|acosh|asin|asinh|atan|atan2|atanh|ceil|cos|cosh|exp|expm1|floor| - hypot|log|log10|log1p|log2|max|min|pow|random|round|sign|sin|sinh|sqrt| - tan|tanh|trunc - ))\b - name - support.function.static.math.coffee - - - match - (?x)((?<=Number\.)( - is(Finite|Integer|NaN)|toInteger - ))\b - name - support.function.static.number.coffee - - - match - \b(Infinity|NaN|undefined)\b - name - constant.language.coffee - - - match - \; - name - punctuation.terminator.statement.coffee - - - match - ,[ |\t]* - name - meta.delimiter.object.comma.coffee - - - match - \. - name - meta.delimiter.method.period.coffee - - - match - \{|\} - name - meta.brace.curly.coffee - - - match - \(|\) - name - meta.brace.round.coffee - - - match - \[|\]\s* - name - meta.brace.square.coffee - - - include - #instance_variable - - - include - #single_quoted_string - - - include - #double_quoted_string - - - include - #numeric - - - repository - - double_quote - - patterns - - - match - \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.) - name - constant.character.escape.coffee - - - include - #interpolated_coffee - - - include - #jsx-entities - - - - double_quoted_string - - patterns - - - begin - " - beginCaptures - - 0 - - name - punctuation.definition.string.begin.coffee - - - end - " - endCaptures - - 0 - - name - punctuation.definition.string.end.coffee - - - name - string.quoted.double.coffee - patterns - - - include - #double_quote - - - - - - embedded_comment - - patterns - - - captures - - 1 - - name - punctuation.definition.comment.coffee - - - match - (?<!\\)(#).*$\n? - name - comment.line.number-sign.coffee - - - - instance_variable - - patterns - - - match - (@)([a-zA-Z_\$]\w*)? - name - variable.other.readwrite.instance.coffee - - - - interpolated_coffee - - patterns - - - begin - \#\{ - captures - - 0 - - name - punctuation.section.embedded.coffee - - - end - \} - name - source.coffee.embedded.source - patterns - - - include - $self - - - - - - jsx - - name - meta.jsx.coffee - patterns - - - include - #jsx-evaluated-code - - - include - #jsx-tag-area - - - include - #jsx-tag-open - - - include - #jsx-tag-close - - - include - #jsx-tag-invalid - - - - jsx-double-quoted-prop - - patterns - - - begin - (?:\s*=\s*)(") - beginCaptures - - 1 - - name - string.quoted.double.punctuation.definition.begin.coffee - - - end - " - endCaptures - - 0 - - name - string.quoted.double.punctuation.definition.end.coffee - - - patterns - - - include - #double_quote - - - match - .*? - name - string.quoted.double.coffee - - - - - - jsx-entities - - patterns - - - captures - - 1 - - name - punctuation.definition.entity.coffee - - 3 - - name - punctuation.definition.entity.coffee - - - match - (&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;) - name - constant.character.entity.coffee - - - match - & - name - invalid.illegal.bad-ampersand.coffee - - - - jsx-evaluated-code - - begin - { - beginCaptures - - 0 - - name - punctuation.definition.brace.curly.start.coffee - - - end - } - endCaptures - - 0 - - name - punctuation.definition.brace.curly.end.coffee - - - name - meta.brace.curly.coffee - patterns - - - include - $self - - - - jsx-single-quoted-prop - - patterns - - - begin - (?:=)\s?*(') - beginCaptures - - 1 - - name - string.quoted.single.punctuation.definition.string.begin.coffee - - - end - ' - endCaptures - - 0 - - name - string.quoted.single.punctuation.definition.string.end.coffee - - - patterns - - - include - #single_quote - - - match - .*? - name - string.quoted.single.coffee - - - - - - jsx-tag-area - - begin - (<)([a-zA-Z0-9:.]+)(?![^ -]*/>) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.coffee - - 2 - - name - entity.name.tag.coffee - - - end - (</)(\2)([^>]*>)|(\/>) - endCaptures - - 1 - - name - punctuation.definition.tag.begin.coffee - - 2 - - name - entity.name.tag.coffee - - 4 - - name - punctuation.definition.tag.end.coffee - - - name - jsx.tag-area.coffee - patterns - - - include - #jsx-tag-attributes - - - include - #jsx - - - - jsx-tag-attribute-name - - captures - - 1 - - name - entity.other.attribute-name.html - - - match - \b([a-zA-Z_:][a-zA-Z_:0-9\-\.]*) - name - meta.tag.attribute-name.html - - jsx-tag-attributes - - patterns - - - include - #jsx-tag-attribute-name - - - include - #jsx-double-quoted-prop - - - include - #jsx-single-quoted-prop - - - include - #jsx-evaluated-code - - - - jsx-tag-close - - captures - - 1 - - name - punctuation.definition.tag.begin.coffee - - 2 - - name - entity.name.tag.coffee - - 3 - - name - punctuation.definition.tag.end.coffee - - - match - (</)([^>]+)(>)|(\/>) - name - tag.close.coffee - - jsx-tag-invalid - - match - <\s*> - name - invalid.illegal.tag.incomplete.coffee - - jsx-tag-open - - begin - (<)([a-zA-Z0-9:.]+) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.coffee - - 2 - - name - entity.name.tag.coffee - - - end - (/?>) - endCaptures - - 1 - - name - punctuation.definition.tag.end.coffee - - - name - tag.open.coffee - patterns - - - include - #jsx-tag-attributes - - - - numeric - - patterns - - - match - (?<!\$)\b((0([box])[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b - name - constant.numeric.coffee - - - - single_quote - - patterns - - - match - \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.) - name - constant.character.escape.coffee - - - include - #jsx-entities - - - - single_quoted_string - - patterns - - - begin - ' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.coffee - - - end - ' - endCaptures - - 0 - - name - punctuation.definition.string.end.coffee - - - name - string.quoted.single.coffee - patterns - - - include - #single_quote - - - - - - variable_name - - patterns - - - captures - - 1 - - name - variable.assignment.coffee - - - match - ([a-zA-Z\$_]\w*(\.\w+)*) - name - variable.assignment.coffee - - - - - scopeName - source.coffee - -