Skip to content

Commit

Permalink
Fix multi-line function parameter lists
Browse files Browse the repository at this point in the history
Fixes #160
  • Loading branch information
deathaxe committed Aug 27, 2024
1 parent 5e96f22 commit 59f5968
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 50 deletions.
76 changes: 59 additions & 17 deletions CoffeeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,77 @@ contexts:
pop: 1
- include: script
# anonymous functions
- match: (?=\([^()]*?\)\s*[=-]>)
push: function-parameter-list
- match: (?=\()
branch_point: anonymous
branch:
- anonymous-parameter-list
- group
# named functions
- match: |-
(?x)
\s*
( [a-zA-Z\$_@] [\w\$:.]* ) \s*
(?=[:=](?: \s*.\( $ | (?: \s*\(.*\) )? \s* [=-]> ) )
scope: meta.function.identifier.coffee
captures:
1: entity.name.function.coffee
push: function-parameter-list
- match: (?=(?:(?!and=|or=)|@){{identifier}}\s*[:=][^>])
branch_point: function
branch:
- function-name
- immediately-pop
- match: '[=-]>'
scope: keyword.declaration.function.coffee

function-parameter-list:
anonymous-parameter-list:
- match: \(
scope: punctuation.section.parameters.begin.coffee
set:
- anonymous-body
- function-parameter-list-body
- include: comments
- include: else-pop

anonymous-body:
- meta_content_scope: meta.function.coffee
- 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

function-name:
- meta_include_prototype: false
- meta_scope: meta.function.identifier.coffee
- match: (@?){{identifier}}
scope: entity.name.function.coffee
captures:
1: punctuation.definition.variable.coffee
set:
- function-body
- function-parameter-list
- function-assignment
- match: (?=\S)
fail: function

function-assignment:
- meta_include_prototype: false
- match: '[:=](?!>)'
scope: keyword.operator.assignment.coffee
pop: 1
- match: (?=\S)
fail: function

function-parameter-list:
- match: \(
scope: punctuation.section.parameters.begin.coffee
set: function-parameter-list-body
- match: (?=\S)
set: function-body
- include: comments
- include: else-pop

function-parameter-list-body:
- clear_scopes: 1
- meta_scope: meta.function.parameters.coffee
- match: \)
scope: punctuation.section.parameters.end.coffee
set: function-body
pop: 1
- match: '[:=]'
scope: keyword.operator.assignment.coffee
push: parameter-value
Expand All @@ -165,7 +206,8 @@ contexts:
- match: '[=-]>'
scope: meta.function.coffee keyword.declaration.function.coffee
pop: 1
- include: else-pop
- match: (?=\S)
fail: function

###[ FUNCTION CALLS ]#########################################################

Expand Down Expand Up @@ -775,7 +817,7 @@ variables:
# in embed...escape statements.
no_escape_behind: (?<![^\\]\\)(?<![\\]{3})

identifier: '[a-zA-Z\$_]\w*'
identifier: '[[:alpha:]_$]\w*'

component_names: '[A-Z][[:alnum:]_.-]*'
tag_names: '[[:alpha:]][[:alnum:]_.-]*'
Expand Down
73 changes: 40 additions & 33 deletions tests/syntax_test_scope.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,59 +78,29 @@ class App.Router extends Snakeskin.Router
# ^ keyword.operator.assignment.coffee
# ^^ keyword.declaration.function.coffee

namespace.name: ->
# ^^^^^^^^^^^^^^^^^^ - meta.function meta.function
# ^^^^^^^^^^^^^^ meta.function.identifier.coffee entity.name.function.coffee
# ^^^^ meta.function.coffee
# ^ keyword.operator.assignment.coffee
# ^^ keyword.declaration.function.coffee

name = =>
# ^^^^^^^^^ - meta.function meta.function
# ^^^^ meta.function.identifier.coffee entity.name.function.coffee
# ^ meta.function.identifier.coffee - entity
# ^ meta.function.coffee - entity
# ^^^^ meta.function.coffee
# ^ keyword.operator.assignment.coffee
# ^^ keyword.declaration.function.coffee

namespace.name = =>
# ^^^^^^^^^^^^^^^^^^^ - meta.function meta.function
# ^^^^^^^^^^^^^^ 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 meta.function
# ^^^^ meta.function.identifier.coffee entity.name.function.coffee
# ^^^^ meta.function.coffee
# ^ keyword.operator.assignment.coffee
# ^^ keyword.declaration.function.coffee

namespace.name: =>
# ^^^^^^^^^^^^^^^^^^ - meta.function meta.function
# ^^^^^^^^^^^^^^ meta.function.identifier.coffee entity.name.function.coffee
# ^^^^ meta.function.coffee
# ^ keyword.operator.assignment.coffee
# ^^ keyword.declaration.function.coffee

name = =>
# ^^^^^^^^^ - meta.function meta.function
# ^^^^ meta.function.identifier.coffee entity.name.function.coffee
# ^ meta.function.identifier.coffee - entity
# ^ meta.function.coffee - entity
# ^^^^ meta.function.coffee
# ^ keyword.operator.assignment.coffee
# ^^ keyword.declaration.function.coffee

namespace.name = =>
# ^^^^^^^^^^^^^^^^^^^ - meta.function meta.function
# ^^^^^^^^^^^^^^ 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 meta.function
# ^^^^ meta.function.identifier.coffee entity.name.function.coffee
Expand Down Expand Up @@ -164,6 +134,30 @@ class App.Router extends Snakeskin.Router
# ^ punctuation.section.parameters.end.coffee
# ^^ keyword.declaration.function.coffee

name:
# ^^^^ meta.function.identifier.coffee entity.name.function.coffee
# ^ meta.function.coffee keyword.operator.assignment.coffee
(foo, bar = undefined,
#^^^ meta.function.coffee
# ^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.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
baz="buuz", ...) ->
# ^^^^^^^^^^^^^^^^^^ meta.function.parameters.coffee
# ^^^ meta.function.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
Expand Down Expand Up @@ -203,13 +197,26 @@ class App.Router extends Snakeskin.Router
# ^^ keyword.declaration.function.coffee

(foo) ->
# ^^^^^ meta.function.parameters.coffee
# ^^^^^ meta.function.parameters.coffee - meta.function meta.function
# ^^^ meta.function.coffee
# ^ punctuation.section.parameters.begin.coffee
# ^^^ variable.parameter.coffee
# ^ punctuation.section.parameters.end.coffee
# ^^ keyword.declaration.function.coffee

(foo,
bar="baz") ->
# ^^^^^^^^^^^^ meta.function.parameters.coffee - meta.function meta.function
# ^^^ meta.function.coffee - meta.function meta.function
# ^^^ variable.parameter.coffee
# ^ keyword.operator.assignment.coffee
# ^^^^^ meta.string.coffee string.quoted.double.coffee
# ^ punctuation.section.parameters.end.coffee
# ^^ keyword.declaration.function.coffee

->
# ^^ keyword.declaration.function.coffee

###[ KEYWORDS ]################################################################

if .if _if $if
Expand Down

0 comments on commit 59f5968

Please sign in to comment.