From 38697cafe1aa0510641eb9a5dbeebb5d28517397 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 24 Aug 2024 23:31:39 +0200 Subject: [PATCH] Refactor syntax Fixes #128 Fixes #153 Fixes #203 Fixes #212 Fixes #214 Fixes #215 Fixes #221 Fixes #248 Fixes #250 Fixes #252 --- CoffeeScript Literate.sublime-syntax | 3 +- CoffeeScript.sublime-syntax | 781 +++++++++++++++++++-------- Symbol List.tmPreferences | 2 +- tests/syntax_test_scope.coffee | 526 +++++++++++++++++- tests/syntax_test_scope.litcoffee | 51 +- 5 files changed, 1110 insertions(+), 253 deletions(-) diff --git a/CoffeeScript Literate.sublime-syntax b/CoffeeScript Literate.sublime-syntax index 1f3002a..c058105 100644 --- a/CoffeeScript Literate.sublime-syntax +++ b/CoffeeScript Literate.sublime-syntax @@ -157,7 +157,6 @@ contexts: | [ ]{,3}(?[-*_])([ ]{,2}\k){2,}[ \t]*+$ ) push: - - include: block_raw - include: heading - include: separator - match: ^ @@ -175,7 +174,7 @@ contexts: pop: true - include: inline block_raw: - - include: scope:source.coffee + - include: scope:source.coffee#script bold: - match: |- (?x) diff --git a/CoffeeScript.sublime-syntax b/CoffeeScript.sublime-syntax index b568d47..c94f226 100644 --- a/CoffeeScript.sublime-syntax +++ b/CoffeeScript.sublime-syntax @@ -12,259 +12,590 @@ file_extensions: - cson - cjsx -first_line_match: ^#!.*\bcoffee +first_line_match: |- + (?xi: + ^ \#! .* \b(coffee(-script)?)\b # shebang + | ^ \s* \# .*? -\*- .*? \bcoffee(-script)?\b .*? -\*- # editorconfig + ) + +############################################################################## contexts: + main: - - 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+((?!class)\w+(?:\.\w*)*) - scope: meta.class.instance.constructor - captures: - 1: keyword.operator.new.coffee - 2: support.class.coffee - - match: "'''" - scope: punctuation.definition.string.begin.coffee - push: - - meta_scope: meta.string.coffee string.quoted.heredoc.coffee - - match: "'''" - scope: punctuation.definition.string.end.coffee - pop: true - - match: '"""' - scope: punctuation.definition.string.begin.coffee - push: - - meta_scope: meta.string.coffee string.quoted.double.heredoc.coffee - - match: '"""' - scope: punctuation.definition.string.end.coffee - pop: true - - match: \\. - scope: constant.character.escape.coffee - - include: interpolated_coffee - - match: '`' - scope: punctuation.definition.string.begin.coffee - push: - - meta_scope: meta.string.coffee string.quoted.script.coffee - - match: '`' - scope: 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 + 1: punctuation.definition.variable.coffee + + line-comment-body: + - meta_scope: comment.line.number-sign.coffee + - match: $\n? + pop: true + + shebang: + - meta_include_prototype: false + - match: ^\#! + scope: punctuation.definition.comment.coffee + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Python is embedded. + pop: true + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.coffee + # Note: Keep sync with first_line_match! + - match: coffee(?:\d(?:\.\d+)?)?\b + scope: constant.language.shebang.coffee + - match: $\n? + pop: true + +###[ CLASS DECLARATIONS ]##################################################### + + classes: + - match: (class\b)\s+((?!extends)@?[a-zA-Z\$_][\w\.]*)?(?:\s*(extends)\s+(@?[a-zA-Z\$\._][\w\.]*))? + scope: meta.class.coffee captures: - 1: variable.assignment.coffee - 4: punctuation.separator.key-value - 5: keyword.operator.coffee - - match: '(?<=\s|^)([\[\{])(?=.*?[\]\}]\s+[:=])' - scope: keyword.operator.coffee + 1: storage.type.class.coffee + 2: entity.name.type.class.coffee + 3: keyword.control.inheritance.coffee + 4: entity.other.inherited-class.coffee + +###[ FUNCTION DECLARATIONS ]################################################## + + functions: + # Show well-known functions from Express and Mocha in Go To Symbol view + - match: ^\s*(describe|it|app\.(get|post|put|all|del|delete))[^\w] push: - - meta_scope: meta.variable.assignment.destructured.coffee - - match: '([\]\}]\s*[:=])' - scope: keyword.operator.coffee + - meta_scope: meta.function.symbols.coffee + - match: $ pop: true - - include: variable_name - - include: instance_variable - - include: single_quoted_string - - include: double_quoted_string - - include: numeric + - include: script + # anonymous functions + - match: (?=\([^()]*?\)\s*[=-]>) + push: function-parameter-list + # named functions - match: |- (?x) \s* ( [a-zA-Z\$_@] [\w\$:.]* ) \s* (?=[:=](?: \s*.\( $ | (?: \s*\(.*\) )? \s* [=-]> ) ) - scope: meta.function.coffee + scope: meta.function.identifier.coffee captures: 1: entity.name.function.coffee - - match: '^\s*(describe|it|app\.(get|post|put|all|del|delete))[^\w]' - 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 + push: function-parameter-list - match: '[=-]>' - scope: storage.type.function.coffee - - match: '\b(?)' + scope: keyword.operator.assignment.coffee + - match: \( + scope: punctuation.section.parameters.begin.coffee + set: function-parameter-list-body + - match: (?=\S) + set: function-body + + function-parameter-list-body: + - meta_scope: meta.function.parameters.coffee + - match: \) + scope: punctuation.section.parameters.end.coffee + set: function-body + - match: '[:=]' + scope: keyword.operator.assignment.coffee + push: parameter-value + - match: \.{2,3} + scope: keyword.operator.variadic.coffee + - match: '{{identifier}}' + scope: variable.parameter.coffee + - include: comma-separators + - include: comments + + parameter-value: + - match: (?=[,)]) + pop: true + - include: expressions + + function-body: + - meta_content_scope: meta.function.coffee + - match: '[=-]>' + scope: meta.function.coffee keyword.declaration.function.coffee + pop: true + - include: else-pop + +###[ FUNCTION CALLS ]######################################################### + + function-calls: - match: |- - (?x)\b( - decodeURI(Component)?|encodeURI(Component)?|eval|parse(Float|Int)|require - )\b + (?x) + ( decodeURI(?: Component)? | encodeURI(?: Component)? | eval + | parse(?: Float | Int ) | require )\b scope: 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 - scope: support.function.method.array.coffee + (?x) + (console) + (?: + (\.) + ( assert | debug | dir | error | info | log | time | timeEnd | warn )\b + )? + scope: meta.path.coffee + captures: + 1: variable.language.console.coffee + 2: punctuation.accessor.dot.coffee + 3: support.function.console.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 + scope: meta.path.coffee + captures: + 1: punctuation.accessor.dot.coffee + 2: support.function.method.array.coffee - match: |- - (?x)((?<=Array\.)( - isArray - ))\b - scope: support.function.static.array.coffee + (?x) + (Array) + (?: + (\.) + ( isArray )\b + )? + scope: meta.path.coffee + captures: + 1: support.class.coffee + 2: punctuation.accessor.dot.coffee + 3: 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 - scope: support.function.static.object.coffee + (?x) + (Object) + (?: + (\.) + ( create | definePropert(?: ies | y ) | freeze | getOwnProperty(?: Descriptors? | Names ) + | getProperty(Descriptor | Names) | getPrototypeOf | is(?: Extensible | Frozen | Sealed)? + | isnt | keys | preventExtensions | seal )\b + )? + scope: meta.path.coffee + captures: + 1: support.class.coffee + 2: punctuation.accessor.dot.coffee + 3: 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 - scope: support.function.static.math.coffee + (?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 + )? + scope: meta.path.coffee + captures: + 1: support.class.coffee + 2: punctuation.accessor.dot.coffee + 3: support.function.static.math.coffee - match: |- - (?x)((?<=Number\.)( - is(Finite|Integer|NaN)|toInteger - ))\b - scope: support.function.static.number.coffee - - match: \b(Infinity|NaN|undefined)\b - scope: constant.language.coffee + (?x) + (Number) + (?: + (\.) + ( is(?: Finite | Integer | NaN ) | toInteger )\b + )? + scope: meta.path.coffee + captures: + 1: support.class.coffee + 2: punctuation.accessor.dot.coffee + 3: support.function.static.number.coffee + # other classes + - match: |- + (?x) + \b( ArrayBuffer | Blob | Boolean | Date | document | event + | Float(?: 32 | 64)Array | Function | Int(?: 8 | 16 | 32 | 64)Array + | Map | Proxy | RegExp | Set | String | WeakMap | window + | Uint(?: 8 | 16 | 32 | 64)Array | XMLHttpRequest | Symbol )\b + scope: support.class.coffee + # user function calls + - match: '{{identifier}}(?=\()' + scope: meta.function-call.identifier.coffee variable.function.coffee + push: function-call-argument-list + + function-call-argument-list: + - match: \( + scope: punctuation.section.group.begin.coffee + set: function-call-argument-list-body + + function-call-argument-list-body: + - meta_scope: meta.function-call.arguments.coffee + - match: \) + scope: punctuation.section.group.end.coffee + pop: true + - include: script + +###[ KEYWORDS ]############################################################### + + keywords: + # export/import + - match: export(?!\s*:)\b + scope: keyword.control.export.coffee + - match: (?:import|from)(?!\s*:)\b + scope: keyword.control.import.coffee + # excpetion + - match: (?:catch|finally|try)(?!\s*:)\b + scope: keyword.control.exception.coffee + # conditional + - match: if(?!\s*:)\b + scope: keyword.control.conditional.if.coffee + - match: else(?!\s*:)\b + scope: keyword.control.conditional.else.coffee + - match: switch(?!\s*:)\b + scope: keyword.control.conditional.switch.coffee + - match: then(?!\s*:)\b + scope: keyword.control.conditional.then.coffee + - match: unless(?!\s*:)\b + scope: keyword.control.conditional.unless.coffee + - match: when(?!\s*:)\b + scope: keyword.control.conditional.when.coffee + # loop + - match: by(?!\s*:)\b + scope: keyword.control.loop.by.coffee + - match: do(?!\s*:)\b + scope: keyword.control.loop.do.coffee + - match: for(?:\s+own)?(?!\s*:)\b + scope: keyword.control.loop.for.coffee + - match: loop(?!\s*:)\b + scope: keyword.control.loop.loopcoffee + - match: until(?!\s*:)\b + scope: keyword.control.loop.until.coffee + - match: while(?!\s*:)\b + scope: keyword.control.loop.while.coffee + # flow + - match: (?:break|continue|return|throw|yield(?:\s+from)?)(?!\s*:)\b + scope: keyword.control.flow.coffee + # other + - match: (?:debugger\b|\\) + scope: keyword.other.coffee + + operators: + # symbolic + - match: (?:and|or|<<|>>>?|[-+*/%&|^])= + scope: keyword.operator.assignment.augmented.coffee + - match: \+\+?|\-\-?|[*/%] + scope: keyword.operator.arithmetic.coffee + - match: '[=!]==?|[<>]=?' + scope: keyword.operator.comparison.coffee + - match: '&&|\|\||[!?]' + scope: keyword.operator.logical.coffee + - match: '[&|^~]' + scope: keyword.operator.bitwise.coffee + - match: '[:=](?!>)' + scope: keyword.operator.assignment.coffee + - match: \.{2,3} + scope: keyword.operator.variadic.coffee + # alphanumeric + - match: (?:as)\b + scope: keyword.operator.word.coffee keyword.operator.assignment.as.coffee + - match: (?:in|of)\b + scope: keyword.operator.word.coffee keyword.operator.iterator.coffee + - match: (?:and|or|is|isnt|not)\b + scope: keyword.operator.word.coffee keyword.operator.logical.coffee + - match: (?:new)\b + scope: keyword.operator.word.coffee keyword.operator.object.new.coffee + push: maybe-class + - match: (?:delete)\b + scope: keyword.operator.word.coffee keyword.operator.object.delete.coffee + - match: (?:super)\b + scope: keyword.operator.word.coffee keyword.operator.object.super.coffee + - match: (?:instanceof|typeof)\b + scope: keyword.operator.word.coffee keyword.operator.comparison.type.coffee + push: maybe-class + + maybe-class: + - match: ({{identifier}})?(\.) + captures: + 1: support.class.coffee + 2: punctuation.accessor.dot.coffee + - match: '{{identifier}}' + scope: support.class.coffee + pop: true + - include: else-pop + +###[ OBJECTS ]################################################################ + + objects: + - match: (?:this|extends)(?!\s*[:=])\b + scope: variable.language.coffee + - match: ({{identifier}})?(\.) + captures: + 1: variable.other.object.coffee + 2: punctuation.accessor.dot.coffee + push: member + - match: '{{identifier}}' + scope: variable.other.readwrite.coffee + + member: + - meta_scope: meta.path.coffee + # member objects + - match: ({{identifier}})(\.) + captures: + 1: variable.other.object.coffee + 2: punctuation.accessor.dot.coffee + # method + - match: '{{identifier}}(?=\()' + scope: meta.function-call.identifier.coffee variable.function.coffee + set: function-call-argument-list + # member variable + - match: '{{identifier}}' + scope: variable.other.member.coffee + pop: 1 + - include: immediately-pop + + variables: + # member objects + - match: ({{identifier}})(\.) + captures: + 1: variable.other.object.coffee + 2: punctuation.accessor.dot.coffee + - match: '{{identifier}}' + scope: variable.other.member.coffee + +###[ OPERATORS ]############################################################## + + punctuations: + - include: comma-separators - match: \; scope: punctuation.terminator.statement.coffee - - match: ',[ |\t]*' - scope: meta.delimiter.object.comma.coffee - - match: \. - scope: meta.delimiter.method.period.coffee - - match: '\{|\}' - scope: meta.brace.curly.coffee - - match: \(|\) - scope: meta.brace.round.coffee - - match: '\[|\]\s*' - scope: meta.brace.square.coffee - - include: instance_variable - - include: single_quoted_string - - include: double_quoted_string - - include: numeric - double_quoted_string: - - match: '"' + - match: \{ + scope: punctuation.section.block.begin.coffee + - match: \} + scope: punctuation.section.block.end.coffee + - match: \( + scope: punctuation.section.group.begin.coffee + - match: \) + scope: punctuation.section.group.end.coffee + - match: \[ + scope: punctuation.section.brackets.begin.coffee + - match: \] + scope: punctuation.section.brackets.end.coffee + + comma-separators: + - match: \, + scope: punctuation.separator.sequence.coffee + +###[ REGULAR EXPRESSIONS ]##################################################### + + patterns: + - match: /{3} scope: punctuation.definition.string.begin.coffee - push: - - meta_scope: meta.string.coffee string.quoted.double.coffee - - match: '"' - scope: 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 - - include: interpolated_coffee - embedded_comment: - - match: (?' - scope: punctuation.section.embedded.coffee - pop: true - - include: main - numeric: - - match: '(?' + scope: punctuation.section.embedded.coffee + pop: true + - include: script + +###[ VARIABLES ]############################################################### + + instance-variables: + - match: (@)(?:{{identifier}})? + scope: variable.other.readwrite.instance.coffee captures: - 1: variable.assignment.coffee + 1: punctuation.definition.variable.coffee + +###[ PROTOTYPES ]############################################################## + + else-pop: + - match: (?=\S) + pop: true + + immediately-pop: + - match: '' + pop: true + +############################################################################### + + +variables: + + identifier: '[a-zA-Z\$_]\w*' diff --git a/Symbol List.tmPreferences b/Symbol List.tmPreferences index d69d999..92ce429 100644 --- a/Symbol List.tmPreferences +++ b/Symbol List.tmPreferences @@ -5,7 +5,7 @@ scope source.coffee meta.class.coffee, - source.coffee meta.function.coffee + source.coffee meta.function.identifier.coffee entity.name.function settings diff --git a/tests/syntax_test_scope.coffee b/tests/syntax_test_scope.coffee index e6d52e4..75cb467 100644 --- a/tests/syntax_test_scope.coffee +++ b/tests/syntax_test_scope.coffee @@ -1,5 +1,35 @@ # SYNTAX TEST "CoffeeScript.sublime-syntax" +###[ COMMENTS ]############################################################### + +# comment +# <- comment.line.number-sign.coffee punctuation.definition.comment.coffee +#^^^^^^^^^ comment.line.number-sign.coffee + + ### comment ### +# ^^^^^^^^^^^^^^^ comment.block.coffee +# ^^^ punctuation.definition.comment.coffee +# ^^^ punctuation.definition.comment.coffee + + ### +# ^^^^ comment.block.coffee +# ^^^ punctuation.definition.comment.coffee + + class Name +# <- comment.block.coffee +# ^^^^^^^^^^ comment.block.coffee - keyword + + @todo +# ^^^^^ comment.block.coffee variable.annotation.coffee +# ^ punctuation.definition.variable.coffee + + ### +# <- comment.block.coffee +#^^^^ comment.block.coffee +# ^^^ punctuation.definition.comment.coffee + +###[ IMPORT / EXPORT ]######################################################## + import {"foo"} from bar as baz # <- keyword.control.import.coffee #^^^^^ keyword.control.import.coffee @@ -10,6 +40,8 @@ export parentClass # <- keyword.control.export.coffee #^^^^^ keyword.control.export.coffee +###[ CLASSES ]################################################################ + class extends parentClass # <- meta.class.coffee storage.type.class.coffee #^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.coffee @@ -27,23 +59,477 @@ class App.Router extends Snakeskin.Router # ^^^^^^^ keyword.control.inheritance.coffee # ^^^^^^^^^^^^^^^^ entity.other.inherited-class.coffee - index: () => -# <- meta.function.coffee -#^^^^^^ meta.function.coffee -# ^^^^^ entity.name.function.coffee - entity entity -# ^ keyword.operator.coffee -# ^^^^^ meta.inline.function.coffee -# ^^ variable.parameter.function.coffee -# ^^ storage.type.function.coffee - "Hello" -# ^^^^^^^ meta.string.coffee string.quoted.double.coffee - - - keywords: -> - yield @foo -# ^^^^^ keyword.control.coffee -# ^^^^ variable.other.readwrite.instance.coffee - - yield from @foo -# ^^^^^^^^^^ keyword.control.coffee -# ^^^^ variable.other.readwrite.instance.coffee +###[ FUNCTIONS ]############################################################### + + name: +# ^^^^^ - meta.function - entity.name.function + + name: -> +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + @name: -> +# ^^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + namespace.name: -> +# ^^^^^^^^^^^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + name = => +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^ meta.function.identifier.coffee - entity +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + namespace.name = => +# ^^^^^^^^^^^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^ meta.function.identifier.coffee - entity +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + name: => +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + namespace.name: => +# ^^^^^^^^^^^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + name = => +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^ meta.function.identifier.coffee - entity +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + namespace.name = => +# ^^^^^^^^^^^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^ meta.function.identifier.coffee - entity +# ^^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^^ keyword.declaration.function.coffee + + name: () -> +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^ meta.function.coffee +# ^^ meta.function.parameters.coffee +# ^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^ punctuation.section.parameters.begin.coffee +# ^ punctuation.section.parameters.end.coffee +# ^^ keyword.declaration.function.coffee + + name: (foo, bar = undefined, baz="buuz", ...) -> +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^ meta.function.coffee +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.coffee +# ^^^ meta.function.coffee +# ^ keyword.operator.assignment.coffee +# ^ punctuation.section.parameters.begin.coffee +# ^^^ variable.parameter.coffee +# ^ punctuation.separator.sequence.coffee +# ^^^ variable.parameter.coffee +# ^ keyword.operator.assignment.coffee +# ^^^^^^^^^ constant.language.coffee +# ^ punctuation.separator.sequence.coffee +# ^^^ variable.parameter.coffee +# ^ keyword.operator.assignment.coffee +# ^^^^^^ meta.string.coffee string.quoted.double.coffee +# ^ punctuation.separator.sequence.coffee +# ^^^ keyword.operator.variadic.coffee +# ^ punctuation.section.parameters.end.coffee +# ^^ keyword.declaration.function.coffee + + name: ( +# ^^^^ meta.function.identifier.coffee entity.name.function.coffee +# ^^ meta.function.coffee +# ^^ meta.function.parameters.coffee +# ^ punctuation.section.parameters.begin.coffee + foo, +# ^^^ variable.parameter.coffee +# ^ punctuation.separator.sequence.coffee + + bar = undefined, +# ^^^ variable.parameter.coffee +# ^ keyword.operator.assignment.coffee +# ^^^^^^^^^ constant.language.coffee + + baz="buuz" +# ^^^ variable.parameter.coffee +# ^ keyword.operator.assignment.coffee +# ^^^^^^ meta.string.coffee string.quoted.double.coffee + ) -> +#^^ meta.function.parameters.coffee +# <- meta.function.parameters.coffee +# ^ punctuation.section.parameters.end.coffee +# ^^ keyword.declaration.function.coffee + + () -> +# ^^ meta.function.parameters.coffee +# ^^^ meta.function.coffee +# ^ punctuation.section.parameters.begin.coffee +# ^ punctuation.section.parameters.end.coffee +# ^^ keyword.declaration.function.coffee + + () => +# ^^ meta.function.parameters.coffee +# ^^^ meta.function.coffee +# ^ punctuation.section.parameters.begin.coffee +# ^ punctuation.section.parameters.end.coffee +# ^^ keyword.declaration.function.coffee + + (foo) -> +# ^^^^^ meta.function.parameters.coffee +# ^^^ meta.function.coffee +# ^ punctuation.section.parameters.begin.coffee +# ^^^ variable.parameter.coffee +# ^ punctuation.section.parameters.end.coffee +# ^^ keyword.declaration.function.coffee + +###[ KEYWORDS ]################################################################ + + if .if _if $if +# ^^ keyword.control.conditional.if.coffee +# ^^^^^^^^^^^^ - keyword + + for .for _for $for +# ^^^ keyword.control.loop.for.coffee +# ^^^^^^^^^^^^^^^^ - keyword + + break .break _break $break +# ^^^^^ keyword.control.flow.coffee +# ^^^^^^^^^^^^^^^^^^^^^ - keyword + + continue .continue _continue $continue +# ^^^^^^^^ keyword.control.flow.coffee +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - keyword + + yield @foo +# ^^^^^ keyword.control.flow.coffee +# ^^^^ variable.other.readwrite.instance.coffee + + yield from @foo +# ^^^^^^^^^^ keyword.control.flow.coffee +# ^^^^ variable.other.readwrite.instance.coffee + +###[ OPERATORS ]############################################################### + + as +# ^^ keyword.operator.assignment.as.coffee + + in of +# ^^ keyword.operator.iterator.coffee +# ^^ keyword.operator.iterator.coffee + + and or is isnt not +# ^^^ keyword.operator.logical.coffee +# ^^ keyword.operator.logical.coffee +# ^^ keyword.operator.logical.coffee +# ^^^^ keyword.operator.logical.coffee +# ^^^ keyword.operator.logical.coffee + + new +# ^^^ keyword.operator.object.new.coffee + + new Class() +# ^^^ keyword.operator.object.new.coffee +# ^^^^^ support.class.coffee + + new My.Class() +# ^^^ keyword.operator.object.new.coffee +# ^^ support.class.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^ support.class.coffee + + delete +# ^^^^^^ keyword.operator.object.delete.coffee + + delete obj +# ^^^^^^ keyword.operator.object.delete.coffee +# ^^^ variable.other.readwrite.coffee + + obj typeof Bar +# ^^^ variable.other.readwrite.coffee +# ^^^^^^ keyword.operator.comparison.type.coffee +# ^^^ support.class.coffee + + obj instanceof Bar +# ^^^ variable.other.readwrite.coffee +# ^^^^^^^^^^ keyword.operator.comparison.type.coffee +# ^^^ support.class.coffee + + and= or= += -= *= /= %= &= |= ^= <<= >>= >>>= +# ^^^^ keyword.operator.assignment.augmented.coffee +# ^^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^ keyword.operator.assignment.augmented.coffee +# ^^^ keyword.operator.assignment.augmented.coffee +# ^^^ keyword.operator.assignment.augmented.coffee +# ^^^^ keyword.operator.assignment.augmented.coffee + + === == !== != <= >= +# ^^^ keyword.operator.comparison.coffee +# ^^ keyword.operator.comparison.coffee +# ^^^ keyword.operator.comparison.coffee +# ^^ keyword.operator.comparison.coffee +# ^^ keyword.operator.comparison.coffee +# ^^ keyword.operator.comparison.coffee + + i++ i-- +# ^^ keyword.operator.arithmetic.coffee +# ^^ keyword.operator.arithmetic.coffee + + ! ? && || +# ^ keyword.operator.logical.coffee +# ^ keyword.operator.logical.coffee +# ^^ keyword.operator.logical.coffee +# ^^ keyword.operator.logical.coffee + + ^ ~ & | +# ^ keyword.operator.bitwise.coffee +# ^ keyword.operator.bitwise.coffee +# ^ keyword.operator.bitwise.coffee +# ^ keyword.operator.bitwise.coffee + + + - * / % +# ^ keyword.operator.arithmetic.coffee +# ^ keyword.operator.arithmetic.coffee +# ^ keyword.operator.arithmetic.coffee +# ^ keyword.operator.arithmetic.coffee +# ^ keyword.operator.arithmetic.coffee + + = : +# ^ keyword.operator.assignment.coffee +# ^ keyword.operator.assignment.coffee + + ... +# ^^^ keyword.operator.variadic.coffee + +###[ BUILTIN FUNCTIONS ]####################################################### + + console.log() +# ^^^^^^^ variable.language.console.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^ support.function.console.coffee +# ^ punctuation.section.group.begin.coffee +# ^ punctuation.section.group.end.coffee + + Map +# ^^^ support.class.coffee + + Object.create() +# ^^^^^^ support.class.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^ support.function.static.object.coffee +# ^ punctuation.section.group.begin.coffee +# ^ punctuation.section.group.end.coffee + +###[ OBJECT MEMBERS ]########################################################## + + this.key +# ^^^^ variable.language.coffee +# ^ meta.path.coffee punctuation.accessor.dot.coffee +# ^^^ meta.path.coffee variable.other.member.coffee + + obj.Object +# ^^^^^^^^^^ meta.path.coffee +# ^^^ variable.other.object.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^ variable.other.member.coffee + + obj.member +# ^^^^^^^^^^ meta.path.coffee +# ^^^ variable.other.object.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^ variable.other.member.coffee + + obj.child.member +# ^^^^^^^^^^^^^^^^ meta.path.coffee +# ^^^ variable.other.object.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^ variable.other.object.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^ variable.other.member.coffee + + obj.method(1+1, "foo") +# ^^^^^^^^^^ meta.path.coffee +# ^^^^^^ meta.function-call.identifier.coffee +# ^^^^^^^^^^^^ meta.function-call.arguments.coffee +# ^^^ variable.other.object.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^ variable.function.coffee +# ^ punctuation.section.group.begin.coffee +# ^ meta.number.integer.decimal.coffee constant.numeric.value.coffee +# ^ keyword.operator.arithmetic.coffee +# ^ meta.number.integer.decimal.coffee constant.numeric.value.coffee +# ^ punctuation.separator.sequence.coffee +# ^^^^^ meta.string.coffee string.quoted.double.coffee +# ^ punctuation.section.group.end.coffee + +###[ LITERALS ]################################################################ + + Infinity NaN undefined .Infinity .NaN .undefined +# ^^^^^^^^ constant.language.coffee +# ^^^ constant.language.coffee +# ^^^^^^^^^ constant.language.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^^^ variable.other.member.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^ variable.other.member.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^^^^ variable.other.member.coffee + + true on yes .true .on .yes +# ^^^^ constant.language.boolean.true.coffee +# ^^ constant.language.boolean.true.coffee +# ^^^ constant.language.boolean.true.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^ variable.other.member.coffee +# ^ punctuation.accessor.dot.coffee +# ^^ variable.other.member.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^ variable.other.member.coffee + + false off no .false .off .no +# ^^^^^ constant.language.boolean.false.coffee +# ^^^ constant.language.boolean.false.coffee +# ^^ constant.language.boolean.false.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^ variable.other.member.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^ variable.other.member.coffee +# ^ punctuation.accessor.dot.coffee +# ^^ variable.other.member.coffee + + null _null .null +# ^^^^ constant.language.null.coffee +# ^^^^^ variable.other.readwrite.coffee +# ^^^^^ meta.path.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^ variable.other.member.coffee + + 0b1000111101 +# ^^ meta.number.integer.binary.coffee constant.numeric.base.coffee +# ^^^^^^^^^^ meta.number.integer.binary.coffee constant.numeric.value.coffee + + 0o12340576 +# ^^ meta.number.integer.octal.coffee constant.numeric.base.coffee +# ^^^^^^^^ meta.number.integer.octal.coffee constant.numeric.value.coffee + + 0x1234567890ABCDEF +# ^^ meta.number.integer.hexadecimal.coffee constant.numeric.base.coffee +# ^^^^^^^^^^^^^^^^ meta.number.integer.hexadecimal.coffee constant.numeric.value.coffee + + 10e5 +# ^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee + + 10.e5 +# ^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee + + 10.23 +# ^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee + + 10.23e-5 +# ^^^^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee + + 52 +# ^^ meta.number.integer.decimal.coffee constant.numeric.value.coffee + + "foo \. \x28 bar\"" +# ^^^^^^^^^^^^^^^^^^^ meta.string.coffee string.quoted.double.coffee +# ^ punctuation.definition.string.begin.coffee +# ^^ constant.character.escape.coffee +# ^^^^ constant.character.escape.coffee +# ^^ constant.character.escape.coffee +# ^ punctuation.definition.string.end.coffee + + 'foo \. \x28 bar\'' +# ^^^^^^^^^^^^^^^^^^^ meta.string.coffee string.quoted.single.coffee +# ^ punctuation.definition.string.begin.coffee +# ^^ constant.character.escape.coffee +# ^^^^ constant.character.escape.coffee +# ^^ constant.character.escape.coffee +# ^ punctuation.definition.string.end.coffee + + """ +#^ - meta.string - string +# ^^^ meta.string.heredoc.coffee string.quoted.double.coffee punctuation.definition.string.begin.coffee + """ +# <- meta.string.heredoc.coffee string.quoted.double.coffee +#^ meta.string.heredoc.coffee string.quoted.double.coffee +# ^^^ meta.string.heredoc.coffee string.quoted.double.coffee punctuation.definition.string.end.coffee +# ^ - meta.string - string + + ''' +#^ - meta.string - string +# ^^^ meta.string.heredoc.coffee string.quoted.single.coffee punctuation.definition.string.begin.coffee + ''' +# <- meta.string.heredoc.coffee string.quoted.single.coffee +#^ meta.string.heredoc.coffee string.quoted.single.coffee +# ^^^ meta.string.heredoc.coffee string.quoted.single.coffee punctuation.definition.string.end.coffee +# ^ - meta.string - string + + /// +# <- - meta.string +#^ - meta.string +# ^^^ meta.string.regexp.coffee punctuation.definition.string.begin.coffee +# ^ meta.string.regexp.coffee string.regexp.coffee + \. #{var} +#^^^^^^^^^^^ meta.string.regexp.coffee +# ^^ string.regexp.coffee constant.character.escape.coffee +# ^^^^^^ meta.embedded.coffee source.coffee.embedded.source + /// +# <- meta.string.regexp.coffee string.regexp.coffee +#^ meta.string.regexp.coffee string.regexp.coffee +# ^^^ meta.string.regexp.coffee punctuation.definition.string.end.coffee + + /[0-9]bar/img +# ^^^^^^^^^^^^^ meta.string.regexp.coffee +# ^ punctuation.definition.string.begin.coffee +# ^^^^^^^^ string.regexp.coffee +# ^ punctuation.definition.string.end.coffee +# ^^^ constant.language.flags.coffee + + .replace(/\\/g, "/") +# ^^^^^^^^^^^^ meta.function-call.arguments.coffee +# ^^^^^ meta.string.regexp.coffee +# ^ punctuation.definition.string.begin.coffee +# ^^ string.regexp.coffee +# ^ punctuation.definition.string.end.coffee +# ^ constant.language.flags.coffee +# ^ punctuation.separator.sequence.coffee +# ^^^ meta.string.coffee string.quoted.double.coffee + +###[ VARIABLES ]############################################################### + + [object.variable] = 0 +# ^ punctuation.section.brackets.begin.coffee +# ^^^^^^ variable.other.object.coffee +# ^ punctuation.accessor.dot.coffee +# ^^^^^^^^ variable.other.member.coffee +# ^ punctuation.section.brackets.end.coffee +# ^ keyword.operator.assignment.coffee +# ^ meta.number.integer.decimal.coffee constant.numeric.value.coffee + + @variable +# ^^^^^^^^^ variable.other.readwrite.instance.coffee +# ^ punctuation.definition.variable.coffee diff --git a/tests/syntax_test_scope.litcoffee b/tests/syntax_test_scope.litcoffee index 166a607..59dcdbc 100644 --- a/tests/syntax_test_scope.litcoffee +++ b/tests/syntax_test_scope.litcoffee @@ -4,14 +4,55 @@ | <- meta.block-level.markdown markup.heading.markdown punctuation.definition.heading.markdown |^^^^^^^^^ meta.block-level.markdown markup.heading.markdown +# Indendet Code Block class App.Router extends Snakeskin.Router - errorRoutes: { - '404': 'fourOhFour', - '500': 'fiveHundred' - } - index: () => + | <- markup.raw.block.markdown meta.class.coffee storage.type.class.coffee + |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.raw.block.markdown meta.class.coffee + + @index: () => + | ^^^^^^ meta.function.identifier.coffee entity.name.function.coffee + | ^^ meta.function.coffee + | ^^ meta.function.parameters.coffee + | ^^^ meta.function.coffee + | ^^ keyword.declaration.function.coffee @ensureData((data) => @_parseDates(data, ['trending', 'new', 'top']) App.layout.renderExchange('index', data, ['index', 'search']) ) + +> Not in block quotes +> +> class App.Router extends Snakeskin.Router +|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block-level.markdown markup.quote.markdown - markdup.raw + +# https://github.com/SublimeText/CoffeeScript/issues/203 + +This is a test showcasing that multiline string interpolation is broken. Copy this post +into a .litcoffee file and open it in Sublime to see the breakage. + + foo = 69 + baz = 420 + + bar = "This is the value of foo: #{ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.coffee string.quoted.double.coffee + | ^^^ meta.string.coffee meta.embedded.coffee source.coffee.embedded.source + foo + } and this is another variable, baz: #{ + | <- meta.string.coffee meta.embedded.coffee source.coffee.embedded.source punctuation.section.embedded.coffee + |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.coffee string.quoted.double.coffee + | ^^^ meta.string.coffee meta.embedded.coffee source.coffee.embedded.source + baz + }" + | <- meta.string.coffee meta.embedded.coffee source.coffee.embedded.source punctuation.section.embedded.coffee + |^ meta.string.coffee string.quoted.double.coffee punctuation.definition.string.end.coffee + | ^ - meta.string - string + + nowThis.isInterpretedAs 'string' + | <- meta.path.coffee variable.other.object.coffee + |^^^^^^^^^^^^^^^^^^^^^^ meta.path.coffee + | ^^^^^^^^ meta.string.coffee string.quoted.single.coffee + +...even this markdown is as well. :( +| <- meta.paragraph.markdown +|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.paragraph.markdown