Skip to content

Commit

Permalink
[JavaScript] Refactor how statements and expressions are included, fi…
Browse files Browse the repository at this point in the history
…xing some edge bugs
  • Loading branch information
wbond committed Feb 23, 2016
1 parent ac44283 commit c6cd372
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions JavaScript/JavaScript.sublime-syntax
Expand Up @@ -14,10 +14,6 @@ variables:

contexts:
main:
- match: '\}'
scope: meta.brace.curly.js
- match: '\)'
scope: meta.brace.round.js
- include: comments-top-level
- include: keywords-top-level
- include: statements
Expand Down Expand Up @@ -127,12 +123,8 @@ contexts:
1: punctuation.definition.comment.js

statements:
# case/default allows popping out of statement context back to the switch
# context. } allows popping out of block contexts.
- match: '(?=(\bcase\b|\bdefault\b|\}))'
pop: true
- include: conditional
- include: expression
- include: expressions

conditional:
- match: \bswitch\b
Expand All @@ -150,30 +142,36 @@ contexts:
- match: '(?=\})'
pop: true
- match: ':'
push: statements
push:
- match: '(?=(\bcase\b|\bdefault\b|\}))'
pop: true
- include: statements
- match: \b(case|default)\b
scope: keyword.control.switch.js
- include: expression
- include: expressions

- match: \bdo\b
scope: keyword.control.loop.js
push:
- meta_scope: meta.do-while.js
- include: comments
- match: '\}'
scope: meta.block.js meta.brace.curly.js
- match: '\{'
scope: meta.brace.curly.js
push:
- meta_scope: meta.block.js
- match: '\}'
scope: meta.brace.curly.js
pop: true
- include: statements
- match: \bwhile\b
scope: keyword.control.loop.js
- match: '\('
scope: meta.brace.round.js
push:
- meta_scope: meta.group.braces.round.js
- include: expression
- match: '(?=\))'
pop: true
- include: expressions
- match: '\)'
scope: meta.group.braces.round.js meta.brace.round.js
pop: true
Expand Down Expand Up @@ -228,7 +226,7 @@ contexts:
- match: '\)'
scope: meta.brace.round.js
pop: true
- include: expression
- include: expressions
- include: block-scope

block-scope:
Expand All @@ -240,14 +238,13 @@ contexts:
scope: meta.brace.curly.js
push:
- meta_scope: meta.block.js
- match: '(?=\})'
pop: true
- include: statements
- match: '(?=\S)'
pop: true

expression:
# This allows popping out of expression paren contexts
- match: '(?=\))'
pop: true
expressions:
- include: comments
- include: literal-string
- include: literal-string-template
Expand Down Expand Up @@ -354,7 +351,7 @@ contexts:
- match: '\}'
scope: punctuation.definition.template-expression.end.js
pop: true
- include: expression
- include: expressions
- include: string-content

string-content:
Expand Down Expand Up @@ -402,7 +399,7 @@ contexts:
- match: '\)'
scope: meta.brace.round.js
set: constructor-params
- include: expression
- include: expressions
- match: '(?=\S)'
pop: true

Expand Down Expand Up @@ -622,7 +619,7 @@ contexts:
- meta_content_scope: meta.block.js
- match: \n
pop: true
- include: expression
- include: expressions
- match: '\b(async)\b\s*'
scope: meta.function.declaration.js
captures:
Expand All @@ -638,7 +635,10 @@ contexts:
pop: true
- match: '\{'
scope: meta.brace.curly.js
push: statements
push:
- match: '(?=\})'
pop: true
- include: statements

function-declaration-parameters:
- match: \(
Expand All @@ -660,7 +660,7 @@ contexts:
- meta_scope: meta.parameter.optional.js
- match: "(?=[,)])"
pop: true
- include: expression
- include: expressions
- include: comments

label:
Expand Down Expand Up @@ -753,7 +753,7 @@ contexts:
push:
- match: '(?=\}|,)'
pop: true
- include: expression
- include: expressions
- include: method-declaration
- include: comments

Expand Down Expand Up @@ -800,7 +800,7 @@ contexts:
- match: \)
scope: meta.brace.round.js
pop: true
- include: expression
- include: expressions
- match: \)
scope: invalid.illegal.stray.brace.round.js

Expand All @@ -812,7 +812,7 @@ contexts:
- match: '\]'
scope: meta.brace.square.js
pop: true
- include: expression
- include: expressions

literal-number:
- match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)'
Expand Down Expand Up @@ -909,7 +909,7 @@ contexts:
push:
- match: '(?=\))'
pop: true
- include: expression
- include: expressions

literal-variable:
- include: well-known-identifiers
Expand Down

0 comments on commit c6cd372

Please sign in to comment.