Skip to content

Commit

Permalink
Properly scope parameters inside of anonymous functions
Browse files Browse the repository at this point in the history
  • Loading branch information
faultyserver committed Feb 6, 2018
1 parent c6bc591 commit 069898e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
28 changes: 16 additions & 12 deletions myst.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,7 @@ contexts:
1: keyword.control.function.myst
2: entity.name.function.public.myst
4: punctuation.definition.parameters.begin.myst
push:
- include: parameter
- meta_scope: meta.function.body.myst
- match: ;
pop: true
- match: $
pop: true
- match: ','
scope: punctuation.separator.parameter.myst
- match: \)$
scope: punctuation.definition.parameters.end.myst
pop: true
push: function_parameters
- match: \bfn\b
scope: keyword.control.anonymous.myst
push: anonymous_function
Expand Down Expand Up @@ -159,6 +148,19 @@ contexts:
pop: true
- include: parameter

function_parameters:
- include: parameter
- meta_scope: meta.function.body.myst
- match: ;
pop: true
- match: $
pop: true
- match: ','
scope: punctuation.separator.parameter.myst
- match: \)$
scope: punctuation.definition.parameters.end.myst
pop: true

comments:
- match: \#.*
scope: comment.line.number-sign
Expand Down Expand Up @@ -243,4 +245,6 @@ contexts:
- match: -\>
# TODO: This needs a better scope name
scope: keyword.operator.assignment.stab.myst
- match: '\('
push: function_parameters
- include: main
14 changes: 14 additions & 0 deletions sample.mt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ deftype Person

def foo()
days100per100 = 100

func = fn
->(a, *rest, [1, 2, 3] =: _ignored, &block) do
a + b
raise "no"
rescue str : String
0
rescue
nil
end

->(_other) { nil }
end

raise "woops\nit broke"
rescue msg : String
while msg.size <= 10_000_000
Expand Down

0 comments on commit 069898e

Please sign in to comment.