Skip to content

Commit

Permalink
Fix groups vs. anonymous functions
Browse files Browse the repository at this point in the history
This commit assumes parentheses as expression group
until it being followed by an arrow.
  • Loading branch information
deathaxe committed Oct 23, 2024
1 parent 0083361 commit 54fa545
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 14 additions & 4 deletions CoffeeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ contexts:
- match: (?=\()
branch_point: anonymous
branch:
- anonymous-parameter-list
- group
- anonymous-parameter-list
# named functions
- match: (?=(?:(?!and=|or=)|@){{identifier}}\s*[:=][^>])
branch_point: function
Expand All @@ -173,13 +173,23 @@ contexts:
- match: '[=-]>'
scope: meta.function.coffee keyword.declaration.function.coffee
pop: 1
- match: (?=\S)
fail: anonymous

group:
- match: \(
scope: punctuation.section.group.begin.coffee
pop: 1
set: group-body

group-body:
- meta_scope: meta.group.coffee
- match: \)
scope: punctuation.section.group.end.coffee
set: group-check
- include: expressions

group-check:
- match: (?=[=-]>)
fail: anonymous
- include: else-pop

function-name:
- meta_include_prototype: false
Expand Down
10 changes: 10 additions & 0 deletions tests/syntax_test_scope.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ class App.Router extends Snakeskin.Router
->
# ^^ keyword.declaration.function.coffee

(a : "group")
# ^^^^^^^^^^^^^ meta.group.coffee
# ^ punctuation.section.group.begin.coffee
# ^ variable.other.readwrite.coffee
# ^ keyword.operator.assignment.coffee
# ^^^^^^^ meta.string.coffee string.quoted.double.coffee
# ^ punctuation.definition.string.begin.coffee
# ^ punctuation.definition.string.end.coffee
# ^ punctuation.section.group.end.coffee

geometry = new Class();
# ^^^^^^^^ variable.other.readwrite.coffee
# ^ keyword.operator.assignment.coffee
Expand Down

0 comments on commit 54fa545

Please sign in to comment.