From 8b71483aac06ea98d9be4776d66445714b1852ec Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sat, 27 May 2017 20:04:00 -0400 Subject: [PATCH 01/46] Moved comments to prototype. Added missing tests for comments and for a bug that was fixed. --- JavaScript/JavaScript.sublime-syntax | 37 ++++++++++--------------- JavaScript/syntax_test_js.js | 40 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index a731104453..a817eff278 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -21,6 +21,9 @@ contexts: - include: keywords-top-level - include: statements + prototype: + - include: comments + keywords-top-level: - match: \bimport\b scope: meta.import.js keyword.control.import-export.js @@ -40,7 +43,6 @@ contexts: import-extended: - meta_content_scope: meta.import.js - include: import-escape - - include: comments - match: '\{' scope: meta.block.js punctuation.section.block.js set: import-brace @@ -66,7 +68,6 @@ contexts: import-extended-continue: - meta_scope: meta.import.js - include: import-escape - - include: comments - match: ',' scope: punctuation.separator.comma.js set: import-extended @@ -76,7 +77,6 @@ contexts: import-brace: - meta_content_scope: meta.import.js meta.block.js - include: import-escape - - include: comments - match: '\}' scope: punctuation.section.block.js set: import-extended-as @@ -102,7 +102,6 @@ contexts: import-brace-continue: - meta_scope: meta.import.js meta.block.js - include: import-escape - - include: comments - match: '(?=\})' set: import-brace - match: ',' @@ -113,7 +112,6 @@ contexts: import-final: - meta_scope: meta.import.js - - include: comments - match: '\bfrom\b' scope: keyword.control.import-export.js - include: literal-string @@ -135,7 +133,6 @@ contexts: pop: true - include: expressions - include: export-escape - - include: comments - match: '\bdefault\b' scope: keyword.control.import-export.js set: @@ -165,7 +162,6 @@ contexts: export-extended-continue: - meta_scope: meta.export.js - include: export-escape - - include: comments - match: ',' scope: punctuation.separator.comma.js set: export-extended @@ -175,7 +171,6 @@ contexts: export-brace: - meta_content_scope: meta.export.js meta.block.js - include: export-escape - - include: comments - match: '\}' scope: punctuation.section.block.js set: export-extended-as @@ -205,7 +200,6 @@ contexts: export-brace-continue: - meta_scope: meta.export.js meta.block.js - include: export-escape - - include: comments - match: '(?=\})' set: export-brace - match: ',' @@ -216,7 +210,6 @@ contexts: export-final: - meta_scope: meta.export.js - - include: comments - match: '\bfrom\b' scope: keyword.control.import-export.js - include: literal-string @@ -270,7 +263,6 @@ contexts: scope: keyword.control.loop.js push: - meta_scope: meta.do-while.js - - include: comments - match: '\{' scope: punctuation.section.block.js push: @@ -352,7 +344,6 @@ contexts: - include: block-scope block-scope: - - include: comments - match: '\}' scope: meta.block.js punctuation.section.block.js pop: true @@ -367,7 +358,6 @@ contexts: pop: true expressions: - - include: comments - include: regexp-complete - include: literal-string - include: literal-string-template @@ -424,6 +414,7 @@ contexts: - match: /\*\*(?!/) scope: punctuation.definition.comment.js push: + - meta_include_prototype: false - meta_scope: comment.block.documentation.js - match: \*/ scope: punctuation.definition.comment.js @@ -431,6 +422,7 @@ contexts: - match: /\* scope: punctuation.definition.comment.js push: + - meta_include_prototype: false - meta_scope: comment.block.js - match: \*/ scope: punctuation.definition.comment.js @@ -438,6 +430,7 @@ contexts: - match: // scope: punctuation.definition.comment.js push: + - meta_include_prototype: false - meta_scope: comment.line.double-slash.js - match: \n pop: true @@ -446,6 +439,7 @@ contexts: - match: "'" scope: punctuation.definition.string.begin.js push: + - meta_include_prototype: false - meta_scope: string.quoted.single.js - match: (')|(\n) captures: @@ -457,6 +451,7 @@ contexts: captures: 0: punctuation.definition.string.begin.js push: + - meta_include_prototype: false - meta_scope: string.quoted.double.js - match: (")|(\n) captures: @@ -471,6 +466,7 @@ contexts: 1: variable.function.tagged-template.js 2: punctuation.definition.string.template.begin.js push: + - meta_include_prototype: false - meta_scope: string.template.js - match: "`" scope: punctuation.definition.string.template.end.js @@ -500,6 +496,7 @@ contexts: push: regexp regexp: + - meta_include_prototype: false - meta_scope: string.regexp.js - match: "(/)([gimyu]*)" captures: @@ -677,11 +674,9 @@ contexts: pop: true - match: '{{identifier}}' scope: entity.name.class.js - - include: comments class-body: - meta_scope: meta.class.js meta.block.js - - include: comments - match: '\}' scope: punctuation.section.block.js pop: true @@ -856,7 +851,6 @@ contexts: push: arrow-function-declaration function-declaration: - - include: comments - match: '\b(async)\b\s*' scope: meta.function.declaration.js captures: @@ -898,7 +892,6 @@ contexts: arrow-function-declaration-continuation: - meta_content_scope: meta.function.declaration.js - - include: comments - match: '(?=\{)' set: function-block - match: '(?=\S)' @@ -982,7 +975,6 @@ contexts: - match: "(?=[,)])" pop: true - include: expressions - - include: comments label: - match: '^\s*((?!default){{identifier}})\s*(:)' @@ -998,7 +990,6 @@ contexts: - match: '\}' scope: punctuation.section.block.js set: after-identifier - - include: comments - match: \[ scope: punctuation.section.brackets.js push: @@ -1036,6 +1027,7 @@ contexts: - match: "'" scope: punctuation.definition.string.begin.js push: + - meta_include_prototype: false - meta_scope: string.quoted.single.js - meta_content_scope: entity.name.function.js - match: (')|(\n) @@ -1047,6 +1039,7 @@ contexts: - match: '"' scope: punctuation.definition.string.begin.js push: + - meta_include_prototype: false - meta_scope: string.quoted.double.js - meta_content_scope: entity.name.function.js - match: (")|(\n) @@ -1091,7 +1084,6 @@ contexts: - match: "(?=\\}|,|('[^']*'|\"[^\"]*\"|{{identifier}})\\s*:)" pop: true - include: expressions - - include: comments method-declaration: - match: \b(get|set)\b(?!\s*\()\s* @@ -1122,7 +1114,6 @@ contexts: scope: punctuation.section.block.js pop: true - include: statements - - include: comments - match: '(?=\S)' pop: true - match: (?=('[^\\]*'|"[^\\]*")\s*\() @@ -1131,6 +1122,7 @@ contexts: - match: "'" scope: punctuation.definition.string.begin.js push: + - meta_include_prototype: false - meta_scope: string.quoted.single.js - meta_content_scope: entity.name.function.js - match: (')|(\n) @@ -1142,6 +1134,7 @@ contexts: - match: '"' scope: punctuation.definition.string.begin.js push: + - meta_include_prototype: false - meta_scope: string.quoted.double.js - meta_content_scope: entity.name.function.js - match: (")|(\n) @@ -1160,7 +1153,6 @@ contexts: scope: punctuation.section.block.js pop: true - include: statements - - include: comments - match: '(?=\S)' pop: true - match: '({{identifier}})\s*(?=\()' @@ -1177,7 +1169,6 @@ contexts: scope: punctuation.section.block.js pop: true - include: statements - - include: comments - match: '(?=\S)' pop: true diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index b908a1af59..2b4c526ded 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -167,6 +167,41 @@ x --> y; /*@if /*/ // ^^ punctuation.definition.comment.js +// /* +not_a_comment; +// <- -comment + +/* // */ +not_a_comment; +// <- -comment + +/* /* */ +not_a_comment; +// <- -comment + +'// /* not a comment'; +// ^^^^^^^^^^^^^^^^^^^ -comment + +"// /* not a comment"; +// ^^^^^^^^^^^^^^^^^^^ -comment + +`// /* not a comment`; +// ^^^^^^^^^^^^^^^^^^^ -comment + +({ + '// /* not a comment': x => x, +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment + + "// /* not a comment": x => x, +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment + + '// /* not a comment'() {}, +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} + + "// /* not a comment"() {}, +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} +}); + var str = '\':'; var str2 = NaN; // <- storage.type @@ -810,6 +845,11 @@ a = /\//u + 0; // ^ keyword.operator // ^ constant.numeric +1 /**/ / 2 / /**/ 3; +// ^ keyword.operator +// ^ constant.numeric +// ^ keyword.operator + var π = 3.141592653 // ^ variable.other.readwrite From 918a535f33573e84d97e4fcec8c641395aa8c579 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sat, 27 May 2017 21:15:53 -0400 Subject: [PATCH 02/46] Added another meta_include_prototype that I missed due to other bugs. --- JavaScript/JavaScript.sublime-syntax | 1 + 1 file changed, 1 insertion(+) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index a817eff278..d70791e764 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -505,6 +505,7 @@ contexts: set: after-identifier - match: '(?=.|\n)' push: + - meta_include_prototype: false - match: '(?=/)' pop: true - include: scope:source.regexp.js From 29d9336a1b7c35b29719d2b0db184a8d3010e6ae Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 28 May 2017 21:41:45 -0400 Subject: [PATCH 03/46] Expression scope is now pushed. --- JavaScript/JavaScript.sublime-syntax | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index d70791e764..d469955807 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -223,6 +223,9 @@ contexts: 1: punctuation.definition.comment.js statements: + - match: \; + scope: punctuation.terminator.statement.js + - include: conditional - match: '\{' scope: punctuation.section.block.js @@ -233,7 +236,13 @@ contexts: pop: true - include: statements - include: label - - include: expressions + # - include: expressions + + - match: (?=\S) + push: + - match: \n + pop: true + - include: expressions conditional: - match: \bswitch\b @@ -340,6 +349,10 @@ contexts: - match: '\)' scope: punctuation.section.group.js pop: true + + - match: ; + scope: punctuation.terminator.statement.js + - include: expressions - include: block-scope @@ -358,6 +371,12 @@ contexts: pop: true expressions: + - match: (?=;) + pop: true + + - match: (?=}) + pop: true + - include: regexp-complete - include: literal-string - include: literal-string-template @@ -688,6 +707,7 @@ contexts: captures: # these keywords are restricted productions and implicitly end at the end of the line, so we don't push the after-operator scope 1: keyword.control.trycatch.js 2: keyword.control.flow.js + pop: true - match: \bthrow\b scope: keyword.control.trycatch.js push: after-operator @@ -1431,7 +1451,7 @@ contexts: - match: '(?=.|\n)' pop: true - include: object-property - - match: \; - scope: punctuation.terminator.statement.js + # - match: \; + # scope: punctuation.terminator.statement.js - match: "," scope: punctuation.separator.comma.js From 0495ab1f170ad7e4b599869fdad16ef42f37c33a Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 28 May 2017 22:19:55 -0400 Subject: [PATCH 04/46] Moved statement keywords to statements context. --- JavaScript/JavaScript.sublime-syntax | 57 ++++++++++++++++------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index d469955807..87b0138ff6 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -126,7 +126,9 @@ contexts: export-extended: - meta_content_scope: meta.export.js - - match: '(?=\b(let|const|var)\b)' + + - match: \b(const|let|var)\b + scope: storage.type.js set: - meta_content_scope: meta.export.js - match: '(?=;|\n)' @@ -236,7 +238,25 @@ contexts: pop: true - include: statements - include: label - # - include: expressions + + - include: variable-declaration + + - match: \bthrow\b + scope: keyword.control.trycatch.js + push: restricted-production + + - match: \b(break|continue|goto)\b + scope: keyword.control.loop.js + + - match: \b(yield)\b(?:\s*(\*))? + captures: + 1: keyword.control.flow.js + 2: keyword.generator.asterisk.js + push: restricted-production + + - match: \b(await|return)\b + scope: keyword.control.flow.js + push: restricted-production - match: (?=\S) push: @@ -244,6 +264,16 @@ contexts: pop: true - include: expressions + variable-declaration: + - match: \b(const|let|var)\b + scope: storage.type.js + + restricted-production: + - match: \n + pop: true + - match: (?=\S) + set: expressions + conditional: - match: \bswitch\b scope: keyword.control.switch.js @@ -384,7 +414,6 @@ contexts: - include: unary-operators - include: binary-operators - include: class - - include: keywords - include: constants - include: literal-prototype - include: named-function @@ -702,28 +731,6 @@ contexts: pop: true - include: method-declaration - keywords: - - match: ^\s*\b(?:(throw)|(yield|return))\b\s*$ - captures: # these keywords are restricted productions and implicitly end at the end of the line, so we don't push the after-operator scope - 1: keyword.control.trycatch.js - 2: keyword.control.flow.js - pop: true - - match: \bthrow\b - scope: keyword.control.trycatch.js - push: after-operator - - match: \b(break|continue|goto)\b - scope: keyword.control.loop.js - - match: \b(yield)\b(?:\s*(\*))? - captures: - 1: keyword.control.flow.js - 2: keyword.generator.asterisk.js - push: after-operator - - match: \b(await|return)\b - scope: keyword.control.flow.js - push: after-operator - - match: \b(const|let|var)\b - scope: storage.type.js - constants: - match: \btrue\b scope: constant.language.boolean.true.js From 5ad77af61f526e1872192b51829be128b2f1b462 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 28 May 2017 22:43:35 -0400 Subject: [PATCH 05/46] Added class and function statements. Implemented semicolon insertion. --- JavaScript/JavaScript.sublime-syntax | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 87b0138ff6..af90a0437b 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -258,16 +258,31 @@ contexts: scope: keyword.control.flow.js push: restricted-production + - include: literal-prototype + - include: class + - include: named-function + - match: (?=\S) - push: - - match: \n - pop: true - - include: expressions + push: expression-statement variable-declaration: - match: \b(const|let|var)\b scope: storage.type.js + expression-statement: + - match: \n + set: + - match: >- + (?x) (?= + \+\+ | + \+= | + [-+*><&|^\[(] + ) + set: expression-statement + - match: (?=\S) + pop: true + - include: expressions + restricted-production: - match: \n pop: true @@ -415,7 +430,6 @@ contexts: - include: binary-operators - include: class - include: constants - - include: literal-prototype - include: named-function - include: anonymous-function - include: object-literal From 6d3cf3e9c32e7cfd0f9688e845a15582b348869d Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 01:23:31 -0400 Subject: [PATCH 06/46] Implemented the two-level expression scheme. All tests pass, somehow. --- JavaScript/JavaScript.sublime-syntax | 357 ++++++++++++++++----------- JavaScript/syntax_test_js.js | 12 +- 2 files changed, 225 insertions(+), 144 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index af90a0437b..442c03f8cf 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -114,7 +114,8 @@ contexts: - meta_scope: meta.import.js - match: '\bfrom\b' scope: keyword.control.import-export.js - - include: literal-string + - match: (?=['"]) + push: literal-string - match: '(?=\S)' pop: true @@ -127,20 +128,18 @@ contexts: export-extended: - meta_content_scope: meta.export.js - - match: \b(const|let|var)\b - scope: storage.type.js - set: - - meta_content_scope: meta.export.js - - match: '(?=;|\n)' - pop: true - - include: expressions + - include: variable-declaration - include: export-escape + - match: '\bdefault\b' scope: keyword.control.import-export.js - set: - - meta_content_scope: meta.export.js - - match: '(?=;|\n)' - pop: true + push: + - match: (?=class) + set: class + + - match: (?=function) + set: function-declaration + - include: expressions - match: '\{' scope: meta.block.js punctuation.section.block.js @@ -214,7 +213,8 @@ contexts: - meta_scope: meta.export.js - match: '\bfrom\b' scope: keyword.control.import-export.js - - include: literal-string + - match: (?=['"]) + push: literal-string - match: '(?=\S)' pop: true @@ -258,9 +258,7 @@ contexts: scope: keyword.control.flow.js push: restricted-production - - include: literal-prototype - - include: class - - include: named-function + - include: function-or-class-declaration - match: (?=\S) push: expression-statement @@ -268,20 +266,34 @@ contexts: variable-declaration: - match: \b(const|let|var)\b scope: storage.type.js + push: expression-statement + + function-or-class-declaration: + - match: (?=class) + push: class + + - match: (?=function) + push: named-function expression-statement: + - match: (?=\S) + set: [ expression-statement-end, expression-begin ] + + expression-statement-end: - match: \n - set: - - match: >- - (?x) (?= - \+\+ | - \+= | - [-+*><&|^\[(] - ) - set: expression-statement - - match: (?=\S) - pop: true - - include: expressions + set: expression-statement-line-continuation + - include: expression-end + + expression-statement-line-continuation: + - match: >- + (?x) (?= + \+\+ | + \+= | + [-+*/><&|^\[(] + ) + set: expression-statement-end + - match: (?=\S) + pop: true restricted-production: - match: \n @@ -294,7 +306,8 @@ contexts: scope: keyword.control.switch.js push: - meta_scope: meta.switch.js - - include: round-brackets + - match: (?=\() + push: round-brackets - match: '\}' scope: meta.block.js punctuation.section.block.js pop: true @@ -311,7 +324,7 @@ contexts: - include: statements - match: \b(case|default)\b scope: keyword.control.switch.js - - include: expressions + - include: statements - match: \bdo\b scope: keyword.control.loop.js @@ -333,7 +346,8 @@ contexts: - meta_scope: meta.group.js - match: '(?=\))' pop: true - - include: expressions + - match: (?=\S) + push: expressions - match: '\)' scope: meta.group.js punctuation.section.group.js pop: true @@ -398,7 +412,8 @@ contexts: - match: ; scope: punctuation.terminator.statement.js - - include: expressions + - match: (?=\S) + push: expressions - include: block-scope block-scope: @@ -415,62 +430,72 @@ contexts: - match: '(?=\S)' pop: true + expression-break: + - match: (?=[;})\]]) + pop: true + expressions: - - match: (?=;) + - match: (?=\S) + set: [ expression-end, expression-begin ] + + expression-no-comma: + - match: (?=\S) + set: [ expression-end-no-comma, expression-begin ] + + expression-end: + - include: expression-break + + - include: postfix-operators + - include: binary-operators + + - include: bracketed-property-access + - include: function-call + + - include: literal-punctuation + - include: fallthrough + + - match: (?=\S) pop: true - - match: (?=}) + expression-end-no-comma: + - match: (?=,) pop: true + - include: expression-end + + expression-begin: + - match: \) + scope: invalid.illegal.stray-bracket-end + pop: true + + - include: expression-break + + - include: literal-prototype - include: regexp-complete - include: literal-string - include: literal-string-template - include: constructor - - include: unary-operators - - include: binary-operators + - include: prefix-operators + - include: class - include: constants - include: named-function - include: anonymous-function - include: object-literal + - include: brackets + - include: literal-number - include: literal-call - include: literal-variable - - include: literal-punctuation - - include: fallthrough + + - match: (?=\S) + pop: true fallthrough: # If an arrow function has the ( and ) on different lines, we won't have matched - match: => - scope: storage.type.function.arrow.js - - after-operator: - # Prevent matching "{" as a block, but instead always treat as an object - # literal. This is needed since in the "statements" context, a "{" starts - # an anonymous block, not an object literal. - - match: '(?=\{)' - push: - - include: object-literal - - match: '(?=.|\n)' - pop: true - # When following an operator, a single / is the beginning of a regexp, - # not a division operator - - match: '/(?=[^/*])' - scope: punctuation.definition.string.begin.js - push: regexp - - include: constants - - match: '(?=[\S])' - pop: true - - after-identifier: - # When following an identifier or closing )/], a single / is a division - # operator, not the beginning of a regexp - - match: '/(?=[^/*])' - scope: keyword.operator.arithmetic.js - set: after-operator - - match: '(?=[\S\n])' - pop: true + scope: storage.type.function.arrow.js FALLTHROUGH comments: - match: /\*\*(?!/) @@ -500,26 +525,26 @@ contexts: literal-string: - match: "'" scope: punctuation.definition.string.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.single.js - match: (')|(\n) captures: 1: punctuation.definition.string.end.js 2: invalid.illegal.newline.js - set: after-identifier + pop: true - include: string-content - match: '"' captures: 0: punctuation.definition.string.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.js - match: (")|(\n) captures: 1: punctuation.definition.string.end.js 2: invalid.illegal.newline.js - set: after-identifier + pop: true - include: string-content literal-string-template: @@ -527,12 +552,12 @@ contexts: captures: 1: variable.function.tagged-template.js 2: punctuation.definition.string.template.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.template.js - match: "`" scope: punctuation.definition.string.template.end.js - set: after-identifier + pop: true - match: '\$\{' captures: 0: punctuation.definition.template-expression.begin.js @@ -543,7 +568,8 @@ contexts: - match: '\}' scope: punctuation.definition.template-expression.end.js pop: true - - include: expressions + - match: (?=\S) + push: expressions - include: string-content string-content: @@ -553,9 +579,9 @@ contexts: scope: constant.character.escape.js regexp-complete: - - match: '/(?=(?:[^/\\\[]|\\.|\[([^\]\\]|\\.)+\])+/(?![/*])[gimyu]*(?!\s*[a-zA-Z0-9_$]))' + - match: '/' scope: punctuation.definition.string.begin.js - push: regexp + set: regexp regexp: - meta_include_prototype: false @@ -564,7 +590,7 @@ contexts: captures: 1: punctuation.definition.string.end.js 2: keyword.other.js - set: after-identifier + pop: true - match: '(?=.|\n)' push: - meta_include_prototype: false @@ -577,7 +603,7 @@ contexts: scope: meta.instance.constructor.js captures: 1: keyword.operator.word.new.js - push: constructor-name + set: constructor-name constructor-name: - match: '(?=function\b)' @@ -612,7 +638,7 @@ contexts: scope: variable.type.js - match: '\.' scope: punctuation.accessor.js - - include: square-brackets + - include: bracketed-property-access - match: '(?=\()' set: constructor-params - match: '(?=\S|$)' @@ -624,7 +650,8 @@ contexts: - match: '\)' scope: punctuation.section.group.js set: constructor-params - - include: expressions + - match: (?=\S) + push: expressions - match: '(?=\S)' pop: true @@ -637,7 +664,7 @@ contexts: - match: '(?=\S)' pop: true - unary-operators: + prefix-operators: - match: '~' scope: keyword.operator.bitwise.js - match: '!(?!=)' @@ -648,21 +675,27 @@ contexts: scope: keyword.operator.arithmetic.js - match: \.\.\. scope: keyword.operator.spread.js + - match: \+|\- + scope: keyword.operator.arithmetic.js - binary-operators: - match: \bnew\b scope: keyword.operator.word.new.js - - match: \b(delete|instanceof)\b + - match: \bdelete|typeof|void\b scope: keyword.operator.js - - match: \b(in|of|typeof|void)\b + + binary-operators: + - match: \binstanceof\b + scope: keyword.operator.js + push: expression-begin + - match: \b(in|of)\b scope: keyword.operator.js - push: after-operator + push: expression-begin - match: '&&|\|\|' scope: keyword.operator.logical.js - push: after-operator + push: expression-begin - match: '=(?![=>])' scope: keyword.operator.assignment.js - push: after-operator + push: expression-begin - match: |- (?x) %= | # assignment right-to-left both @@ -677,7 +710,7 @@ contexts: >>= | # assignment right-to-left both >>>= # assignment right-to-left both scope: keyword.operator.assignment.augmented.js - push: after-operator + push: expression-begin - match: |- (?x) << | # bitwise-shift left-to-right both @@ -687,7 +720,7 @@ contexts: \^ | # bitwise-xor left-to-right both \| # bitwise-or left-to-right both scope: keyword.operator.bitwise.js - push: after-operator + push: expression-begin - match: |- (?x) <= | # relational left-to-right both @@ -695,7 +728,7 @@ contexts: < | # relational left-to-right both > # relational left-to-right both scope: keyword.operator.relational.js - push: after-operator + push: expression-begin - match: |- (?x) === | # equality left-to-right both @@ -703,7 +736,7 @@ contexts: == | # equality left-to-right both != # equality left-to-right both scope: keyword.operator.comparison.js - push: after-operator + push: expression-begin - match: |- (?x) / | # division left-to-right both @@ -712,15 +745,20 @@ contexts: \+ | # addition left-to-right both - # subtraction left-to-right both scope: keyword.operator.arithmetic.js - push: after-operator + push: expression-begin - match: '\?|:' scope: keyword.operator.ternary.js - push: after-operator + push: expression-begin + + postfix-operators: + - match: '--' + scope: keyword.operator.arithmetic.js + - match: '\+\+' class: - match: \bclass\b scope: storage.type.class.js - push: + set: - meta_scope: meta.class.js - match: '\{' scope: punctuation.section.block.js @@ -748,19 +786,19 @@ contexts: constants: - match: \btrue\b scope: constant.language.boolean.true.js - push: after-identifier + pop: true - match: \bfalse\b scope: constant.language.boolean.false.js - push: after-identifier + pop: true - match: \bnull\b scope: constant.language.null.js - push: after-identifier + pop: true - match: \bundefined\b scope: constant.language.undefined.js - push: after-identifier + pop: true - match: \bNaN\b scope: constant.language.nan.js - push: after-identifier + pop: true literal-prototype: - match: '({{identifier}})\s*(\.)\s*(prototype)(?=\s*=\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' @@ -769,7 +807,7 @@ contexts: 1: support.class.js 2: punctuation.accessor.js 3: support.constant.prototype.js - push: + set: - meta_scope: meta.function.declaration.js - match: '\s*(=)\s*' captures: @@ -786,7 +824,7 @@ contexts: 2: punctuation.accessor.js 3: support.constant.prototype.js 4: punctuation.accessor.js - push: + set: - meta_scope: meta.function.declaration.js - match: '(?={{func_lookahead}})' set: function-declaration @@ -799,10 +837,11 @@ contexts: 1: support.class.js 2: punctuation.accessor.js 3: support.constant.prototype.js + pop: true named-function: - match: '(?=(({{identifier}})\s*(\.)\s*)+({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' - push: + set: - meta_scope: meta.function.declaration.js - match: '(?={{func_lookahead}})' set: function-declaration @@ -810,7 +849,7 @@ contexts: set: arrow-function-declaration - include: function-declaration-identifiers - match: '(?=({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' - push: + set: - meta_scope: meta.function.declaration.js - match: '(?={{func_lookahead}})' set: function-declaration @@ -818,15 +857,15 @@ contexts: set: arrow-function-declaration - include: function-declaration-single-identifier - match: '(?={{func_lookahead}}(\s*\*)?\s+{{identifier}})' - push: function-declaration + set: function-declaration anonymous-function: - match: '(?={{func_lookahead}})' - push: + set: - meta_content_scope: meta.function.anonymous.js - include: function-declaration - match: '(?={{arrow_func_lookahead}})' - push: + set: - meta_content_scope: meta.function.anonymous.js - include: arrow-function-declaration @@ -955,7 +994,8 @@ contexts: - meta_scope: comment.line.double-slash.js - match: \n set: arrow-function-concise-continuation - - include: expressions + - match: (?=\S) + push: expression-no-comma arrow-function-concise-continuation: # Allow newlines in a concise body if the next line is a continuation @@ -1003,7 +1043,8 @@ contexts: - meta_scope: meta.parameter.optional.js - match: "(?=[,)}])" pop: true - - include: expressions + - match: (?=\S) + push: expression-no-comma - match: \.\.\. scope: keyword.operator.spread.js - match: '{{identifier}}' @@ -1016,7 +1057,8 @@ contexts: - meta_scope: meta.parameter.optional.js - match: "(?=[,)])" pop: true - - include: expressions + - match: (?=\S) + push: expression-no-comma label: - match: '^\s*((?!default){{identifier}})\s*(:)' @@ -1027,18 +1069,21 @@ contexts: object-literal: - match: '\{' scope: punctuation.section.block.js - push: + set: - meta_scope: meta.object-literal.js - match: '\}' scope: punctuation.section.block.js - set: after-identifier + pop: true + - match: ',' + scope: punctuation.separator.comma.js - match: \[ scope: punctuation.section.brackets.js push: - match: \] scope: punctuation.section.brackets.js pop: true - - include: expressions + - match: (?=\S) + push: expressions - match: '({{identifier}})\s*(\})' captures: 1: variable.other.readwrite.js @@ -1058,9 +1103,11 @@ contexts: 2: punctuation.dollar.js 3: punctuation.separator.key-value.js push: + - meta_scope: TEST - match: ':' scope: meta.function.declaration.js punctuation.separator.key-value.js - - include: either-function-declaration + set: expression-no-comma + # set: either-function-declaration - match: '(?=\S)' pop: true - match: "(?=('.*'|\".*\"|{{identifier}})\\s*:({{func_lookahead}}|{{arrow_func_lookahead}}))" @@ -1116,16 +1163,16 @@ contexts: scope: meta.object-literal.key.js - match: (?=[-+]?(?:\.[0-9]|0[bxo]|\d)) push: - - meta_content_scope: meta.object-literal.key.js + - meta_scope: meta.object-literal.key.js - include: literal-number - - match: '' - pop: true + # - match: '' + # pop: true - match: ':' scope: punctuation.separator.key-value.js push: - match: "(?=\\}|,|('[^']*'|\"[^\"]*\"|{{identifier}})\\s*:)" pop: true - - include: expressions + - include: expression-no-comma method-declaration: - match: \b(get|set)\b(?!\s*\()\s* @@ -1221,30 +1268,57 @@ contexts: round-brackets: - match: \( scope: punctuation.section.group.js - push: + set: - meta_scope: meta.group.js - match: \) scope: punctuation.section.group.js - set: after-identifier - - include: expressions + pop: true + - match: (?=\S) + push: expressions - match: \) scope: invalid.illegal.stray-bracket-end.js + pop: true + + function-call: + - match: \( + scope: punctuation.section.group.js + push: + - meta_scope: meta.group.js + - match: \) + scope: punctuation.section.group.js + pop: true + - match: (?=\S) + push: expressions square-brackets: + - match: '\[' + scope: punctuation.section.brackets.js + set: + - meta_scope: meta.brackets.js + - match: '\]' + scope: punctuation.section.brackets.js + pop: true + - match: (?=\S) + push: expressions + + bracketed-property-access: - match: '\[' scope: punctuation.section.brackets.js push: - meta_scope: meta.brackets.js - match: '\]' scope: punctuation.section.brackets.js - set: after-identifier - - include: expressions + pop: true + - match: (?=\S) + push: expressions literal-number: - match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)' scope: invalid.illegal.numeric.hex.js + pop: true - match: '(?:\B[-+]|\b)0[0-9]+\.(\B|\b[0-9]+)' scope: invalid.illegal.numeric.octal.js + pop: true - match: |- (?xi) (?:\B[-+])? @@ -1258,29 +1332,29 @@ contexts: )(e[-+]?[0-9]+)? # e.g. e+123, E-123 ) scope: constant.numeric.js - push: after-identifier + pop: true - match: '(?:\B[-+]|\b)(Infinity)\b' scope: constant.language.infinity.js - push: after-identifier + pop: true literal-call: - match: (\$)(?=\s*\() scope: variable.function.js variable.other.dollar.only.js punctuation.dollar.js - push: + set: - meta_scope: meta.function-call.js - include: function-call-params - match: \b(clearTimeout|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|escape|eval|isFinite|isNaN|parseFloat|parseInt|setTimeout|super|unescape)\b(?=\() scope: support.function.js - push: + set: - meta_scope: meta.function-call.js - include: function-call-params - match: '({{identifier}})(?=\s*\()' scope: variable.function.js - push: + set: - meta_scope: meta.function-call.js - include: function-call-params - match: '(?={{identifier}}\s*\.\s*{{identifier}}\s*\()' - push: + set: - match: \b(console)(?:(\.)(warn|info|log|error|time|timeEnd|assert|count|dir|group|groupCollapsed|groupEnd|profile|profileEnd|table|trace|timeStamp))?\b captures: 1: support.type.object.console.js @@ -1321,44 +1395,45 @@ contexts: method-call: - match: \b(shift|sort|splice|unshift|pop|push|reverse|copyWithin|fill)\b(?=\() scope: support.function.mutator.js - push: + set: - meta_scope: meta.function-call.method.js - include: function-call-params - match: \b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\b(?=\() scope: support.function.dom.js - push: + set: - meta_scope: meta.function-call.method.js - include: function-call-params - match: '({{identifier}})\s*(?=\()' scope: variable.function.js - push: + set: - meta_scope: meta.function-call.method.js - include: function-call-params function-call-params: - match: '\)' scope: meta.group.js punctuation.section.group.js - set: after-identifier + pop: true - match: '\(' scope: punctuation.section.group.js push: - meta_scope: meta.group.js - match: '(?=\))' - set: after-identifier + pop: true # Consume comma plus any whitespace to prevent whitespace from # getting meta scopes when they don't really apply - match: '(,)\s+' captures: 1: punctuation.separator.comma.js - - include: expressions + - match: (?=\S) + push: expression-no-comma literal-variable: - match: '(?={{identifier}})' - push: + set: # Once we've consumed an identifier, switch to the special context that # property handles ambiguous tokens including "/" - match: '(?!{{identifier}})' - set: after-identifier + pop: true - include: well-known-identifiers - include: language-identifiers - include: dollar-identifiers @@ -1432,22 +1507,29 @@ contexts: object-property: - match: \b__proto__\b scope: variable.language.proto.js + pop: true - match: \bconstructor\b scope: variable.language.constructor.js + pop: true - match: \bprototype\b scope: variable.language.prototype.js + pop: true - match: '{{dollar_only_identifier}}' scope: meta.property.object.dollar.only.js punctuation.dollar.js + pop: true - match: '{{dollar_identifier}}' scope: meta.property.object.dollar.js captures: 1: punctuation.dollar.js + pop: true - match: '{{identifier}}' scope: meta.property.object.js + pop: true - match: \b(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\b scope: support.constant.dom.js + pop: true - match: '(?=.|\n)' - set: after-identifier + pop: true literal-punctuation: - match: \. @@ -1472,7 +1554,6 @@ contexts: - match: '(?=.|\n)' pop: true - include: object-property - # - match: \; - # scope: punctuation.terminator.statement.js - - match: "," + - match: ',' scope: punctuation.separator.comma.js + push: expression-begin diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index 2b4c526ded..c9fbf07174 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -251,7 +251,7 @@ var obj = { // ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // <- meta.object-literal.key.dollar entity.name.function punctuation.dollar // <- meta.object-literal.key.dollar entity.name.function - punctuation.dollar - } + }, [true==false ? 'one' : 'two']: false, // ^ punctuation.section.brackets @@ -585,7 +585,7 @@ class Foo extends React.Component { //^^^ meta.function.anonymous meta.function.declaration // ^^ meta.block punctuation.section.block -const test = ({a, b, c=()=>({active:false}) }) => {} +const test = ({a, b, c=()=>({active:false}) }) => {}; // ^ entity.name.function // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block @@ -624,7 +624,7 @@ xhr.onload = () => {} // <- support.class.js // ^ entity.name.function -var simpleArrow = foo => bar +var simpleArrow = foo => bar; // ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // ^ entity.name.function // ^ variable.parameter.function @@ -637,7 +637,7 @@ var Proto = () => { this._var = 1; } -Proto.prototype.getVar = () => this._var +Proto.prototype.getVar = () => this._var; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // ^ support.class // ^ support.constant.prototype @@ -792,7 +792,7 @@ var reg = /a+/gimy.exec('aabb') // ^^^^ keyword.other // ^ punctuation.accessor -'aabbcc'.replace(/b+/, 'd') +'aabbcc'.replace(/b+/, 'd'); // ^^^^ string.regexp // ^ keyword.operator.quantifier.regexp @@ -942,7 +942,7 @@ var arrowFuncBraceNextLine = () => /* comments! */ var conciseFunc = () => foo //^^^ meta.block variable.other.readwrite - .bar() + .bar(); //^^^^^^ meta.block // Handle an arrow function in a parenthetical group From d06206ca6bffa30582b7aa464391a8e962f592b9 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 10:33:26 -0400 Subject: [PATCH 07/46] Renamed "expressions" to singular "expression". --- JavaScript/JavaScript.sublime-syntax | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 442c03f8cf..36c6b4c6f8 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -140,7 +140,7 @@ contexts: - match: (?=function) set: function-declaration - - include: expressions + - include: expression - match: '\{' scope: meta.block.js punctuation.section.block.js set: export-brace @@ -299,7 +299,7 @@ contexts: - match: \n pop: true - match: (?=\S) - set: expressions + set: expression-statement conditional: - match: \bswitch\b @@ -347,7 +347,7 @@ contexts: - match: '(?=\))' pop: true - match: (?=\S) - push: expressions + push: expression - match: '\)' scope: meta.group.js punctuation.section.group.js pop: true @@ -413,7 +413,7 @@ contexts: scope: punctuation.terminator.statement.js - match: (?=\S) - push: expressions + push: expression - include: block-scope block-scope: @@ -434,7 +434,7 @@ contexts: - match: (?=[;})\]]) pop: true - expressions: + expression: - match: (?=\S) set: [ expression-end, expression-begin ] @@ -569,7 +569,7 @@ contexts: scope: punctuation.definition.template-expression.end.js pop: true - match: (?=\S) - push: expressions + push: expression - include: string-content string-content: @@ -651,7 +651,7 @@ contexts: scope: punctuation.section.group.js set: constructor-params - match: (?=\S) - push: expressions + push: expression - match: '(?=\S)' pop: true @@ -1083,7 +1083,7 @@ contexts: scope: punctuation.section.brackets.js pop: true - match: (?=\S) - push: expressions + push: expression - match: '({{identifier}})\s*(\})' captures: 1: variable.other.readwrite.js @@ -1274,7 +1274,7 @@ contexts: scope: punctuation.section.group.js pop: true - match: (?=\S) - push: expressions + push: expression - match: \) scope: invalid.illegal.stray-bracket-end.js pop: true @@ -1288,7 +1288,7 @@ contexts: scope: punctuation.section.group.js pop: true - match: (?=\S) - push: expressions + push: expression square-brackets: - match: '\[' @@ -1299,7 +1299,7 @@ contexts: scope: punctuation.section.brackets.js pop: true - match: (?=\S) - push: expressions + push: expression bracketed-property-access: - match: '\[' @@ -1310,7 +1310,7 @@ contexts: scope: punctuation.section.brackets.js pop: true - match: (?=\S) - push: expressions + push: expression literal-number: - match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)' From 5114ff9f647d04c5cd787837a629c882ca3e9b82 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 16:30:26 -0400 Subject: [PATCH 08/46] Moved comment contexts to the top of the file. --- JavaScript/JavaScript.sublime-syntax | 62 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index d70791e764..ccc3a3424d 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -24,6 +24,37 @@ contexts: prototype: - include: comments + comments: + - match: /\*\*(?!/) + scope: punctuation.definition.comment.js + push: + - meta_include_prototype: false + - meta_scope: comment.block.documentation.js + - match: \*/ + scope: punctuation.definition.comment.js + pop: true + - match: /\* + scope: punctuation.definition.comment.js + push: + - meta_include_prototype: false + - meta_scope: comment.block.js + - match: \*/ + scope: punctuation.definition.comment.js + pop: true + - match: // + scope: punctuation.definition.comment.js + push: + - meta_include_prototype: false + - meta_scope: comment.line.double-slash.js + - match: \n + pop: true + + comments-top-level: + - match: ^(#!).*$\n? + scope: comment.line.shebang.js + captures: + 1: punctuation.definition.comment.js + keywords-top-level: - match: \bimport\b scope: meta.import.js keyword.control.import-export.js @@ -216,12 +247,6 @@ contexts: - match: '(?=\S)' pop: true - comments-top-level: - - match: ^(#!).*$\n? - scope: comment.line.shebang.js - captures: - 1: punctuation.definition.comment.js - statements: - include: conditional - match: '\{' @@ -410,31 +435,6 @@ contexts: - match: '(?=[\S\n])' pop: true - comments: - - match: /\*\*(?!/) - scope: punctuation.definition.comment.js - push: - - meta_include_prototype: false - - meta_scope: comment.block.documentation.js - - match: \*/ - scope: punctuation.definition.comment.js - pop: true - - match: /\* - scope: punctuation.definition.comment.js - push: - - meta_include_prototype: false - - meta_scope: comment.block.js - - match: \*/ - scope: punctuation.definition.comment.js - pop: true - - match: // - scope: punctuation.definition.comment.js - push: - - meta_include_prototype: false - - meta_scope: comment.line.double-slash.js - - match: \n - pop: true - literal-string: - match: "'" scope: punctuation.definition.string.begin.js From 51d601979d22fd48bd76bab70c02f866e82ca6ad Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 28 May 2017 21:41:45 -0400 Subject: [PATCH 09/46] Expression scope is now pushed. --- JavaScript/JavaScript.sublime-syntax | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index ccc3a3424d..7b94f1c3b4 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -248,6 +248,9 @@ contexts: pop: true statements: + - match: \; + scope: punctuation.terminator.statement.js + - include: conditional - match: '\{' scope: punctuation.section.block.js @@ -258,7 +261,13 @@ contexts: pop: true - include: statements - include: label - - include: expressions + # - include: expressions + + - match: (?=\S) + push: + - match: \n + pop: true + - include: expressions conditional: - match: \bswitch\b @@ -365,6 +374,10 @@ contexts: - match: '\)' scope: punctuation.section.group.js pop: true + + - match: ; + scope: punctuation.terminator.statement.js + - include: expressions - include: block-scope @@ -383,6 +396,12 @@ contexts: pop: true expressions: + - match: (?=;) + pop: true + + - match: (?=}) + pop: true + - include: regexp-complete - include: literal-string - include: literal-string-template @@ -688,6 +707,7 @@ contexts: captures: # these keywords are restricted productions and implicitly end at the end of the line, so we don't push the after-operator scope 1: keyword.control.trycatch.js 2: keyword.control.flow.js + pop: true - match: \bthrow\b scope: keyword.control.trycatch.js push: after-operator @@ -1431,7 +1451,7 @@ contexts: - match: '(?=.|\n)' pop: true - include: object-property - - match: \; - scope: punctuation.terminator.statement.js + # - match: \; + # scope: punctuation.terminator.statement.js - match: "," scope: punctuation.separator.comma.js From edf9547b8e0bf007c08c51c63111b94650eca7bd Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 28 May 2017 22:19:55 -0400 Subject: [PATCH 10/46] Moved statement keywords to statements context. --- JavaScript/JavaScript.sublime-syntax | 57 ++++++++++++++++------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 7b94f1c3b4..db15ecfcfc 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -157,7 +157,9 @@ contexts: export-extended: - meta_content_scope: meta.export.js - - match: '(?=\b(let|const|var)\b)' + + - match: \b(const|let|var)\b + scope: storage.type.js set: - meta_content_scope: meta.export.js - match: '(?=;|\n)' @@ -261,7 +263,25 @@ contexts: pop: true - include: statements - include: label - # - include: expressions + + - include: variable-declaration + + - match: \bthrow\b + scope: keyword.control.trycatch.js + push: restricted-production + + - match: \b(break|continue|goto)\b + scope: keyword.control.loop.js + + - match: \b(yield)\b(?:\s*(\*))? + captures: + 1: keyword.control.flow.js + 2: keyword.generator.asterisk.js + push: restricted-production + + - match: \b(await|return)\b + scope: keyword.control.flow.js + push: restricted-production - match: (?=\S) push: @@ -269,6 +289,16 @@ contexts: pop: true - include: expressions + variable-declaration: + - match: \b(const|let|var)\b + scope: storage.type.js + + restricted-production: + - match: \n + pop: true + - match: (?=\S) + set: expressions + conditional: - match: \bswitch\b scope: keyword.control.switch.js @@ -409,7 +439,6 @@ contexts: - include: unary-operators - include: binary-operators - include: class - - include: keywords - include: constants - include: literal-prototype - include: named-function @@ -702,28 +731,6 @@ contexts: pop: true - include: method-declaration - keywords: - - match: ^\s*\b(?:(throw)|(yield|return))\b\s*$ - captures: # these keywords are restricted productions and implicitly end at the end of the line, so we don't push the after-operator scope - 1: keyword.control.trycatch.js - 2: keyword.control.flow.js - pop: true - - match: \bthrow\b - scope: keyword.control.trycatch.js - push: after-operator - - match: \b(break|continue|goto)\b - scope: keyword.control.loop.js - - match: \b(yield)\b(?:\s*(\*))? - captures: - 1: keyword.control.flow.js - 2: keyword.generator.asterisk.js - push: after-operator - - match: \b(await|return)\b - scope: keyword.control.flow.js - push: after-operator - - match: \b(const|let|var)\b - scope: storage.type.js - constants: - match: \btrue\b scope: constant.language.boolean.true.js From 8bf34b8e934748aec19555f6bb8050a11bbb9aa4 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 28 May 2017 22:43:35 -0400 Subject: [PATCH 11/46] Added class and function statements. Implemented semicolon insertion. --- JavaScript/JavaScript.sublime-syntax | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index db15ecfcfc..aa2cd619bc 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -283,16 +283,31 @@ contexts: scope: keyword.control.flow.js push: restricted-production + - include: literal-prototype + - include: class + - include: named-function + - match: (?=\S) - push: - - match: \n - pop: true - - include: expressions + push: expression-statement variable-declaration: - match: \b(const|let|var)\b scope: storage.type.js + expression-statement: + - match: \n + set: + - match: >- + (?x) (?= + \+\+ | + \+= | + [-+*><&|^\[(] + ) + set: expression-statement + - match: (?=\S) + pop: true + - include: expressions + restricted-production: - match: \n pop: true @@ -440,7 +455,6 @@ contexts: - include: binary-operators - include: class - include: constants - - include: literal-prototype - include: named-function - include: anonymous-function - include: object-literal From e522556c337352949980c83779ee1afd3f777278 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 01:23:31 -0400 Subject: [PATCH 12/46] Implemented the two-level expression scheme. All tests pass, somehow. --- JavaScript/JavaScript.sublime-syntax | 357 ++++++++++++++++----------- JavaScript/syntax_test_js.js | 12 +- 2 files changed, 225 insertions(+), 144 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index aa2cd619bc..66fe18cf01 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -145,7 +145,8 @@ contexts: - meta_scope: meta.import.js - match: '\bfrom\b' scope: keyword.control.import-export.js - - include: literal-string + - match: (?=['"]) + push: literal-string - match: '(?=\S)' pop: true @@ -158,20 +159,18 @@ contexts: export-extended: - meta_content_scope: meta.export.js - - match: \b(const|let|var)\b - scope: storage.type.js - set: - - meta_content_scope: meta.export.js - - match: '(?=;|\n)' - pop: true - - include: expressions + - include: variable-declaration - include: export-escape + - match: '\bdefault\b' scope: keyword.control.import-export.js - set: - - meta_content_scope: meta.export.js - - match: '(?=;|\n)' - pop: true + push: + - match: (?=class) + set: class + + - match: (?=function) + set: function-declaration + - include: expressions - match: '\{' scope: meta.block.js punctuation.section.block.js @@ -245,7 +244,8 @@ contexts: - meta_scope: meta.export.js - match: '\bfrom\b' scope: keyword.control.import-export.js - - include: literal-string + - match: (?=['"]) + push: literal-string - match: '(?=\S)' pop: true @@ -283,9 +283,7 @@ contexts: scope: keyword.control.flow.js push: restricted-production - - include: literal-prototype - - include: class - - include: named-function + - include: function-or-class-declaration - match: (?=\S) push: expression-statement @@ -293,20 +291,34 @@ contexts: variable-declaration: - match: \b(const|let|var)\b scope: storage.type.js + push: expression-statement + + function-or-class-declaration: + - match: (?=class) + push: class + + - match: (?=function) + push: named-function expression-statement: + - match: (?=\S) + set: [ expression-statement-end, expression-begin ] + + expression-statement-end: - match: \n - set: - - match: >- - (?x) (?= - \+\+ | - \+= | - [-+*><&|^\[(] - ) - set: expression-statement - - match: (?=\S) - pop: true - - include: expressions + set: expression-statement-line-continuation + - include: expression-end + + expression-statement-line-continuation: + - match: >- + (?x) (?= + \+\+ | + \+= | + [-+*/><&|^\[(] + ) + set: expression-statement-end + - match: (?=\S) + pop: true restricted-production: - match: \n @@ -319,7 +331,8 @@ contexts: scope: keyword.control.switch.js push: - meta_scope: meta.switch.js - - include: round-brackets + - match: (?=\() + push: round-brackets - match: '\}' scope: meta.block.js punctuation.section.block.js pop: true @@ -336,7 +349,7 @@ contexts: - include: statements - match: \b(case|default)\b scope: keyword.control.switch.js - - include: expressions + - include: statements - match: \bdo\b scope: keyword.control.loop.js @@ -358,7 +371,8 @@ contexts: - meta_scope: meta.group.js - match: '(?=\))' pop: true - - include: expressions + - match: (?=\S) + push: expressions - match: '\)' scope: meta.group.js punctuation.section.group.js pop: true @@ -423,7 +437,8 @@ contexts: - match: ; scope: punctuation.terminator.statement.js - - include: expressions + - match: (?=\S) + push: expressions - include: block-scope block-scope: @@ -440,86 +455,96 @@ contexts: - match: '(?=\S)' pop: true + expression-break: + - match: (?=[;})\]]) + pop: true + expressions: - - match: (?=;) + - match: (?=\S) + set: [ expression-end, expression-begin ] + + expression-no-comma: + - match: (?=\S) + set: [ expression-end-no-comma, expression-begin ] + + expression-end: + - include: expression-break + + - include: postfix-operators + - include: binary-operators + + - include: bracketed-property-access + - include: function-call + + - include: literal-punctuation + - include: fallthrough + + - match: (?=\S) pop: true - - match: (?=}) + expression-end-no-comma: + - match: (?=,) pop: true + - include: expression-end + + expression-begin: + - match: \) + scope: invalid.illegal.stray-bracket-end + pop: true + + - include: expression-break + + - include: literal-prototype - include: regexp-complete - include: literal-string - include: literal-string-template - include: constructor - - include: unary-operators - - include: binary-operators + - include: prefix-operators + - include: class - include: constants - include: named-function - include: anonymous-function - include: object-literal + - include: brackets + - include: literal-number - include: literal-call - include: literal-variable - - include: literal-punctuation - - include: fallthrough + + - match: (?=\S) + pop: true fallthrough: # If an arrow function has the ( and ) on different lines, we won't have matched - match: => - scope: storage.type.function.arrow.js - - after-operator: - # Prevent matching "{" as a block, but instead always treat as an object - # literal. This is needed since in the "statements" context, a "{" starts - # an anonymous block, not an object literal. - - match: '(?=\{)' - push: - - include: object-literal - - match: '(?=.|\n)' - pop: true - # When following an operator, a single / is the beginning of a regexp, - # not a division operator - - match: '/(?=[^/*])' - scope: punctuation.definition.string.begin.js - push: regexp - - include: constants - - match: '(?=[\S])' - pop: true - - after-identifier: - # When following an identifier or closing )/], a single / is a division - # operator, not the beginning of a regexp - - match: '/(?=[^/*])' - scope: keyword.operator.arithmetic.js - set: after-operator - - match: '(?=[\S\n])' - pop: true + scope: storage.type.function.arrow.js FALLTHROUGH literal-string: - match: "'" scope: punctuation.definition.string.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.single.js - match: (')|(\n) captures: 1: punctuation.definition.string.end.js 2: invalid.illegal.newline.js - set: after-identifier + pop: true - include: string-content - match: '"' captures: 0: punctuation.definition.string.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.js - match: (")|(\n) captures: 1: punctuation.definition.string.end.js 2: invalid.illegal.newline.js - set: after-identifier + pop: true - include: string-content literal-string-template: @@ -527,12 +552,12 @@ contexts: captures: 1: variable.function.tagged-template.js 2: punctuation.definition.string.template.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.template.js - match: "`" scope: punctuation.definition.string.template.end.js - set: after-identifier + pop: true - match: '\$\{' captures: 0: punctuation.definition.template-expression.begin.js @@ -543,7 +568,8 @@ contexts: - match: '\}' scope: punctuation.definition.template-expression.end.js pop: true - - include: expressions + - match: (?=\S) + push: expressions - include: string-content string-content: @@ -553,9 +579,9 @@ contexts: scope: constant.character.escape.js regexp-complete: - - match: '/(?=(?:[^/\\\[]|\\.|\[([^\]\\]|\\.)+\])+/(?![/*])[gimyu]*(?!\s*[a-zA-Z0-9_$]))' + - match: '/' scope: punctuation.definition.string.begin.js - push: regexp + set: regexp regexp: - meta_include_prototype: false @@ -564,7 +590,7 @@ contexts: captures: 1: punctuation.definition.string.end.js 2: keyword.other.js - set: after-identifier + pop: true - match: '(?=.|\n)' push: - meta_include_prototype: false @@ -577,7 +603,7 @@ contexts: scope: meta.instance.constructor.js captures: 1: keyword.operator.word.new.js - push: constructor-name + set: constructor-name constructor-name: - match: '(?=function\b)' @@ -612,7 +638,7 @@ contexts: scope: variable.type.js - match: '\.' scope: punctuation.accessor.js - - include: square-brackets + - include: bracketed-property-access - match: '(?=\()' set: constructor-params - match: '(?=\S|$)' @@ -624,7 +650,8 @@ contexts: - match: '\)' scope: punctuation.section.group.js set: constructor-params - - include: expressions + - match: (?=\S) + push: expressions - match: '(?=\S)' pop: true @@ -637,7 +664,7 @@ contexts: - match: '(?=\S)' pop: true - unary-operators: + prefix-operators: - match: '~' scope: keyword.operator.bitwise.js - match: '!(?!=)' @@ -648,21 +675,27 @@ contexts: scope: keyword.operator.arithmetic.js - match: \.\.\. scope: keyword.operator.spread.js + - match: \+|\- + scope: keyword.operator.arithmetic.js - binary-operators: - match: \bnew\b scope: keyword.operator.word.new.js - - match: \b(delete|instanceof)\b + - match: \bdelete|typeof|void\b scope: keyword.operator.js - - match: \b(in|of|typeof|void)\b + + binary-operators: + - match: \binstanceof\b + scope: keyword.operator.js + push: expression-begin + - match: \b(in|of)\b scope: keyword.operator.js - push: after-operator + push: expression-begin - match: '&&|\|\|' scope: keyword.operator.logical.js - push: after-operator + push: expression-begin - match: '=(?![=>])' scope: keyword.operator.assignment.js - push: after-operator + push: expression-begin - match: |- (?x) %= | # assignment right-to-left both @@ -677,7 +710,7 @@ contexts: >>= | # assignment right-to-left both >>>= # assignment right-to-left both scope: keyword.operator.assignment.augmented.js - push: after-operator + push: expression-begin - match: |- (?x) << | # bitwise-shift left-to-right both @@ -687,7 +720,7 @@ contexts: \^ | # bitwise-xor left-to-right both \| # bitwise-or left-to-right both scope: keyword.operator.bitwise.js - push: after-operator + push: expression-begin - match: |- (?x) <= | # relational left-to-right both @@ -695,7 +728,7 @@ contexts: < | # relational left-to-right both > # relational left-to-right both scope: keyword.operator.relational.js - push: after-operator + push: expression-begin - match: |- (?x) === | # equality left-to-right both @@ -703,7 +736,7 @@ contexts: == | # equality left-to-right both != # equality left-to-right both scope: keyword.operator.comparison.js - push: after-operator + push: expression-begin - match: |- (?x) / | # division left-to-right both @@ -712,15 +745,20 @@ contexts: \+ | # addition left-to-right both - # subtraction left-to-right both scope: keyword.operator.arithmetic.js - push: after-operator + push: expression-begin - match: '\?|:' scope: keyword.operator.ternary.js - push: after-operator + push: expression-begin + + postfix-operators: + - match: '--' + scope: keyword.operator.arithmetic.js + - match: '\+\+' class: - match: \bclass\b scope: storage.type.class.js - push: + set: - meta_scope: meta.class.js - match: '\{' scope: punctuation.section.block.js @@ -748,19 +786,19 @@ contexts: constants: - match: \btrue\b scope: constant.language.boolean.true.js - push: after-identifier + pop: true - match: \bfalse\b scope: constant.language.boolean.false.js - push: after-identifier + pop: true - match: \bnull\b scope: constant.language.null.js - push: after-identifier + pop: true - match: \bundefined\b scope: constant.language.undefined.js - push: after-identifier + pop: true - match: \bNaN\b scope: constant.language.nan.js - push: after-identifier + pop: true literal-prototype: - match: '({{identifier}})\s*(\.)\s*(prototype)(?=\s*=\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' @@ -769,7 +807,7 @@ contexts: 1: support.class.js 2: punctuation.accessor.js 3: support.constant.prototype.js - push: + set: - meta_scope: meta.function.declaration.js - match: '\s*(=)\s*' captures: @@ -786,7 +824,7 @@ contexts: 2: punctuation.accessor.js 3: support.constant.prototype.js 4: punctuation.accessor.js - push: + set: - meta_scope: meta.function.declaration.js - match: '(?={{func_lookahead}})' set: function-declaration @@ -799,10 +837,11 @@ contexts: 1: support.class.js 2: punctuation.accessor.js 3: support.constant.prototype.js + pop: true named-function: - match: '(?=(({{identifier}})\s*(\.)\s*)+({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' - push: + set: - meta_scope: meta.function.declaration.js - match: '(?={{func_lookahead}})' set: function-declaration @@ -810,7 +849,7 @@ contexts: set: arrow-function-declaration - include: function-declaration-identifiers - match: '(?=({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' - push: + set: - meta_scope: meta.function.declaration.js - match: '(?={{func_lookahead}})' set: function-declaration @@ -818,15 +857,15 @@ contexts: set: arrow-function-declaration - include: function-declaration-single-identifier - match: '(?={{func_lookahead}}(\s*\*)?\s+{{identifier}})' - push: function-declaration + set: function-declaration anonymous-function: - match: '(?={{func_lookahead}})' - push: + set: - meta_content_scope: meta.function.anonymous.js - include: function-declaration - match: '(?={{arrow_func_lookahead}})' - push: + set: - meta_content_scope: meta.function.anonymous.js - include: arrow-function-declaration @@ -955,7 +994,8 @@ contexts: - meta_scope: comment.line.double-slash.js - match: \n set: arrow-function-concise-continuation - - include: expressions + - match: (?=\S) + push: expression-no-comma arrow-function-concise-continuation: # Allow newlines in a concise body if the next line is a continuation @@ -1003,7 +1043,8 @@ contexts: - meta_scope: meta.parameter.optional.js - match: "(?=[,)}])" pop: true - - include: expressions + - match: (?=\S) + push: expression-no-comma - match: \.\.\. scope: keyword.operator.spread.js - match: '{{identifier}}' @@ -1016,7 +1057,8 @@ contexts: - meta_scope: meta.parameter.optional.js - match: "(?=[,)])" pop: true - - include: expressions + - match: (?=\S) + push: expression-no-comma label: - match: '^\s*((?!default){{identifier}})\s*(:)' @@ -1027,18 +1069,21 @@ contexts: object-literal: - match: '\{' scope: punctuation.section.block.js - push: + set: - meta_scope: meta.object-literal.js - match: '\}' scope: punctuation.section.block.js - set: after-identifier + pop: true + - match: ',' + scope: punctuation.separator.comma.js - match: \[ scope: punctuation.section.brackets.js push: - match: \] scope: punctuation.section.brackets.js pop: true - - include: expressions + - match: (?=\S) + push: expressions - match: '({{identifier}})\s*(\})' captures: 1: variable.other.readwrite.js @@ -1058,9 +1103,11 @@ contexts: 2: punctuation.dollar.js 3: punctuation.separator.key-value.js push: + - meta_scope: TEST - match: ':' scope: meta.function.declaration.js punctuation.separator.key-value.js - - include: either-function-declaration + set: expression-no-comma + # set: either-function-declaration - match: '(?=\S)' pop: true - match: "(?=('.*'|\".*\"|{{identifier}})\\s*:({{func_lookahead}}|{{arrow_func_lookahead}}))" @@ -1116,16 +1163,16 @@ contexts: scope: meta.object-literal.key.js - match: (?=[-+]?(?:\.[0-9]|0[bxo]|\d)) push: - - meta_content_scope: meta.object-literal.key.js + - meta_scope: meta.object-literal.key.js - include: literal-number - - match: '' - pop: true + # - match: '' + # pop: true - match: ':' scope: punctuation.separator.key-value.js push: - match: "(?=\\}|,|('[^']*'|\"[^\"]*\"|{{identifier}})\\s*:)" pop: true - - include: expressions + - include: expression-no-comma method-declaration: - match: \b(get|set)\b(?!\s*\()\s* @@ -1221,30 +1268,57 @@ contexts: round-brackets: - match: \( scope: punctuation.section.group.js - push: + set: - meta_scope: meta.group.js - match: \) scope: punctuation.section.group.js - set: after-identifier - - include: expressions + pop: true + - match: (?=\S) + push: expressions - match: \) scope: invalid.illegal.stray-bracket-end.js + pop: true + + function-call: + - match: \( + scope: punctuation.section.group.js + push: + - meta_scope: meta.group.js + - match: \) + scope: punctuation.section.group.js + pop: true + - match: (?=\S) + push: expressions square-brackets: + - match: '\[' + scope: punctuation.section.brackets.js + set: + - meta_scope: meta.brackets.js + - match: '\]' + scope: punctuation.section.brackets.js + pop: true + - match: (?=\S) + push: expressions + + bracketed-property-access: - match: '\[' scope: punctuation.section.brackets.js push: - meta_scope: meta.brackets.js - match: '\]' scope: punctuation.section.brackets.js - set: after-identifier - - include: expressions + pop: true + - match: (?=\S) + push: expressions literal-number: - match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)' scope: invalid.illegal.numeric.hex.js + pop: true - match: '(?:\B[-+]|\b)0[0-9]+\.(\B|\b[0-9]+)' scope: invalid.illegal.numeric.octal.js + pop: true - match: |- (?xi) (?:\B[-+])? @@ -1258,29 +1332,29 @@ contexts: )(e[-+]?[0-9]+)? # e.g. e+123, E-123 ) scope: constant.numeric.js - push: after-identifier + pop: true - match: '(?:\B[-+]|\b)(Infinity)\b' scope: constant.language.infinity.js - push: after-identifier + pop: true literal-call: - match: (\$)(?=\s*\() scope: variable.function.js variable.other.dollar.only.js punctuation.dollar.js - push: + set: - meta_scope: meta.function-call.js - include: function-call-params - match: \b(clearTimeout|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|escape|eval|isFinite|isNaN|parseFloat|parseInt|setTimeout|super|unescape)\b(?=\() scope: support.function.js - push: + set: - meta_scope: meta.function-call.js - include: function-call-params - match: '({{identifier}})(?=\s*\()' scope: variable.function.js - push: + set: - meta_scope: meta.function-call.js - include: function-call-params - match: '(?={{identifier}}\s*\.\s*{{identifier}}\s*\()' - push: + set: - match: \b(console)(?:(\.)(warn|info|log|error|time|timeEnd|assert|count|dir|group|groupCollapsed|groupEnd|profile|profileEnd|table|trace|timeStamp))?\b captures: 1: support.type.object.console.js @@ -1321,44 +1395,45 @@ contexts: method-call: - match: \b(shift|sort|splice|unshift|pop|push|reverse|copyWithin|fill)\b(?=\() scope: support.function.mutator.js - push: + set: - meta_scope: meta.function-call.method.js - include: function-call-params - match: \b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\b(?=\() scope: support.function.dom.js - push: + set: - meta_scope: meta.function-call.method.js - include: function-call-params - match: '({{identifier}})\s*(?=\()' scope: variable.function.js - push: + set: - meta_scope: meta.function-call.method.js - include: function-call-params function-call-params: - match: '\)' scope: meta.group.js punctuation.section.group.js - set: after-identifier + pop: true - match: '\(' scope: punctuation.section.group.js push: - meta_scope: meta.group.js - match: '(?=\))' - set: after-identifier + pop: true # Consume comma plus any whitespace to prevent whitespace from # getting meta scopes when they don't really apply - match: '(,)\s+' captures: 1: punctuation.separator.comma.js - - include: expressions + - match: (?=\S) + push: expression-no-comma literal-variable: - match: '(?={{identifier}})' - push: + set: # Once we've consumed an identifier, switch to the special context that # property handles ambiguous tokens including "/" - match: '(?!{{identifier}})' - set: after-identifier + pop: true - include: well-known-identifiers - include: language-identifiers - include: dollar-identifiers @@ -1432,22 +1507,29 @@ contexts: object-property: - match: \b__proto__\b scope: variable.language.proto.js + pop: true - match: \bconstructor\b scope: variable.language.constructor.js + pop: true - match: \bprototype\b scope: variable.language.prototype.js + pop: true - match: '{{dollar_only_identifier}}' scope: meta.property.object.dollar.only.js punctuation.dollar.js + pop: true - match: '{{dollar_identifier}}' scope: meta.property.object.dollar.js captures: 1: punctuation.dollar.js + pop: true - match: '{{identifier}}' scope: meta.property.object.js + pop: true - match: \b(s(hape|ystemId|c(heme|ope|rolling)|ta(ndby|rt)|ize|ummary|pecified|e(ctionRowIndex|lected(Index)?)|rc)|h(space|t(tpEquiv|mlFor)|e(ight|aders)|ref(lang)?)|n(o(Resize|tation(s|Name)|Shade|Href|de(Name|Type|Value)|Wrap)|extSibling|ame)|c(h(ildNodes|Off|ecked|arset)?|ite|o(ntent|o(kie|rds)|de(Base|Type)?|l(s|Span|or)|mpact)|ell(s|Spacing|Padding)|l(ear|assName)|aption)|t(ype|Bodies|itle|Head|ext|a(rget|gName)|Foot)|i(sMap|ndex|d|m(plementation|ages))|o(ptions|wnerDocument|bject)|d(i(sabled|r)|o(c(type|umentElement)|main)|e(clare|f(er|ault(Selected|Checked|Value)))|at(eTime|a))|useMap|p(ublicId|arentNode|r(o(file|mpt)|eviousSibling))|e(n(ctype|tities)|vent|lements)|v(space|ersion|alue(Type)?|Link|Align)|URL|f(irstChild|orm(s)?|ace|rame(Border)?)|width|l(ink(s)?|o(ngDesc|wSrc)|a(stChild|ng|bel))|a(nchors|c(ce(ssKey|pt(Charset)?)|tion)|ttributes|pplets|l(t|ign)|r(chive|eas)|xis|Link|bbr)|r(ow(s|Span|Index)|ules|e(v|ferrer|l|adOnly))|m(ultiple|e(thod|dia)|a(rgin(Height|Width)|xLength))|b(o(dy|rder)|ackground|gColor))\b scope: support.constant.dom.js + pop: true - match: '(?=.|\n)' - set: after-identifier + pop: true literal-punctuation: - match: \. @@ -1472,7 +1554,6 @@ contexts: - match: '(?=.|\n)' pop: true - include: object-property - # - match: \; - # scope: punctuation.terminator.statement.js - - match: "," + - match: ',' scope: punctuation.separator.comma.js + push: expression-begin diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index 2b4c526ded..c9fbf07174 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -251,7 +251,7 @@ var obj = { // ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // <- meta.object-literal.key.dollar entity.name.function punctuation.dollar // <- meta.object-literal.key.dollar entity.name.function - punctuation.dollar - } + }, [true==false ? 'one' : 'two']: false, // ^ punctuation.section.brackets @@ -585,7 +585,7 @@ class Foo extends React.Component { //^^^ meta.function.anonymous meta.function.declaration // ^^ meta.block punctuation.section.block -const test = ({a, b, c=()=>({active:false}) }) => {} +const test = ({a, b, c=()=>({active:false}) }) => {}; // ^ entity.name.function // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block @@ -624,7 +624,7 @@ xhr.onload = () => {} // <- support.class.js // ^ entity.name.function -var simpleArrow = foo => bar +var simpleArrow = foo => bar; // ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // ^ entity.name.function // ^ variable.parameter.function @@ -637,7 +637,7 @@ var Proto = () => { this._var = 1; } -Proto.prototype.getVar = () => this._var +Proto.prototype.getVar = () => this._var; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // ^ support.class // ^ support.constant.prototype @@ -792,7 +792,7 @@ var reg = /a+/gimy.exec('aabb') // ^^^^ keyword.other // ^ punctuation.accessor -'aabbcc'.replace(/b+/, 'd') +'aabbcc'.replace(/b+/, 'd'); // ^^^^ string.regexp // ^ keyword.operator.quantifier.regexp @@ -942,7 +942,7 @@ var arrowFuncBraceNextLine = () => /* comments! */ var conciseFunc = () => foo //^^^ meta.block variable.other.readwrite - .bar() + .bar(); //^^^^^^ meta.block // Handle an arrow function in a parenthetical group From 9cd5d1a4e839c164163e80e63ad06500fc519632 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 10:33:26 -0400 Subject: [PATCH 13/46] Renamed "expressions" to singular "expression". --- JavaScript/JavaScript.sublime-syntax | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 66fe18cf01..9393736d77 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -171,7 +171,7 @@ contexts: - match: (?=function) set: function-declaration - - include: expressions + - include: expression - match: '\{' scope: meta.block.js punctuation.section.block.js set: export-brace @@ -324,7 +324,7 @@ contexts: - match: \n pop: true - match: (?=\S) - set: expressions + set: expression-statement conditional: - match: \bswitch\b @@ -372,7 +372,7 @@ contexts: - match: '(?=\))' pop: true - match: (?=\S) - push: expressions + push: expression - match: '\)' scope: meta.group.js punctuation.section.group.js pop: true @@ -438,7 +438,7 @@ contexts: scope: punctuation.terminator.statement.js - match: (?=\S) - push: expressions + push: expression - include: block-scope block-scope: @@ -459,7 +459,7 @@ contexts: - match: (?=[;})\]]) pop: true - expressions: + expression: - match: (?=\S) set: [ expression-end, expression-begin ] @@ -569,7 +569,7 @@ contexts: scope: punctuation.definition.template-expression.end.js pop: true - match: (?=\S) - push: expressions + push: expression - include: string-content string-content: @@ -651,7 +651,7 @@ contexts: scope: punctuation.section.group.js set: constructor-params - match: (?=\S) - push: expressions + push: expression - match: '(?=\S)' pop: true @@ -1083,7 +1083,7 @@ contexts: scope: punctuation.section.brackets.js pop: true - match: (?=\S) - push: expressions + push: expression - match: '({{identifier}})\s*(\})' captures: 1: variable.other.readwrite.js @@ -1274,7 +1274,7 @@ contexts: scope: punctuation.section.group.js pop: true - match: (?=\S) - push: expressions + push: expression - match: \) scope: invalid.illegal.stray-bracket-end.js pop: true @@ -1288,7 +1288,7 @@ contexts: scope: punctuation.section.group.js pop: true - match: (?=\S) - push: expressions + push: expression square-brackets: - match: '\[' @@ -1299,7 +1299,7 @@ contexts: scope: punctuation.section.brackets.js pop: true - match: (?=\S) - push: expressions + push: expression bracketed-property-access: - match: '\[' @@ -1310,7 +1310,7 @@ contexts: scope: punctuation.section.brackets.js pop: true - match: (?=\S) - push: expressions + push: expression literal-number: - match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)' From bb77569d329946f882f7defabeaa2e5d8e902d60 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 14:15:48 -0400 Subject: [PATCH 14/46] Minor cleanup. --- JavaScript/JavaScript.sublime-syntax | 64 +++++++++++----------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 9393736d77..2ecb708652 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -15,6 +15,13 @@ variables: func_lookahead: '\s*\b(async\s+)?function\b' arrow_func_lookahead: '\s*(\basync\s*)?([_$[:alpha:]][_$[:alnum:]]*|\(([^()]|\([^()]*\))*\))\s*=>' + line_continuation_lookahead: >- + (?x) (?= + \+\+ | + \+= | + [-+*/><&|^\[(] + ) + contexts: main: - include: comments-top-level @@ -55,6 +62,10 @@ contexts: captures: 1: punctuation.definition.comment.js + else-pop: + - match: (?=\S) + pop: true + keywords-top-level: - match: \bimport\b scope: meta.import.js keyword.control.import-export.js @@ -306,20 +317,12 @@ contexts: expression-statement-end: - match: \n - set: expression-statement-line-continuation + set: + - match: '{{line_continuation_lookahead}}' + set: expression-statement-end + - include: else-pop - include: expression-end - expression-statement-line-continuation: - - match: >- - (?x) (?= - \+\+ | - \+= | - [-+*/><&|^\[(] - ) - set: expression-statement-end - - match: (?=\S) - pop: true - restricted-production: - match: \n pop: true @@ -332,7 +335,7 @@ contexts: push: - meta_scope: meta.switch.js - match: (?=\() - push: round-brackets + push: parenthesized-expression - match: '\}' scope: meta.block.js punctuation.section.block.js pop: true @@ -479,8 +482,7 @@ contexts: - include: literal-punctuation - include: fallthrough - - match: (?=\S) - pop: true + - include: else-pop expression-end-no-comma: - match: (?=,) @@ -508,14 +510,14 @@ contexts: - include: anonymous-function - include: object-literal - - include: brackets + - include: parenthesized-expression + - include: array-literal - include: literal-number - include: literal-call - include: literal-variable - - match: (?=\S) - pop: true + - include: else-pop fallthrough: # If an arrow function has the ( and ) on different lines, we won't have matched @@ -1103,13 +1105,10 @@ contexts: 2: punctuation.dollar.js 3: punctuation.separator.key-value.js push: - - meta_scope: TEST - match: ':' scope: meta.function.declaration.js punctuation.separator.key-value.js set: expression-no-comma - # set: either-function-declaration - - match: '(?=\S)' - pop: true + - include: else-pop - match: "(?=('.*'|\".*\"|{{identifier}})\\s*:({{func_lookahead}}|{{arrow_func_lookahead}}))" push: - meta_content_scope: meta.object-literal.key.js meta.function.declaration.js @@ -1146,15 +1145,13 @@ contexts: captures: 1: punctuation.separator.key-value.js - include: either-function-declaration - - match: '(?=\S)' - pop: true + - include: else-pop - include: method-declaration - match: "(?=\"|')" push: - meta_scope: meta.object-literal.key.js - include: literal-string - - match: '(?=.|\n)' - pop: true + - include: else-pop - match: '(\$)[$\w]*(?=\s*:)' scope: meta.object-literal.key.dollar.js captures: @@ -1165,8 +1162,6 @@ contexts: push: - meta_scope: meta.object-literal.key.js - include: literal-number - # - match: '' - # pop: true - match: ':' scope: punctuation.separator.key-value.js push: @@ -1261,11 +1256,7 @@ contexts: - match: '(?=\S)' pop: true - brackets: - - include: round-brackets - - include: square-brackets - - round-brackets: + parenthesized-expression: - match: \( scope: punctuation.section.group.js set: @@ -1290,7 +1281,7 @@ contexts: - match: (?=\S) push: expression - square-brackets: + array-literal: - match: '\[' scope: punctuation.section.brackets.js set: @@ -1430,10 +1421,6 @@ contexts: literal-variable: - match: '(?={{identifier}})' set: - # Once we've consumed an identifier, switch to the special context that - # property handles ambiguous tokens including "/" - - match: '(?!{{identifier}})' - pop: true - include: well-known-identifiers - include: language-identifiers - include: dollar-identifiers @@ -1443,6 +1430,7 @@ contexts: - match: '{{identifier}}(?=\s*[\[.])' scope: variable.other.object.js - include: simple-identifiers + - include: else-pop well-known-identifiers: - match: \b(Array|Boolean|Date|Function|Map|Math|Number|Object|Promise|Proxy|RegExp|Set|String|WeakMap|XMLHttpRequest)\b From b18022f1b37700b07e67d0bb85b0db9d1a412782 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 14:34:44 -0400 Subject: [PATCH 15/46] Scope arrays as meta.sequence per #790. Fixes #324. --- JavaScript/JavaScript.sublime-syntax | 12 +++++++++--- JavaScript/syntax_test_js.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 2ecb708652..5419296a82 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -470,6 +470,13 @@ contexts: - match: (?=\S) set: [ expression-end-no-comma, expression-begin ] + expression-list: + - include: expression-break + - match: ',' + scope: punctuation.separator.comma.js + - match: (?=\S) + push: expression-no-comma + expression-end: - include: expression-break @@ -1285,12 +1292,11 @@ contexts: - match: '\[' scope: punctuation.section.brackets.js set: - - meta_scope: meta.brackets.js + - meta_scope: meta.sequence.js - match: '\]' scope: punctuation.section.brackets.js pop: true - - match: (?=\S) - push: expression + - include: expression-list bracketed-property-access: - match: '\[' diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index c9fbf07174..26fd7df0a8 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -384,6 +384,21 @@ var obj = { // ^ constant.numeric }); +[ a, b, c ]; +// <- meta.sequence punctuation.section.brackets +// ^ meta.sequence punctuation.separator.comma +// ^^^^^^^^ meta.sequence +// ^ meta.sequence punctuation.section.brackets + +function x() {} +[ a, b, c ]; +// <- meta.sequence.js + ++ +function x() {} +[ a, b, c ]; +// <- meta.brackets.js + var $ = function(baz) { // ^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous // ^ variable.other.dollar.only punctuation.dollar entity.name.function From 35bd19bcf1bad486a04e9af5c6d3fdbe38dcc293 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 14:56:25 -0400 Subject: [PATCH 16/46] Improved line continuation lookahead. --- JavaScript/JavaScript.sublime-syntax | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 5419296a82..e806fd0853 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -16,10 +16,11 @@ variables: arrow_func_lookahead: '\s*(\basync\s*)?([_$[:alpha:]][_$[:alnum:]]*|\(([^()]|\([^()]*\))*\))\s*=>' line_continuation_lookahead: >- - (?x) (?= - \+\+ | - \+= | - [-+*/><&|^\[(] + (?x) + (?! \+\+ | -- ) + (?= + != | + [ -+*/% ><= &|^ \[( ;,.:? ] ) contexts: From a993ab8cca1d4e5cbc58dfff2bfc9064f7c61d4d Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 22:38:33 -0400 Subject: [PATCH 17/46] Cleanup in object literal. --- JavaScript/JavaScript.sublime-syntax | 176 ++++++++++----------------- 1 file changed, 67 insertions(+), 109 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 5ecebd9d35..f1988719e9 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -15,6 +15,13 @@ variables: func_lookahead: '\s*\b(async\s+)?function\b' arrow_func_lookahead: '\s*(\basync\s*)?([_$[:alpha:]][_$[:alnum:]]*|\(([^()]|\([^()]*\))*\))\s*=>' + method_name: >- + (?x)(?: + {{identifier}} + | '(?:[^\\']|\\.)*' + | "(?:[^\\"]|\\.)*" + ) + line_continuation_lookahead: >- (?x) (?! \+\+ | -- ) @@ -67,6 +74,10 @@ contexts: - match: (?=\S) pop: true + comma-separator: + - match: ',' + scope: punctuation.separator.comma.js + keywords-top-level: - match: \bimport\b scope: meta.import.js keyword.control.import-export.js @@ -473,8 +484,7 @@ contexts: expression-list: - include: expression-break - - match: ',' - scope: punctuation.separator.comma.js + - include: comma-separator - match: (?=\S) push: expression-no-comma @@ -1084,8 +1094,7 @@ contexts: - match: '\}' scope: punctuation.section.block.js pop: true - - match: ',' - scope: punctuation.separator.comma.js + - include: comma-separator - match: \[ scope: punctuation.section.brackets.js push: @@ -1094,59 +1103,16 @@ contexts: pop: true - match: (?=\S) push: expression - - match: '({{identifier}})\s*(\})' - captures: - 1: variable.other.readwrite.js - 2: punctuation.section.block.js - pop: true - - match: '({{identifier}})\s*(,)' - captures: - 1: variable.other.readwrite.js - 2: punctuation.separator.comma.js - - match: '({{identifier}})[ \t]*($\n?|(?=//|/\*))' - captures: - 1: variable.other.readwrite.js - - match: '((\$)[$\w]*)\s*(:)\s*(?=({{func_lookahead}}|{{arrow_func_lookahead}}))' - scope: meta.function.declaration.js - captures: - 1: meta.object-literal.key.dollar.js entity.name.function.js - 2: punctuation.dollar.js - 3: punctuation.separator.key-value.js - push: - - meta_scope: TEST - - match: ':' - scope: meta.function.declaration.js punctuation.separator.key-value.js - set: expression-no-comma - - include: else-pop - - match: "(?=('.*'|\".*\"|{{identifier}})\\s*:({{func_lookahead}}|{{arrow_func_lookahead}}))" + - match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))' + scope: variable.other.readwrite.js + - match: >- + (?x)(?= + {{method_name}}\s*: + (?: {{func_lookahead}} | {{arrow_func_lookahead}} ) + ) push: - meta_content_scope: meta.object-literal.key.js meta.function.declaration.js - - match: "'" - scope: punctuation.definition.string.begin.js - push: - - meta_include_prototype: false - - meta_scope: string.quoted.single.js - - meta_content_scope: entity.name.function.js - - match: (')|(\n) - captures: - 1: punctuation.definition.string.end.js - 2: invalid.illegal.newline.js - pop: true - - include: string-content - - match: '"' - scope: punctuation.definition.string.begin.js - push: - - meta_include_prototype: false - - meta_scope: string.quoted.double.js - - meta_content_scope: entity.name.function.js - - match: (")|(\n) - captures: - 1: punctuation.definition.string.end.js - 2: invalid.illegal.newline.js - pop: true - - include: string-content - - match: '{{identifier}}' - scope: entity.name.function.js + - include: method-name - match: '(?=:)' set: - match: '(:)\s*' @@ -1160,7 +1126,6 @@ contexts: push: - meta_scope: meta.object-literal.key.js - include: literal-string - - include: else-pop - match: '(\$)[$\w]*(?=\s*:)' scope: meta.object-literal.key.dollar.js captures: @@ -1173,12 +1138,46 @@ contexts: - include: literal-number - match: ':' scope: punctuation.separator.key-value.js - push: - - match: "(?=\\}|,|('[^']*'|\"[^\"]*\"|{{identifier}})\\s*:)" - pop: true - - include: expression-no-comma + push: expression-no-comma + + meta-object-literal-key: + - meta_scope: meta.object-literal.key.js + - include: else-pop + + method-name: + - match: '(\$)[_$[:alnum:]]*' + scope: meta.object-literal.key.dollar.js entity.name.function.js + captures: + 1: punctuation.dollar.js + - match: '{{identifier}}' + scope: entity.name.function.js + - match: "'" + scope: punctuation.definition.string.begin.js + push: + - meta_include_prototype: false + - meta_scope: string.quoted.single.js + - meta_content_scope: entity.name.function.js + - match: (')|(\n) + captures: + 1: punctuation.definition.string.end.js + 2: invalid.illegal.newline.js + pop: true + - include: string-content + - match: '"' + scope: punctuation.definition.string.begin.js + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.js + - meta_content_scope: entity.name.function.js + - match: (")|(\n) + captures: + 1: punctuation.definition.string.end.js + 2: invalid.illegal.newline.js + pop: true + - include: string-content method-declaration: + - meta_scope: meta.function.declaration.js - match: \b(get|set)\b(?!\s*\()\s* scope: meta.function.declaration.js captures: @@ -1207,63 +1206,22 @@ contexts: scope: punctuation.section.block.js pop: true - include: statements - - match: '(?=\S)' - pop: true - - match: (?=('[^\\]*'|"[^\\]*")\s*\() + - include: else-pop + - match: (?={{method_name}}\s*\() push: - - meta_content_scope: meta.function.declaration.js - - match: "'" - scope: punctuation.definition.string.begin.js - push: - - meta_include_prototype: false - - meta_scope: string.quoted.single.js - - meta_content_scope: entity.name.function.js - - match: (')|(\n) - captures: - 1: punctuation.definition.string.end.js - 2: invalid.illegal.newline.js - pop: true - - include: string-content - - match: '"' - scope: punctuation.definition.string.begin.js - push: - - meta_include_prototype: false - - meta_scope: string.quoted.double.js - - meta_content_scope: entity.name.function.js - - match: (")|(\n) - captures: - 1: punctuation.definition.string.end.js - 2: invalid.illegal.newline.js - pop: true - - include: string-content + - meta_scope: meta.function.declaration.js + - include: method-name - match: \s* - include: function-declaration-parameters - match: '\{' scope: punctuation.section.block.js - push: - - meta_scope: meta.block.js - - match: '\}' - scope: punctuation.section.block.js - pop: true - - include: statements - - match: '(?=\S)' - pop: true - - match: '({{identifier}})\s*(?=\()' - scope: meta.function.declaration.js - captures: - 1: entity.name.function.js - push: - - include: function-declaration-parameters - - match: '\{' - scope: punctuation.section.block.js - push: - - meta_scope: meta.block.js + set: + - meta_scope: meta.function.declaration.js meta.block.js - match: '\}' scope: punctuation.section.block.js pop: true - include: statements - - match: '(?=\S)' - pop: true + - include: else-pop parenthesized-expression: - match: \( @@ -1551,5 +1509,5 @@ contexts: pop: true - include: object-property - match: ',' - scope: punctuation.separator.comma.js + scope: punctuation.separator.comma.js # TODO: Change to keyword.operator.comma.js ? push: expression-begin From 63655685510cf226f5187a93ff85e9caa49d4344 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 May 2017 23:00:47 -0400 Subject: [PATCH 18/46] Minor simplifications. Also, postfix decrement is scoped properly. --- JavaScript/JavaScript.sublime-syntax | 53 ++++++++++------------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index f1988719e9..9e116075c0 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -106,8 +106,7 @@ contexts: - match: '\*' scope: constant.other.js set: import-extended-as - - match: '(?=\S)' - pop: true + - include: else-pop import-extended-as: - meta_content_scope: meta.import.js @@ -125,8 +124,7 @@ contexts: - match: ',' scope: punctuation.separator.comma.js set: import-extended - - match: '(?=\S)' - pop: true + - include: else-pop import-brace: - meta_content_scope: meta.import.js meta.block.js @@ -140,8 +138,7 @@ contexts: - match: '\*' scope: constant.other.js set: import-brace-as - - match: '(?=\S)' - pop: true + - include: else-pop import-brace-as: - meta_content_scope: meta.import.js meta.block.js @@ -161,8 +158,7 @@ contexts: - match: ',' scope: punctuation.separator.comma.js set: import-brace - - match: '(?=\S)' - pop: true + - include: else-pop import-final: - meta_scope: meta.import.js @@ -170,8 +166,7 @@ contexts: scope: keyword.control.import-export.js - match: (?=['"]) push: literal-string - - match: '(?=\S)' - pop: true + - include: else-pop export-escape: - match: '(?=;|function|var|class)' @@ -201,8 +196,7 @@ contexts: - match: '\*' scope: constant.other.js set: export-extended-as - - match: '(?=\S)' - pop: true + - include: else-pop export-extended-as: - meta_content_scope: meta.export.js @@ -220,8 +214,7 @@ contexts: - match: ',' scope: punctuation.separator.comma.js set: export-extended - - match: '(?=\S)' - pop: true + - include: else-pop export-brace: - meta_content_scope: meta.export.js meta.block.js @@ -235,8 +228,7 @@ contexts: - match: '\*' scope: constant.other.js set: export-brace-as - - match: '(?=\S)' - pop: true + - include: else-pop export-brace-as: - meta_content_scope: meta.export.js meta.block.js @@ -260,8 +252,7 @@ contexts: - match: ',' scope: punctuation.separator.comma.js set: export-brace - - match: '(?=\S)' - pop: true + - include: else-pop export-final: - meta_scope: meta.export.js @@ -269,8 +260,7 @@ contexts: scope: keyword.control.import-export.js - match: (?=['"]) push: literal-string - - match: '(?=\S)' - pop: true + - include: else-pop statements: - match: \; @@ -467,8 +457,7 @@ contexts: - match: '(?=\})' pop: true - include: statements - - match: '(?=\S)' - pop: true + - include: else-pop expression-break: - match: (?=[;})\]]) @@ -540,7 +529,7 @@ contexts: fallthrough: # If an arrow function has the ( and ) on different lines, we won't have matched - match: => - scope: storage.type.function.arrow.js FALLTHROUGH + scope: storage.type.function.arrow.js literal-string: - match: "'" @@ -633,16 +622,14 @@ contexts: push: function-declaration - match: '(?=\()' set: constructor-params - - match: '(?=\S)' - pop: true + - include: else-pop - match: '(?=class\b)' set: - meta_scope: meta.instance.constructor.js - include: class - match: '(?=\()' set: constructor-params - - match: '(?=\S)' - pop: true + - include: else-pop - match: '(?={{identifier}})' set: - meta_scope: meta.instance.constructor.js meta.function-call.constructor.js @@ -672,8 +659,7 @@ contexts: set: constructor-params - match: (?=\S) push: expression - - match: '(?=\S)' - pop: true + - include: else-pop constructor-params: - meta_content_scope: meta.instance.constructor.js @@ -681,8 +667,7 @@ contexts: push: - meta_scope: meta.function-call.constructor.js - include: function-call-params - - match: '(?=\S)' - pop: true + - include: else-pop prefix-operators: - match: '~' @@ -774,6 +759,7 @@ contexts: - match: '--' scope: keyword.operator.arithmetic.js - match: '\+\+' + scope: keyword.operator.arithmetic.js class: - match: \bclass\b @@ -791,8 +777,7 @@ contexts: scope: entity.other.inherited-class.js - match: '\.' scope: punctuation.accessor.js - - match: '(?=\S)' - pop: true + - include: else-pop - match: '{{identifier}}' scope: entity.name.class.js @@ -1081,7 +1066,7 @@ contexts: push: expression-no-comma label: - - match: '^\s*((?!default){{identifier}})\s*(:)' + - match: '({{identifier}})\s*(:)' captures: 1: entity.name.label.js 2: punctuation.separator.js From 2bcf9e08a194fab35551a99b4ab0fd533043ffab Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sat, 10 Jun 2017 19:07:24 -0400 Subject: [PATCH 19/46] Fixed variable names to pop correctly. Then fixed constructor stuff because the change broke it. --- JavaScript/JavaScript.sublime-syntax | 122 +++++++++++++++------------ 1 file changed, 69 insertions(+), 53 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 831efbc396..e844ed6f73 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -608,57 +608,56 @@ contexts: - include: scope:source.regexp.js constructor: - - match: '\b(new)\b\s+(?=({{identifier}}|\())' - scope: meta.instance.constructor.js - captures: - 1: keyword.operator.word.new.js - set: constructor-name + - match: '\bnew\b' + scope: keyword.operator.word.new.js + set: + - meta-constructor + - constructor-name + + meta-constructor: + - meta_scope: meta.instance.constructor.js + - include: else-pop constructor-name: - match: '(?=function\b)' set: - - meta_scope: meta.instance.constructor.js - - match: '(?=function\b)' - push: function-declaration - - match: '(?=\()' - set: constructor-params - - include: else-pop + - constructor-params + - function-declaration - match: '(?=class\b)' set: - - meta_scope: meta.instance.constructor.js - - include: class - - match: '(?=\()' - set: constructor-params - - include: else-pop + - constructor-params + - class - match: '(?={{identifier}})' set: - - meta_scope: meta.instance.constructor.js meta.function-call.constructor.js - - include: well-known-identifiers - - include: language-identifiers - - match: '{{dollar_only_identifier}}' - scope: variable.type.dollar.only.js punctuation.dollar.js - - match: '{{dollar_identifier}}' - scope: variable.type.dollar.js - captures: - 1: punctuation.dollar.js - - match: '{{identifier}}' - scope: variable.type.js - - match: '\.' - scope: punctuation.accessor.js - - include: bracketed-property-access - - match: '(?=\()' - set: constructor-params - - match: '(?=\S|$)' - pop: true + - - meta_scope: meta.function-call.constructor.js + - include: else-pop + - constructor-params + - - include: well-known-identifiers + - include: language-identifiers + - match: '{{dollar_only_identifier}}' + scope: variable.type.dollar.only.js punctuation.dollar.js + - match: '{{dollar_identifier}}' + scope: variable.type.dollar.js + captures: + 1: punctuation.dollar.js + - match: '{{identifier}}' + scope: variable.type.js + - match: '\.' + scope: punctuation.accessor.js + - include: bracketed-property-access + - match: '(?=\S|$)' + pop: true - match: '\(' scope: punctuation.section.group.js set: - - meta_scope: meta.instance.constructor.js meta.function-call.constructor.js meta.group.js - - match: '\)' - scope: punctuation.section.group.js - set: constructor-params - - match: (?=\S) - push: expression + - - meta_scope: meta.function-call.constructor.js + - include: else-pop + - constructor-params + - - meta_scope: meta.group.js + - match: '\)' + scope: punctuation.section.group.js + pop: true + - expression - include: else-pop constructor-params: @@ -1371,56 +1370,68 @@ contexts: push: expression-no-comma literal-variable: - - match: '(?={{identifier}})' - set: - - include: well-known-identifiers - - include: language-identifiers - - include: dollar-identifiers - - include: support - - match: '\b[[:upper:]][_$[:alnum:]]*(?=\s*[\[.])' - scope: support.class.js - - match: '{{identifier}}(?=\s*[\[.])' - scope: variable.other.object.js - - include: simple-identifiers - - include: else-pop + - include: well-known-identifiers + - include: language-identifiers + - include: dollar-identifiers + - include: support + - match: '\b[[:upper:]][_$[:alnum:]]*(?=\s*[\[.])' + scope: support.class.js + pop: true + - match: '{{identifier}}(?=\s*[\[.])' + scope: variable.other.object.js + pop: true + - include: simple-identifiers well-known-identifiers: - match: \b(Array|Boolean|Date|Function|Map|Math|Number|Object|Promise|Proxy|RegExp|Set|String|WeakMap|XMLHttpRequest)\b scope: support.class.builtin.js + pop: true - match: \b((Eval|Range|Reference|Syntax|Type|URI)?Error)\b scope: support.class.error.js + pop: true - match: \b(document|window|navigator)\b scope: support.type.object.dom.js + pop: true - match: \b(Buffer|EventEmitter|Server|Pipe|Socket|REPLServer|ReadStream|WriteStream|Stream|Inflate|Deflate|InflateRaw|DeflateRaw|GZip|GUnzip|Unzip|Zip)\b scope: support.class.node.js + pop: true language-identifiers: - match: \b(arguments)\b scope: variable.language.arguments.js + pop: true - match: \b(super)\b scope: variable.language.super.js + pop: true - match: \b(this)\b scope: variable.language.this.js + pop: true - match: \b(self)\b scope: variable.language.self.js + pop: true dollar-identifiers: - match: '{{dollar_only_identifier}}' scope: variable.other.dollar.only.js punctuation.dollar.js + pop: true - match: '{{dollar_identifier}}' scope: variable.other.dollar.js captures: 1: punctuation.dollar.js + pop: true simple-identifiers: - match: '{{constant_identifier}}' scope: variable.other.constant.js + pop: true - match: '{{identifier}}' scope: variable.other.readwrite.js + pop: true support: - match: \bdebugger\b scope: keyword.other.js + pop: true - match: |- (?x) \b( @@ -1429,20 +1440,25 @@ contexts: WRONG_DOCUMENT_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR|NOT_SUPPORTED_ERR|INUSE_ATTRIBUTE_ERR )\b scope: support.constant.dom.js + pop: true - match: \b(assert|buffer|child_process|cluster|constants|crypto|dgram|dns|domain|events|fs|http|https|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|timers|tls|tty|url|util|vm|zlib)\b scope: support.module.node.js + pop: true - match: \b(process)(?:(\.)(arch|argv|config|connected|env|execArgv|execPath|exitCode|mainModule|pid|platform|release|stderr|stdin|stdout|title|version|versions))?\b captures: 1: support.type.object.process.js 2: punctuation.accessor.js 3: support.type.object.process.js - - match: \b(exports|module(?:(\.)(exports|id|filename|loaded|parent|children)))?\b + pop: true + - match: \b(exports|module(?:(\.)(exports|id|filename|loaded|parent|children))?)\b captures: 1: support.type.object.module.js 2: punctuation.accessor.js 3: support.type.object.module.js + pop: true - match: \b(global|GLOBAL|root|__dirname|__filename)\b scope: support.type.object.node.js + pop: true object-property: - match: \b__proto__\b From 2bc6eb4ed0c3be1ccc23daa42fd0fcbe5408f6b1 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 11 Jun 2017 15:16:07 -0400 Subject: [PATCH 20/46] Fixed and unified import/export aliases. --- JavaScript/JavaScript.sublime-syntax | 93 ++++++++++++---------------- JavaScript/syntax_test_js.js | 20 ++++++ 2 files changed, 60 insertions(+), 53 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index e844ed6f73..46818a32e9 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -89,6 +89,19 @@ contexts: - match: \b(export|default|from|as)\b scope: keyword.control.import-export.js + import-export-alias: + - match: \bas\b + scope: keyword.control.import-export.js + set: + - match: \bdefault\b + scope: keyword.control.import-export.js + pop: true + - match: '{{identifier}}' + scope: variable.other.readwrite.js + pop: true + - include: else-pop + - include: else-pop + import-escape: - match: '(?=;|function|var|class)' pop: true @@ -103,22 +116,16 @@ contexts: set: import-brace - match: '{{identifier}}' scope: variable.other.readwrite.js - set: import-extended-as + push: + - import-extended-continue + - import-export-alias - match: '\*' scope: constant.other.js - set: import-extended-as + push: + - import-extended-continue + - import-export-alias - include: else-pop - import-extended-as: - - meta_content_scope: meta.import.js - - include: import-escape - - match: '\b(as)(?:\s+({{identifier}}))?' - captures: - 1: keyword.control.import-export.js - 2: variable.other.readwrite.js - - match: '(?=\S)' - set: import-extended-continue - import-extended-continue: - meta_scope: meta.import.js - include: import-escape @@ -132,25 +139,21 @@ contexts: - include: import-escape - match: '\}' scope: punctuation.section.block.js - set: import-extended-as + push: + - import-extended-continue + - import-export-alias - match: '{{identifier}}' scope: variable.other.readwrite.js - set: import-brace-as + push: + - import-brace-continue + - import-export-alias - match: '\*' scope: constant.other.js - set: import-brace-as + push: + - import-brace-continue + - import-export-alias - include: else-pop - import-brace-as: - - meta_content_scope: meta.import.js meta.block.js - - include: import-escape - - match: '\b(as)\b(\s+(?:{{identifier}}))?' - captures: - 1: keyword.control.import-export.js - 2: variable.other.readwrite.js - - match: '(?=\S)' - set: import-brace-continue - import-brace-continue: - meta_scope: meta.import.js meta.block.js - include: import-escape @@ -195,19 +198,11 @@ contexts: set: export-brace - match: '\*' scope: constant.other.js - set: export-extended-as + push: + - export-extended-continue + - import-export-alias - include: else-pop - export-extended-as: - - meta_content_scope: meta.export.js - - include: export-escape - - match: '\b(as)(?:\s+({{identifier}}))?' - captures: - 1: keyword.control.import-export.js - 2: variable.other.readwrite.js - - match: '(?=\S)' - set: export-extended-continue - export-extended-continue: - meta_scope: meta.export.js - include: export-escape @@ -221,29 +216,21 @@ contexts: - include: export-escape - match: '\}' scope: punctuation.section.block.js - set: export-extended-as + push: + - export-extended-continue + - import-export-alias - match: '{{identifier}}' scope: variable.other.readwrite.js - set: export-brace-as + push: + - export-brace-continue + - import-export-alias - match: '\*' scope: constant.other.js - set: export-brace-as + push: + - export-brace-continue + - import-export-alias - include: else-pop - export-brace-as: - - meta_content_scope: meta.export.js meta.block.js - - include: export-escape - - match: \b(as)\s+(default)\b - captures: - 1: keyword.control.import-export.js - 2: keyword.control.import-export.js - - match: '\b(as)\b(\s+(?:{{identifier}}))?' - captures: - 1: keyword.control.import-export.js - 2: variable.other.readwrite.js - - match: '(?=\S)' - set: export-brace-continue - export-brace-continue: - meta_scope: meta.export.js meta.block.js - include: export-escape diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index b1e57bf29c..f6f42e2962 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -91,6 +91,26 @@ export { import1 as name1, import2 as name2, nameN } from "./othermod"; // ^ keyword.control.import-export // ^ keyword.control.import-export +import * as + alias from "module"; +// ^^^^^^^^^^^^^^^^^^^^ meta.import.js + +import { member as + alias } from "module"; +// ^^^^^^^^^^^^^^^^^^^^^^ meta.import.js + +import { * as + alias } from "module"; +// ^^^^^^^^^^^^^^^^^^^^^^ meta.import.js + +export { member as + alias } from "module"; +// ^^^^^^^^^^^^^^^^^^^^^^ meta.export.js + +export { member as + default } from "module"; +// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.export.js + // This object literal is technically broken since foo() does not have a // method body, but we include it here to ensure that highlighting is not // broken as the user is typing From 477c785087d41e2641260589a76a6bcf5c964f3a Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 11 Jun 2017 15:28:17 -0400 Subject: [PATCH 21/46] Removed various *-continue scopes that aren't needed with the new architecture. --- JavaScript/JavaScript.sublime-syntax | 72 +++++----------------------- 1 file changed, 13 insertions(+), 59 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 46818a32e9..49b3fe3c1b 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -111,57 +111,33 @@ contexts: import-extended: - meta_content_scope: meta.import.js - include: import-escape + - include: comma-separator - match: '\{' scope: meta.block.js punctuation.section.block.js set: import-brace - match: '{{identifier}}' scope: variable.other.readwrite.js - push: - - import-extended-continue - - import-export-alias + push: import-export-alias - match: '\*' scope: constant.other.js - push: - - import-extended-continue - - import-export-alias - - include: else-pop - - import-extended-continue: - - meta_scope: meta.import.js - - include: import-escape - - match: ',' - scope: punctuation.separator.comma.js - set: import-extended + push: import-export-alias - include: else-pop import-brace: - meta_content_scope: meta.import.js meta.block.js - include: import-escape + - include: comma-separator - match: '\}' scope: punctuation.section.block.js push: - - import-extended-continue + - import-extended - import-export-alias - match: '{{identifier}}' scope: variable.other.readwrite.js - push: - - import-brace-continue - - import-export-alias + push: import-export-alias - match: '\*' scope: constant.other.js - push: - - import-brace-continue - - import-export-alias - - include: else-pop - - import-brace-continue: - - meta_scope: meta.import.js meta.block.js - - include: import-escape - - match: '(?=\})' - set: import-brace - - match: ',' - scope: punctuation.separator.comma.js - set: import-brace + push: import-export-alias - include: else-pop import-final: @@ -183,6 +159,7 @@ contexts: - include: variable-declaration - include: export-escape + - include: comma-separator - match: '\bdefault\b' scope: keyword.control.import-export.js push: @@ -198,47 +175,24 @@ contexts: set: export-brace - match: '\*' scope: constant.other.js - push: - - export-extended-continue - - import-export-alias - - include: else-pop - - export-extended-continue: - - meta_scope: meta.export.js - - include: export-escape - - match: ',' - scope: punctuation.separator.comma.js - set: export-extended + push: import-export-alias - include: else-pop export-brace: - meta_content_scope: meta.export.js meta.block.js - include: export-escape + - include: comma-separator - match: '\}' scope: punctuation.section.block.js push: - - export-extended-continue + - export-extended - import-export-alias - match: '{{identifier}}' scope: variable.other.readwrite.js - push: - - export-brace-continue - - import-export-alias + push: import-export-alias - match: '\*' scope: constant.other.js - push: - - export-brace-continue - - import-export-alias - - include: else-pop - - export-brace-continue: - - meta_scope: meta.export.js meta.block.js - - include: export-escape - - match: '(?=\})' - set: export-brace - - match: ',' - scope: punctuation.separator.comma.js - set: export-brace + push: import-export-alias - include: else-pop export-final: From a4f18e911fe8d4ddfa9a571156d080e40819322d Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 11 Jun 2017 15:39:38 -0400 Subject: [PATCH 22/46] Import/export braces now use the stack for simplicity. --- JavaScript/JavaScript.sublime-syntax | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 49b3fe3c1b..17f57eaf96 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -113,8 +113,10 @@ contexts: - include: import-escape - include: comma-separator - match: '\{' - scope: meta.block.js punctuation.section.block.js - set: import-brace + scope: punctuation.section.block.js + push: + - import-export-alias + - import-brace - match: '{{identifier}}' scope: variable.other.readwrite.js push: import-export-alias @@ -124,14 +126,12 @@ contexts: - include: else-pop import-brace: - - meta_content_scope: meta.import.js meta.block.js + - meta_scope: meta.block.js - include: import-escape - include: comma-separator - match: '\}' scope: punctuation.section.block.js - push: - - import-extended - - import-export-alias + pop: true - match: '{{identifier}}' scope: variable.other.readwrite.js push: import-export-alias @@ -172,21 +172,19 @@ contexts: - include: expression - match: '\{' scope: meta.block.js punctuation.section.block.js - set: export-brace + push: export-brace - match: '\*' scope: constant.other.js push: import-export-alias - include: else-pop export-brace: - - meta_content_scope: meta.export.js meta.block.js + - meta_scope: meta.block.js - include: export-escape - include: comma-separator - match: '\}' scope: punctuation.section.block.js - push: - - export-extended - - import-export-alias + pop: true - match: '{{identifier}}' scope: variable.other.readwrite.js push: import-export-alias From 512491f0925a2a89f0bfa0f369e2cae57391ac41 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 11 Jun 2017 15:49:18 -0400 Subject: [PATCH 23/46] Replaced the rest of the sets with pushes and pops. Consolidated more duplicate logic. --- JavaScript/JavaScript.sublime-syntax | 50 +++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 17f57eaf96..a4b46a66c2 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -81,14 +81,26 @@ contexts: keywords-top-level: - match: \bimport\b - scope: meta.import.js keyword.control.import-export.js - push: import-extended + scope: keyword.control.import-export.js + push: + - import-meta + - import-export-final + - import-extended + - match: \bexport\b - scope: meta.export.js keyword.control.import-export.js - push: export-extended + scope: keyword.control.import-export.js + push: + - export-meta + - import-export-final + - export-extended + - match: \b(export|default|from|as)\b scope: keyword.control.import-export.js + import-meta: + - meta_scope: meta.import.js + - include: else-pop + import-export-alias: - match: \bas\b scope: keyword.control.import-export.js @@ -102,14 +114,20 @@ contexts: - include: else-pop - include: else-pop + import-export-final: + - match: '\bfrom\b' + scope: keyword.control.import-export.js + - match: (?=['"]) + push: literal-string + - include: else-pop + import-escape: - match: '(?=;|function|var|class)' pop: true - match: "(?='|\"|\\bfrom\\b)" - set: import-final + pop: true import-extended: - - meta_content_scope: meta.import.js - include: import-escape - include: comma-separator - match: '\{' @@ -140,23 +158,17 @@ contexts: push: import-export-alias - include: else-pop - import-final: - - meta_scope: meta.import.js - - match: '\bfrom\b' - scope: keyword.control.import-export.js - - match: (?=['"]) - push: literal-string + export-meta: + - meta_scope: meta.export.js - include: else-pop export-escape: - match: '(?=;|function|var|class)' pop: true - match: "(?='|\"|\\bfrom\\b)" - set: export-final + pop: true export-extended: - - meta_content_scope: meta.export.js - - include: variable-declaration - include: export-escape - include: comma-separator @@ -193,14 +205,6 @@ contexts: push: import-export-alias - include: else-pop - export-final: - - meta_scope: meta.export.js - - match: '\bfrom\b' - scope: keyword.control.import-export.js - - match: (?=['"]) - push: literal-string - - include: else-pop - statements: - match: \; scope: punctuation.terminator.statement.js From 78b6f0c3e3fb51f95e9704eeeb5842d0cf56f283 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Sun, 11 Jun 2017 16:27:38 -0400 Subject: [PATCH 24/46] Moved things around to fix #1028. --- JavaScript/JavaScript.sublime-syntax | 72 +++++++++++++++++----------- JavaScript/syntax_test_js.js | 15 ++++++ 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index a4b46a66c2..8ece1a59b0 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -91,7 +91,6 @@ contexts: scope: keyword.control.import-export.js push: - export-meta - - import-export-final - export-extended - match: \b(export|default|from|as)\b @@ -121,31 +120,37 @@ contexts: push: literal-string - include: else-pop - import-escape: - - match: '(?=;|function|var|class)' - pop: true - - match: "(?='|\"|\\bfrom\\b)" + import-extended: + - match: (?='|") pop: true + - match: (?=\S) + set: + - import-list + - import-export-alias + - import-item - import-extended: - - include: import-escape - - include: comma-separator - - match: '\{' - scope: punctuation.section.block.js + import-list: + - match: ',' + scope: punctuation.separator.comma.js push: - import-export-alias - - import-brace + - import-item + - include: else-pop + + import-item: + - match: '\{' + scope: punctuation.section.block.js + set: import-brace - match: '{{identifier}}' scope: variable.other.readwrite.js - push: import-export-alias + pop: true - match: '\*' scope: constant.other.js - push: import-export-alias + pop: true - include: else-pop import-brace: - meta_scope: meta.block.js - - include: import-escape - include: comma-separator - match: '\}' scope: punctuation.section.block.js @@ -162,19 +167,12 @@ contexts: - meta_scope: meta.export.js - include: else-pop - export-escape: - - match: '(?=;|function|var|class)' - pop: true - - match: "(?='|\"|\\bfrom\\b)" - pop: true - export-extended: - include: variable-declaration - - include: export-escape - - include: comma-separator + - match: '\bdefault\b' scope: keyword.control.import-export.js - push: + set: - match: (?=class) set: class @@ -182,17 +180,37 @@ contexts: set: function-declaration - include: expression + + - match: (?=\S) + set: + - import-export-final + - export-list + - import-export-alias + - export-item + + export-list: + - match: ',' + scope: punctuation.separator.comma.js + push: + - import-export-alias + - export-item + - include: else-pop + + export-item: - match: '\{' - scope: meta.block.js punctuation.section.block.js - push: export-brace + scope: punctuation.section.block.js + set: + - export-brace + - match: '{{identifier}}' + scope: variable.other.readwrite.js + pop: true - match: '\*' scope: constant.other.js - push: import-export-alias + pop: true - include: else-pop export-brace: - meta_scope: meta.block.js - - include: export-escape - include: comma-separator - match: '\}' scope: punctuation.section.block.js diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index f6f42e2962..62e29eb79e 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -111,6 +111,21 @@ export { member as default } from "module"; // ^^^^^^^^^^^^^^^^^^^^^^^^ meta.export.js +let from; +// ^^^^ variable.other.readwrite.js + +import from from "./othermod"; +// ^^^^ variable.other.readwrite.js + +import { from } from "./othermod"; +// ^^^^ variable.other.readwrite.js + +export from from "./othermod"; +// ^^^^ variable.other.readwrite.js + +export { from } from "./othermod"; +// ^^^^ variable.other.readwrite.js + // This object literal is technically broken since foo() does not have a // method body, but we include it here to ensure that highlighting is not // broken as the user is typing From 3de201f94eb7d430debfa70687bbaac8f1ee36f5 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 21 Jun 2017 20:24:32 -0400 Subject: [PATCH 25/46] Fixed bug with case statement. --- JavaScript/JavaScript.sublime-syntax | 34 ++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index e844ed6f73..96cf23487a 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -331,6 +331,12 @@ contexts: - match: (?=\S) set: expression-statement + expect-case-colon: + - match: ':' + scope: punctuation.separator.js + pop: true + - include: else-pop + conditional: - match: \bswitch\b scope: keyword.control.switch.js @@ -345,15 +351,21 @@ contexts: scope: punctuation.section.block.js push: - meta_scope: meta.block.js + - match: '(?=\})' pop: true - - match: ':' + + - match: \b(case)\b + scope: keyword.control.switch.js push: - - match: '(?=(\bcase\b|\bdefault\b|\}))' - pop: true - - include: statements - - match: \b(case|default)\b + - expect-case-colon + - expression + + - match: \b(default)\b scope: keyword.control.switch.js + push: + - expect-case-colon + - include: statements - match: \bdo\b @@ -482,6 +494,7 @@ contexts: - include: postfix-operators - include: binary-operators + - include: ternary-operator - include: bracketed-property-access - include: function-call @@ -750,9 +763,16 @@ contexts: - # subtraction left-to-right both scope: keyword.operator.arithmetic.js push: expression-begin - - match: '\?|:' + + ternary-operator: + - match: '\?' scope: keyword.operator.ternary.js - push: expression-begin + set: + - - match: ':' + scope: keyword.operator.ternary.js + set: expression + - include: else-pop + - expression postfix-operators: - match: '--' From c91a31df3cb6c4efa8ecc4db8eb7f5339936248f Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 28 Jun 2017 13:13:06 -0400 Subject: [PATCH 26/46] Fixed bug with for statement. --- JavaScript/JavaScript.sublime-syntax | 12 ++++++------ JavaScript/syntax_test_js.js | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 96cf23487a..8241b190d7 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -454,19 +454,19 @@ contexts: - match: ; scope: punctuation.terminator.statement.js - - match: (?=\S) - push: expression + - match: \b(const|let|var)\b + scope: storage.type.js + + - include: expression-list - include: block-scope block-scope: - - match: '\}' - scope: meta.block.js punctuation.section.block.js - pop: true - match: '\{' scope: punctuation.section.block.js push: - meta_scope: meta.block.js - - match: '(?=\})' + - match: '\}' + scope: punctuation.section.block.js pop: true - include: statements - include: else-pop diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index b1e57bf29c..03097ed209 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -446,6 +446,7 @@ do { for (var i = 0; i < 10; i++) { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.for // ^^^^^^^^^^^^^^^^^^^^^^ meta.group +// ^^^ storage.type.js // ^ meta.block i += 1; // ^^^^^^^ meta.for meta.block From 2c43becc3275e4983233fc607e6826420bba117a Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 5 Jul 2017 17:24:45 -0400 Subject: [PATCH 27/46] Fixed import meta scope issue. --- JavaScript/JavaScript.sublime-syntax | 8 ++++++-- JavaScript/syntax_test_js.js | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index f413155acd..648cb7ef1c 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -75,6 +75,10 @@ contexts: - match: (?=\S) pop: true + immediately-pop: + - match: '' + pop: true + comma-separator: - match: ',' scope: punctuation.separator.comma.js @@ -98,7 +102,7 @@ contexts: import-meta: - meta_scope: meta.import.js - - include: else-pop + - include: immediately-pop import-export-alias: - match: \bas\b @@ -165,7 +169,7 @@ contexts: export-meta: - meta_scope: meta.export.js - - include: else-pop + - include: immediately-pop export-extended: - include: variable-declaration diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index e85a20e2bc..7c6f6ec9c9 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -56,6 +56,7 @@ export default function (a) { } //^ keyword.control.import-export // ^ keyword.control.import-export // ^ storage.type +// ^ - meta.export export default function name1(b) { } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.export @@ -233,6 +234,9 @@ not_a_comment; '// /* not a comment'() {}, // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} + '// /* not a comment'() {}, +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} + "// /* not a comment"() {}, // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} }); From b6946fa105404143b4365bd1e24d25910105561d Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 5 Jul 2017 17:30:55 -0400 Subject: [PATCH 28/46] Fixed doubled function meta scopes in parameter lists. --- JavaScript/JavaScript.sublime-syntax | 17 ++++++----------- JavaScript/syntax_test_js.js | 1 + 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 648cb7ef1c..be59b94e11 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -851,11 +851,11 @@ contexts: anonymous-function: - match: '(?={{func_lookahead}})' set: - - meta_content_scope: meta.function.anonymous.js + - meta_scope: meta.function.anonymous.js meta.function.declaration.js - include: function-declaration - match: '(?={{arrow_func_lookahead}})' set: - - meta_content_scope: meta.function.anonymous.js + - meta_scope: meta.function.anonymous.js meta.function.declaration.js - include: arrow-function-declaration function-declaration-identifiers: @@ -921,43 +921,39 @@ contexts: push: arrow-function-declaration function-declaration: + - meta_scope: meta.function.declaration.js - match: '\b(async)\b\s*' - scope: meta.function.declaration.js captures: 1: storage.type.js - match: \b(function)\b(\*)?\s* - scope: meta.function.declaration.js captures: 1: storage.type.function.js 2: keyword.generator.asterisk.js - match: '{{identifier}}' - scope: meta.function.declaration.js entity.name.function.js + scope: entity.name.function.js - include: function-declaration-parameters - match: '(?=\s*\{)' set: function-block arrow-function-declaration: + - meta_scope: meta.function.declaration.js - match: '\s*(=>)\s*(?=\n|//|/*)' - scope: meta.function.declaration.js captures: 1: storage.type.function.arrow.js set: arrow-function-declaration-continuation - match: '\s*(=>)(?=\s*\{)' - scope: meta.function.declaration.js captures: 1: storage.type.function.arrow.js set: function-block - match: '(\s*(=>))\s*(?=\S)' captures: - 1: meta.function.declaration.js 2: storage.type.function.arrow.js set: arrow-function-concise-body - match: '\b(async)\b\s*' - scope: meta.function.declaration.js captures: 1: storage.type.js - match: '{{identifier}}' - scope: meta.function.declaration.js variable.parameter.function.js + scope: variable.parameter.function.js - include: function-declaration-parameters arrow-function-declaration-continuation: @@ -1010,7 +1006,6 @@ contexts: - match: \( scope: punctuation.section.group.begin.js push: - - meta_scope: meta.function.declaration.js - match: \) scope: punctuation.section.group.end.js pop: true diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index 7c6f6ec9c9..3d9a794861 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -239,6 +239,7 @@ not_a_comment; "// /* not a comment"() {}, // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} +// ^ - meta.function.declaration meta.function.declaration }); var str = '\':'; From 6393a920de1bfbfac1d21ad87b0832c4976e6637 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 5 Jul 2017 17:34:02 -0400 Subject: [PATCH 29/46] Fixed string key scope. --- JavaScript/JavaScript.sublime-syntax | 5 +++-- JavaScript/syntax_test_js.js | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index be59b94e11..134171ae20 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1088,8 +1088,9 @@ contexts: - include: method-declaration - match: "(?=\"|')" push: - - meta_scope: meta.object-literal.key.js - - include: literal-string + - - meta_scope: meta.object-literal.key.js + - include: immediately-pop + - literal-string - match: '(\$)[$\w]*(?=\s*:)' scope: meta.object-literal.key.dollar.js captures: diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index 3d9a794861..c214941f12 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -306,12 +306,12 @@ var obj = { // <- meta.object-literal.key "key4": true, - // <- meta.object-literal.key string.quoted.double - // ^ punctuation.separator.key-value - string +// ^^^^^^ meta.object-literal.key string.quoted.double +// ^ punctuation.separator.key-value - string 'key5': false, - // <- meta.object-literal.key string.quoted.single - // ^ punctuation.separator.key-value - string - // ^^^^^ constant.language.boolean.false +// ^^^^^^meta.object-literal.key string.quoted.single +// ^ punctuation.separator.key-value - string +// ^^^^^ constant.language.boolean.false objKey: new function() { // ^^^^^^^^ storage.type.function From aaa3cc9f03df3210e5be5005e9fdfb248b65107c Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 5 Jul 2017 17:42:57 -0400 Subject: [PATCH 30/46] Fixed block scope lasting too long. --- JavaScript/JavaScript.sublime-syntax | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 134171ae20..77977049f2 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -426,12 +426,14 @@ contexts: - include: block-scope block-scope: + - match: '\}' + scope: meta.block.js punctuation.section.block.js + pop: true - match: '\{' scope: punctuation.section.block.js push: - meta_scope: meta.block.js - - match: '\}' - scope: punctuation.section.block.js + - match: (?=}) pop: true - include: statements - include: else-pop From 370aca688222b71410779201e4b7fc5b18c1ccc2 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Thu, 6 Jul 2017 16:19:25 -0400 Subject: [PATCH 31/46] Fixed some doubled scopes. --- JavaScript/JavaScript.sublime-syntax | 36 +++++++++++++--------------- JavaScript/syntax_test_js.js | 1 + 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 77977049f2..c2457a1f2f 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -641,11 +641,8 @@ contexts: - include: else-pop constructor-params: - - meta_content_scope: meta.instance.constructor.js - match: '(?=\()' - push: - - meta_scope: meta.function-call.constructor.js - - include: function-call-params + push: function-call-params - include: else-pop prefix-operators: @@ -1077,7 +1074,7 @@ contexts: (?: {{func_lookahead}} | {{arrow_func_lookahead}} ) ) push: - - meta_content_scope: meta.object-literal.key.js meta.function.declaration.js + - meta_scope: meta.object-literal.key.js meta.function.declaration.js - include: method-name - match: '(?=:)' set: @@ -1176,20 +1173,21 @@ contexts: - include: else-pop - match: (?={{method_name}}\s*\() push: - - meta_scope: meta.function.declaration.js - - include: method-name - - match: \s* - - include: function-declaration-parameters - - match: '\{' - scope: punctuation.section.block.js - set: - - meta_scope: meta.function.declaration.js meta.block.js - - - match: '\}' - scope: punctuation.section.block.js - pop: true - - include: statements - - include: else-pop + - - meta_scope: meta.function.declaration.js + - include: immediately-pop + - - include: method-name + - match: \s* + - include: function-declaration-parameters + - match: '\{' + scope: punctuation.section.block.js + set: + - meta_scope: meta.block.js + + - match: '\}' + scope: punctuation.section.block.js + pop: true + - include: statements + - include: else-pop parenthesized-expression: - match: \( diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index c214941f12..d46fa15961 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -786,6 +786,7 @@ var Constructor = function() { var abc = new ABC( // ^ meta.instance.constructor keyword.operator.word.new // ^ meta.instance.constructor meta.function-call.constructor +// ^ - meta.instance.constructor meta.instance.constructor 'my-name-is-abc', new (function () { // ^ meta.instance.constructor meta.function-call.constructor meta.instance.constructor keyword.operator.word.new From 7aeb854ea7966182f32319d3bba5db40d6fa5070 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Thu, 6 Jul 2017 16:25:48 -0400 Subject: [PATCH 32/46] Added word breaks to some lookaheads. --- JavaScript/JavaScript.sublime-syntax | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index c2457a1f2f..35ab1c274f 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -177,10 +177,10 @@ contexts: - match: '\bdefault\b' scope: keyword.control.import-export.js set: - - match: (?=class) + - match: (?=\bclass\b) set: class - - match: (?=function) + - match: (?=\bfunction\b) set: function-declaration - include: expression @@ -272,10 +272,10 @@ contexts: push: expression-statement function-or-class-declaration: - - match: (?=class) + - match: (?=\bclass\b) push: class - - match: (?=function) + - match: (?=\bfunction\b) push: named-function expression-statement: @@ -599,11 +599,11 @@ contexts: - include: else-pop constructor-name: - - match: '(?=function\b)' + - match: '(?=\bfunction\b)' set: - constructor-params - function-declaration - - match: '(?=class\b)' + - match: '(?=\bclass\b)' set: - constructor-params - class From 019869f64827c5c25507f711537bf7e5e40c468d Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Fri, 7 Jul 2017 14:04:58 -0400 Subject: [PATCH 33/46] Cleaned up object literal. --- JavaScript/JavaScript.sublime-syntax | 121 ++++++++++++++------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 35ab1c274f..5a95cb54a4 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -20,6 +20,7 @@ variables: {{identifier}} | '(?:[^\\']|\\.)*' | "(?:[^\\"]|\\.)*" + | \[ {{identifier}} (?:\.{{identifier}})* \] ) line_continuation_lookahead: >- @@ -797,15 +798,13 @@ contexts: 3: support.constant.prototype.js set: - meta_scope: meta.function.declaration.js - - match: '\s*(=)\s*' - captures: - 1: keyword.operator.assignment.js + - match: '=' + scope: keyword.operator.assignment.js - match: '(?={{func_lookahead}})' set: function-declaration - match: '(?={{arrow_func_lookahead}})' set: arrow-function-declaration - - match: '(?=.|\n)' - pop: true + - include: else-pop - match: '({{identifier}})\s*(\.)\s*(prototype)\s*(\.)\s*(?={{identifier}}\s*=\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' captures: 1: support.class.js @@ -934,6 +933,10 @@ contexts: - match: '(?=\s*\{)' set: function-block + meta-function-declaration: + - meta_scope: meta.function.declaration + - include: immediately-pop + arrow-function-declaration: - meta_scope: meta.function.declaration.js - match: '\s*(=>)\s*(?=\n|//|/*)' @@ -1057,7 +1060,28 @@ contexts: - match: '\}' scope: punctuation.section.block.js pop: true - - include: comma-separator + + - match: >- + (?x)(?= + {{method_name}}\s*: + (?: {{func_lookahead}} | {{arrow_func_lookahead}} ) + ) + push: + - - meta_scope: meta.function.declaration.js + - include: immediately-pop + - - include: either-function-declaration + - include: else-pop + - - match: ':' + scope: punctuation.separator.key-value.js + - include: else-pop + - - meta_scope: meta.object-literal.key.js + - include: else-pop + - method-name + + - include: method-declaration + + - match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))' + scope: variable.other.readwrite.js - match: \[ scope: punctuation.section.brackets.js push: @@ -1066,25 +1090,6 @@ contexts: pop: true - match: (?=\S) push: expression - - match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))' - scope: variable.other.readwrite.js - - match: >- - (?x)(?= - {{method_name}}\s*: - (?: {{func_lookahead}} | {{arrow_func_lookahead}} ) - ) - push: - - meta_scope: meta.object-literal.key.js meta.function.declaration.js - - include: method-name - - match: '(?=:)' - set: - - match: '(:)\s*' - scope: meta.function.declaration.js - captures: - 1: punctuation.separator.key-value.js - - include: either-function-declaration - - include: else-pop - - include: method-declaration - match: "(?=\"|')" push: - - meta_scope: meta.object-literal.key.js @@ -1100,6 +1105,8 @@ contexts: push: - meta_scope: meta.object-literal.key.js - include: literal-number + + - include: comma-separator - match: ':' scope: punctuation.separator.key-value.js push: expression-no-comma @@ -1117,7 +1124,7 @@ contexts: scope: entity.name.function.js - match: "'" scope: punctuation.definition.string.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.single.js - meta_content_scope: entity.name.function.js @@ -1129,7 +1136,7 @@ contexts: - include: string-content - match: '"' scope: punctuation.definition.string.begin.js - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.js - meta_content_scope: entity.name.function.js @@ -1140,55 +1147,49 @@ contexts: pop: true - include: string-content - method-declaration: - - meta_scope: meta.function.declaration.js - - match: \b(get|set)\b(?!\s*\()\s* - scope: meta.function.declaration.js - captures: - 1: storage.type.accessor.js - - match: (\*)\s* - scope: meta.function.declaration.js - captures: - 1: keyword.generator.asterisk.js - - match: \b(static)\b\s* - scope: meta.function.declaration.js - captures: - 1: storage.type.js - - match: '(\[)({{identifier}}(?:\.{{identifier}}|\.)*)?(\])?\s*(?=$|\()' - scope: meta.function.declaration.js + - match: '(\[)({{identifier}}(?:\.{{identifier}}|\.)*)?(\])?' captures: 1: punctuation.definition.symbol.begin.js 2: entity.name.function.js 3: punctuation.definition.symbol.end.js - push: - - include: function-declaration-parameters - - match: '\{' - scope: punctuation.section.block.js - push: - - meta_scope: meta.block.js - - match: '\}' - scope: punctuation.section.block.js - pop: true - - include: statements - - include: else-pop - - match: (?={{method_name}}\s*\() + pop: true + + - include: else-pop + + method-declaration: + - match: |- + (?x)(?= + \b(?: get|set|async|static )\b + | \* + | {{method_name}} \s* \( + ) push: - - meta_scope: meta.function.declaration.js - include: immediately-pop - - - include: method-name - - match: \s* - - include: function-declaration-parameters - - match: '\{' + + - - match: '\{' scope: punctuation.section.block.js set: - meta_scope: meta.block.js - - match: '\}' scope: punctuation.section.block.js pop: true - include: statements - include: else-pop + - - include: function-declaration-parameters + - include: else-pop + + - method-name + + - - match: \* + scope: keyword.generator.asterisk.js + - match: \b(get|set)\b(?!\s*\() + scope: storage.type.accessor.js + - match: \bstatic\b + scope: storage.type.js + - include: else-pop + parenthesized-expression: - match: \( scope: punctuation.section.group.js From b228687510d643764e5b229ff5a676f78ed44947 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Fri, 7 Jul 2017 15:06:15 -0400 Subject: [PATCH 34/46] Substantially simplified function internals. --- JavaScript/JavaScript.sublime-syntax | 136 +++++++++++---------------- JavaScript/syntax_test_js.js | 84 ++++++++--------- 2 files changed, 95 insertions(+), 125 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 5a95cb54a4..4c7bd677ca 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -277,7 +277,7 @@ contexts: push: class - match: (?=\bfunction\b) - push: named-function + push: function-declaration expression-statement: - match: (?=\S) @@ -494,8 +494,8 @@ contexts: - include: class - include: constants - - include: named-function - - include: anonymous-function + - include: function-assignment + - include: either-function-declaration - include: object-literal - include: parenthesized-expression @@ -826,7 +826,7 @@ contexts: 3: support.constant.prototype.js pop: true - named-function: + function-assignment: - match: '(?=(({{identifier}})\s*(\.)\s*)+({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' set: - meta_scope: meta.function.declaration.js @@ -843,18 +843,6 @@ contexts: - match: '(?={{arrow_func_lookahead}})' set: arrow-function-declaration - include: function-declaration-single-identifier - - match: '(?={{func_lookahead}}(\s*\*)?\s+{{identifier}})' - set: function-declaration - - anonymous-function: - - match: '(?={{func_lookahead}})' - set: - - meta_scope: meta.function.anonymous.js meta.function.declaration.js - - include: function-declaration - - match: '(?={{arrow_func_lookahead}})' - set: - - meta_scope: meta.function.anonymous.js meta.function.declaration.js - - include: arrow-function-declaration function-declaration-identifiers: - match: '(?={{identifier}}\s*\.)' @@ -914,83 +902,65 @@ contexts: either-function-declaration: - match: '(?={{func_lookahead}})' - push: function-declaration + set: function-declaration - match: '(?={{arrow_func_lookahead}})' - push: arrow-function-declaration + set: arrow-function-declaration function-declaration: - - meta_scope: meta.function.declaration.js - - match: '\b(async)\b\s*' - captures: - 1: storage.type.js - - match: \b(function)\b(\*)?\s* - captures: - 1: storage.type.function.js - 2: keyword.generator.asterisk.js - - match: '{{identifier}}' - scope: entity.name.function.js - - include: function-declaration-parameters - - match: '(?=\s*\{)' - set: function-block + - match: '' + set: + - - include: immediately-pop + - function-block + - - meta_scope: meta.function.declaration.js + - include: immediately-pop + - - include: function-declaration-parameters + - include: else-pop + - - match: '{{identifier}}' + scope: entity.name.function.js + pop: true + - include: else-pop + - - match: \b(function)\b\s*(\*)? + captures: + 1: storage.type.function.js + 2: keyword.generator.asterisk.js + pop: true + - include: else-pop + - - match: '\basync\b' + scope: storage.type.js + pop: true + - include: else-pop meta-function-declaration: - meta_scope: meta.function.declaration - include: immediately-pop arrow-function-declaration: - - meta_scope: meta.function.declaration.js - - match: '\s*(=>)\s*(?=\n|//|/*)' - captures: - 1: storage.type.function.arrow.js - set: arrow-function-declaration-continuation - - match: '\s*(=>)(?=\s*\{)' - captures: - 1: storage.type.function.arrow.js - set: function-block - - match: '(\s*(=>))\s*(?=\S)' - captures: - 2: storage.type.function.arrow.js - set: arrow-function-concise-body - - match: '\b(async)\b\s*' - captures: - 1: storage.type.js - - match: '{{identifier}}' - scope: variable.parameter.function.js - - include: function-declaration-parameters - - arrow-function-declaration-continuation: - - meta_content_scope: meta.function.declaration.js - - match: '(?=\{)' - set: function-block - - match: '(?=\S)' - set: arrow-function-concise-body - - arrow-function-concise-body: - - meta_content_scope: meta.block.js - - match: '(?=[);}\],])' - pop: true - - match: '\n' - set: arrow-function-concise-continuation - # This custom comment match is required so that we move to the - # arrow-function-concise-continuation context to try and continue the - # body. Previously we didn't match the \n in the comments context, but that - # caused completions to appear at the end of a single-line comment. - - match: // - scope: punctuation.definition.comment.js + - match: '' set: - - meta_scope: comment.line.double-slash.js - - match: \n - set: arrow-function-concise-continuation - - match: (?=\S) - push: expression-no-comma - - arrow-function-concise-continuation: - # Allow newlines in a concise body if the next line is a continuation - # of the previous via method chaining - - match: '(?=^\s*(\.|/[/*]))' - set: arrow-function-concise-body - - match: '(?=.|\n)' - pop: true + - - meta_scope: meta.function.declaration.js + - match: (?=\{) + set: function-block + - match: (?=\S) + set: + - - meta_scope: meta.block.js + - include: immediately-pop + - - match: (?=,) + pop: true + - include: expression-statement-end + - expression-begin + - - match: '=>' + scope: storage.type.function.arrow.js + pop: true + - include: else-pop + - - match: '{{identifier}}' + scope: variable.parameter.function.js + pop: true + - include: function-declaration-parameters + - include: else-pop + - - match: '\basync\b' + scope: storage.type.js + pop: true + - include: else-pop function-block: - meta_scope: meta.block.js diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index d46fa15961..18a19a87d2 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -147,14 +147,14 @@ function foo() { // <- meta.function.declaration // <- meta.function.declaration // <- meta.function.declaration -// ^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^ meta.function.declaration // ^ storage.type.function // ^ entity.name.function } // <- meta.block var bar = function() { -// ^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^ meta.function.declaration // <- storage.type // ^ variable.other.readwrite entity.name.function // ^ storage.type.function @@ -164,7 +164,7 @@ baz = function*() // <- meta.function.declaration // <- meta.function.declaration // <- meta.function.declaration -// ^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^ meta.function.declaration // <- variable.other.readwrite entity.name.function // ^ storage.type.function // ^ keyword.generator.asterisk @@ -288,7 +288,7 @@ var obj = { // <- meta.object-literal.key.dollar punctuation.dollar // <- meta.object-literal.key.dollar - punctuation.dollar $keyFunc: function() { -// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // <- meta.object-literal.key.dollar entity.name.function punctuation.dollar // <- meta.object-literal.key.dollar entity.name.function - punctuation.dollar }, @@ -329,37 +329,37 @@ var obj = { }(), funcKey: function() { -// ^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key entity.name.function }, func2Key: function func2Key() { -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key entity.name.function }, funcKeyArrow: () => { -// ^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key entity.name.function }, "funcStringKey": function funcStringKey() -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key string.quoted.double entity.name.function { }, 'funcStringKey': function() { -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key string.quoted.single entity.name.function }, 'funcStringKeyArrow': () => { -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key string.quoted.single entity.name.function }, "func\\String2KeyArrow": (foo) => { -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ meta.object-literal.key string.quoted.double entity.name.function // ^ constant.character.escape }, @@ -368,17 +368,17 @@ var obj = { // ^^^^ constant.language.boolean.true qux() -// ^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^ meta.function.declaration // <- entity.name.function {}, 'funcStringMethod'() { -// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function }, 'funcStringMethodWithSameLineColon'() { var foo = { name: 'jeff' }; }, -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function "key (": true, @@ -391,13 +391,13 @@ var obj = { // <- meta.object-literal.key static foo(bar) { -// ^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^ meta.function.declaration // ^ storage.type // ^entity.name.function }, *baz(){ -// ^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^ meta.function.declaration // <- keyword.generator.asterisk // ^ entity.name.function } @@ -440,7 +440,7 @@ function x() {} // <- meta.brackets.js var $ = function(baz) { -// ^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ variable.other.dollar.only punctuation.dollar entity.name.function } @@ -563,7 +563,7 @@ class MyClass extends TheirClass { // ^^^^^^^ storage.modifier.extends // ^ meta.block constructor(el) -// ^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function { // ^ meta.class meta.block meta.block punctuation.section.block @@ -573,7 +573,7 @@ class MyClass extends TheirClass { // ^ meta.class meta.block meta.block punctuation.section.block get foo() -// ^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^ meta.function.declaration // <- storage.type.accessor // ^ entity.name.function { @@ -581,19 +581,19 @@ class MyClass extends TheirClass { } static foo(baz) { -// ^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^ meta.function.declaration // ^ storage.type // ^ entity.name.function } qux() -// ^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^ meta.function.declaration { } // ^ meta.class meta.block meta.block punctuation.section.block get bar () { -// ^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^ meta.function.declaration // ^ meta.class meta.block meta.block punctuation.section.block // <- storage.type.accessor // ^ entity.name.function @@ -601,7 +601,7 @@ class MyClass extends TheirClass { } baz() { return null } -// ^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^ meta.function.declaration // <- entity.name.function get() { return "foobar"; } @@ -638,7 +638,7 @@ class Foo extends React.Component { () => {} // <- meta.function.declaration punctuation.section.group // <- meta.function.declaration punctuation.section.group -//^^^ meta.function.anonymous meta.function.declaration +//^^^ meta.function.declaration // ^^ meta.block punctuation.section.block const test = ({a, b, c=()=>({active:false}) }) => {}; @@ -661,40 +661,40 @@ const test = ({a, b, c=()=>({active:false}) }) => {}; // ^^ storage.type.function.arrow MyClass.foo = function() {} -// ^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ support.class // ^ entity.name.function MyClass.foo = () => {} -// ^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^ meta.function.declaration // ^ support.class // ^ entity.name.function xhr.onload = function() {} -// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // <- support.class.js // ^ entity.name.function xhr.onload = () => {} -// ^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^ meta.function.declaration // <- support.class.js // ^ entity.name.function var simpleArrow = foo => bar; -// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function // ^ variable.parameter.function // ^ storage.type.function.arrow var Proto = () => { -// ^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function // ^ storage.type.function.arrow this._var = 1; } Proto.prototype.getVar = () => this._var; -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ support.class // ^ support.constant.prototype // ^ entity.name.function @@ -702,7 +702,7 @@ Proto.prototype.getVar = () => this._var; Class3.prototype = function() { // ^^^^^^^^^^^^^ meta.prototype.declaration -// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - meta.function.anonymous +// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ support.class // ^ support.constant.prototype } @@ -731,10 +731,10 @@ return new Promise(resolve => preferenceObject.set({value}, resolve)); // ^ meta.function-call.constructor punctuation.section.group var anotherSingle = function(){a = param => param; return param2 => param2 * a} -// ^ meta.function.declaration variable.parameter.function - meta.function.anonymous +// ^ meta.function.declaration variable.parameter.function // ^ meta.block meta.block variable.other.readwrite // ^ meta.block punctuation.terminator.statement -// ^ meta.function.anonymous meta.function.declaration variable.parameter.function +// ^ meta.function.declaration variable.parameter.function // ^ meta.block meta.block variable.other.readwrite // ^ meta.block punctuation.section.block @@ -778,7 +778,7 @@ var Constructor = function() { // ^ variable.language.this this._method = function() {} // ^ variable.language.this - // ^ entity.name.function - meta.function.anonymous + // ^ entity.name.function } // Tests to ensure the new keyword is highlighted properly even when the @@ -963,29 +963,29 @@ var re = /^\/[^/]+/ y / ((x - 1) / -2) define(['common'], function(common) { -// ^ meta.function.anonymous meta.function.declaration +// ^ meta.function.declaration var namedFunc = function() { -// ^ meta.function.declaration - meta.function.anonymous +// ^ meta.function.declaration } }); new FooBar(function(){ -// ^ meta.function.anonymous meta.function.declaration +// ^ meta.function.declaration var namedFunc2 = function() { -// ^ meta.function.declaration - meta.function.anonymous +// ^ meta.function.declaration } }) ['foo'].bar = function() { -// ^ meta.property.object entity.name.function - meta.function.anonymous +// ^ meta.property.object entity.name.function } ['foo'].$ = function() { -// ^ meta.property.object.dollar.only entity.name.function - meta.function.anonymous +// ^ meta.property.object.dollar.only entity.name.function } ['foo'].$bar = function() { -// ^ meta.property.object.dollar entity.name.function - meta.function.anonymous +// ^ meta.property.object.dollar entity.name.function } { From e00c755cdead6d60ac3752637bd60b65a3cbf331 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 11 Jul 2017 15:20:57 -0400 Subject: [PATCH 35/46] Fixed overextensive meta.block.js in function declaration. --- JavaScript/JavaScript.sublime-syntax | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 4c7bd677ca..69c7729590 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -909,8 +909,9 @@ contexts: function-declaration: - match: '' set: - - - include: immediately-pop - - function-block + - - match: (?=\S) + set: function-block + - include: else-pop - - meta_scope: meta.function.declaration.js - include: immediately-pop - - include: function-declaration-parameters From 4ea9885bd484c94cdb3b787c6f55c624b5ecd99f Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 11 Jul 2017 15:54:24 -0400 Subject: [PATCH 36/46] Fixed misordered meta scope. --- JavaScript/JavaScript.sublime-syntax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 69c7729590..7029d8c4cd 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1038,10 +1038,10 @@ contexts: (?: {{func_lookahead}} | {{arrow_func_lookahead}} ) ) push: - - - meta_scope: meta.function.declaration.js - - include: immediately-pop - - include: either-function-declaration - include: else-pop + - - meta_scope: meta.function.declaration.js + - include: immediately-pop - - match: ':' scope: punctuation.separator.key-value.js - include: else-pop From 1a74f9579e4f02661855209956770ffa5168cd82 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 11 Jul 2017 16:43:07 -0400 Subject: [PATCH 37/46] Fixed scoping for ternary operator. --- JavaScript/JavaScript.sublime-syntax | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 7029d8c4cd..554a46efec 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -735,9 +735,9 @@ contexts: set: - - match: ':' scope: keyword.operator.ternary.js - set: expression + set: expression-no-comma - include: else-pop - - expression + - expression-no-comma postfix-operators: - match: '--' @@ -931,10 +931,6 @@ contexts: pop: true - include: else-pop - meta-function-declaration: - - meta_scope: meta.function.declaration - - include: immediately-pop - arrow-function-declaration: - match: '' set: From 4bee151a0691f823edf88d8a069df53f12fb6a36 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 11 Jul 2017 18:08:46 -0400 Subject: [PATCH 38/46] Rewrote constructor. --- JavaScript/JavaScript.sublime-syntax | 130 +++++++++++++-------------- 1 file changed, 62 insertions(+), 68 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 554a46efec..1be743d618 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -464,7 +464,7 @@ contexts: - include: binary-operators - include: ternary-operator - - include: bracketed-property-access + - include: property-access - include: function-call - include: literal-punctuation @@ -592,29 +592,42 @@ contexts: - match: '\bnew\b' scope: keyword.operator.word.new.js set: - - meta-constructor - - constructor-name - - meta-constructor: - - meta_scope: meta.instance.constructor.js - - include: else-pop + - - meta_scope: meta.instance.constructor.js + - include: else-pop + - constructor-body - constructor-name: - - match: '(?=\bfunction\b)' - set: - - constructor-params - - function-declaration - - match: '(?=\bclass\b)' - set: - - constructor-params - - class - - match: '(?={{identifier}})' + constructor-body: + - match: (?=\S) set: - - meta_scope: meta.function-call.constructor.js - include: else-pop - - constructor-params - - - include: well-known-identifiers + + - - match: '(?=\()' + set: function-call-params + - include: else-pop + + - - include: property-access + - include: else-pop + + - - include: expression-break + + - include: regexp-complete + - include: literal-string + - include: literal-string-template + + - include: class + - include: constants + - include: either-function-declaration + - include: object-literal + + - include: parenthesized-expression + - include: array-literal + + - include: literal-number + + - include: well-known-identifiers - include: language-identifiers + - match: '{{dollar_only_identifier}}' scope: variable.type.dollar.only.js punctuation.dollar.js - match: '{{dollar_identifier}}' @@ -623,28 +636,9 @@ contexts: 1: punctuation.dollar.js - match: '{{identifier}}' scope: variable.type.js - - match: '\.' - scope: punctuation.accessor.js - - include: bracketed-property-access - - match: '(?=\S|$)' pop: true - - match: '\(' - scope: punctuation.section.group.js - set: - - - meta_scope: meta.function-call.constructor.js - - include: else-pop - - constructor-params - - - meta_scope: meta.group.js - - match: '\)' - scope: punctuation.section.group.js - pop: true - - expression - - include: else-pop - constructor-params: - - match: '(?=\()' - push: function-call-params - - include: else-pop + - include: else-pop prefix-operators: - match: '~' @@ -728,6 +722,9 @@ contexts: - # subtraction left-to-right both scope: keyword.operator.arithmetic.js push: expression-begin + - match: ',' + scope: punctuation.separator.comma.js # TODO: Change to keyword.operator.comma.js ? + push: expression-begin ternary-operator: - match: '\?' @@ -1192,7 +1189,7 @@ contexts: pop: true - include: expression-list - bracketed-property-access: + property-access: - match: '\[' scope: punctuation.section.brackets.js push: @@ -1203,6 +1200,29 @@ contexts: - match: (?=\S) push: expression + - match: \. + scope: punctuation.accessor.js + push: + # All of these matches use set (or effectively a set via the final + # include/match/pop construct) instead of push so that we escape this + # accessor state once a match has been made. Otherwise identifiers + # following method definitions or method calls will be scoped as + # properties. + - match: '(?=({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' + set: + - meta_scope: meta.function.declaration.js + - match: '(?={{func_lookahead}})' + set: function-declaration + - match: '(?={{arrow_func_lookahead}})' + set: arrow-function-declaration + - include: function-declaration-final-identifier + - match: '(?={{identifier}}\s*\()' + set: + - include: method-call + - match: '(?=.|\n)' + pop: true + - include: object-property + literal-number: - match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)' scope: invalid.illegal.numeric.hex.js @@ -1317,6 +1337,7 @@ contexts: 1: punctuation.separator.comma.js - match: (?=\S) push: expression-no-comma + - include: else-pop literal-variable: - include: well-known-identifiers @@ -1434,31 +1455,4 @@ contexts: scope: support.constant.dom.js pop: true - match: '(?=.|\n)' - pop: true - - literal-punctuation: - - match: \. - scope: punctuation.accessor.js - push: - # All of these matches use set (or effectively a set via the final - # include/match/pop construct) instead of push so that we escape this - # accessor state once a match has been made. Otherwise identifiers - # following method definitions or method calls will be scoped as - # properties. - - match: '(?=({{identifier}})\s*(=)\s*({{func_lookahead}}|{{arrow_func_lookahead}}))' - set: - - meta_scope: meta.function.declaration.js - - match: '(?={{func_lookahead}})' - set: function-declaration - - match: '(?={{arrow_func_lookahead}})' - set: arrow-function-declaration - - include: function-declaration-final-identifier - - match: '(?={{identifier}}\s*\()' - set: - - include: method-call - - match: '(?=.|\n)' - pop: true - - include: object-property - - match: ',' - scope: punctuation.separator.comma.js # TODO: Change to keyword.operator.comma.js ? - push: expression-begin + pop: true \ No newline at end of file From 602561afbdec16c089bc3041251fb0833621bac0 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 11 Jul 2017 18:17:28 -0400 Subject: [PATCH 39/46] Fixed meta scopes not popping correctly. --- JavaScript/JavaScript.sublime-syntax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 1be743d618..83caf5c169 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -593,14 +593,14 @@ contexts: scope: keyword.operator.word.new.js set: - - meta_scope: meta.instance.constructor.js - - include: else-pop + - include: immediately-pop - constructor-body constructor-body: - match: (?=\S) set: - - meta_scope: meta.function-call.constructor.js - - include: else-pop + - include: immediately-pop - - match: '(?=\()' set: function-call-params From 47da79b0863861496d92adb69bec1a0088c4b0d7 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 12 Jul 2017 14:36:29 -0400 Subject: [PATCH 40/46] Fixed extra declaration scope in method declaration. --- JavaScript/JavaScript.sublime-syntax | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 83caf5c169..6133616a00 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1128,9 +1128,6 @@ contexts: | {{method_name}} \s* \( ) push: - - - meta_scope: meta.function.declaration.js - - include: immediately-pop - - - match: '\{' scope: punctuation.section.block.js set: @@ -1141,6 +1138,9 @@ contexts: - include: statements - include: else-pop + - - meta_scope: meta.function.declaration.js + - include: immediately-pop + - - include: function-declaration-parameters - include: else-pop From fd26da85bc8f37fb502bfd378bd7c78cc11e9200 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 12 Jul 2017 16:03:45 -0400 Subject: [PATCH 41/46] Removed reference to deleted literal-punctuation context. --- JavaScript/JavaScript.sublime-syntax | 1 - 1 file changed, 1 deletion(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 6133616a00..5172a6b434 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -467,7 +467,6 @@ contexts: - include: property-access - include: function-call - - include: literal-punctuation - include: fallthrough - include: else-pop From 1ebfdfe976e0200867e2e0945d19a23b869da93c Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Wed, 12 Jul 2017 16:35:00 -0400 Subject: [PATCH 42/46] Added pops for method names. --- JavaScript/JavaScript.sublime-syntax | 2 ++ 1 file changed, 2 insertions(+) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 5172a6b434..8cb42778eb 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1083,8 +1083,10 @@ contexts: scope: meta.object-literal.key.dollar.js entity.name.function.js captures: 1: punctuation.dollar.js + pop: true - match: '{{identifier}}' scope: entity.name.function.js + pop: true - match: "'" scope: punctuation.definition.string.begin.js set: From e10e465adc96d220b9fd1b978eb8ba2ab9d6adc3 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 25 Jul 2017 11:18:36 -0400 Subject: [PATCH 43/46] Minor fixes. --- JavaScript/JavaScript.sublime-syntax | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 8cb42778eb..5c1aea3c4d 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -655,7 +655,7 @@ contexts: - match: \bnew\b scope: keyword.operator.word.new.js - - match: \bdelete|typeof|void\b + - match: \b(?:delete|typeof|void)\b scope: keyword.operator.js binary-operators: @@ -843,20 +843,22 @@ contexts: function-declaration-identifiers: - match: '(?={{identifier}}\s*\.)' push: - - match: '\bprototype\b' - scope: support.constant.prototype.js - - include: language-identifiers - - match: '{{dollar_only_identifier}}' - scope: support.class.dollar.only.js punctuation.dollar.js - - match: '{{dollar_identifier}}' - scope: support.class.dollar.js - captures: - 1: punctuation.dollar.js - - match: '{{identifier}}' - scope: support.class.js - - match: '\.' - scope: punctuation.accessor.js - pop: true + - - match: '\.' + scope: punctuation.accessor.js + pop: true + - include: else-pop + - - match: '\bprototype\b' + scope: support.constant.prototype.js + - include: language-identifiers + - match: '{{dollar_only_identifier}}' + scope: support.class.dollar.only.js punctuation.dollar.js + - match: '{{dollar_identifier}}' + scope: support.class.dollar.js + captures: + 1: punctuation.dollar.js + - match: '{{identifier}}' + scope: support.class.js + - include: else-pop - include: function-declaration-final-identifier function-declaration-final-identifier: From 8a6776a3dc67067f00a5dd7b8aa112d8ae0096b5 Mon Sep 17 00:00:00 2001 From: thom Date: Wed, 2 Aug 2017 09:13:19 -0400 Subject: [PATCH 44/46] Various minor cleanup. --- JavaScript/JavaScript.sublime-syntax | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 5c1aea3c4d..d7947bcb57 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -478,7 +478,7 @@ contexts: expression-begin: - match: \) - scope: invalid.illegal.stray-bracket-end + scope: invalid.illegal.stray-bracket-end.js pop: true - include: expression-break @@ -1076,10 +1076,6 @@ contexts: scope: punctuation.separator.key-value.js push: expression-no-comma - meta-object-literal-key: - - meta_scope: meta.object-literal.key.js - - include: else-pop - method-name: - match: '(\$)[_$[:alnum:]]*' scope: meta.object-literal.key.dollar.js entity.name.function.js From 983b2e47ef219400589c626b5b0ac25c14e977f3 Mon Sep 17 00:00:00 2001 From: thom Date: Wed, 18 Oct 2017 11:22:47 -0400 Subject: [PATCH 45/46] Refactored anonymous contexts to avoid nested lists. --- JavaScript/JavaScript.sublime-syntax | 303 +++++++++++++++------------ 1 file changed, 170 insertions(+), 133 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index d7947bcb57..5ae27a669b 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -439,6 +439,10 @@ contexts: - include: statements - include: else-pop + block-meta: + - meta_scope: meta.block.js + - include: immediately-pop + expression-break: - match: (?=[;})\]]) pop: true @@ -591,53 +595,65 @@ contexts: - match: '\bnew\b' scope: keyword.operator.word.new.js set: - - - meta_scope: meta.instance.constructor.js - - include: immediately-pop + - constructor-meta - constructor-body + constructor-meta: + - meta_scope: meta.instance.constructor.js + - include: immediately-pop + constructor-body: - - match: (?=\S) + - match: '' set: - - - meta_scope: meta.function-call.constructor.js - - include: immediately-pop + - constructor-body-meta + - constructor-body-expect-arguments + - constructor-body-expect-property-access + - constructor-body-expect-class - - - match: '(?=\()' - set: function-call-params - - include: else-pop + constructor-body-meta: + - meta_scope: meta.function-call.constructor.js + - include: immediately-pop - - - include: property-access - - include: else-pop + constructor-body-expect-arguments: + - match: '(?=\()' + set: function-call-params + - include: else-pop - - - include: expression-break + constructor-body-expect-property-access: + - include: property-access + - include: else-pop - - include: regexp-complete - - include: literal-string - - include: literal-string-template + constructor-body-expect-class: + - include: expression-break - - include: class - - include: constants - - include: either-function-declaration - - include: object-literal + - include: regexp-complete + - include: literal-string + - include: literal-string-template - - include: parenthesized-expression - - include: array-literal + - include: class + - include: constants + - include: either-function-declaration + - include: object-literal - - include: literal-number + - include: parenthesized-expression + - include: array-literal - - include: well-known-identifiers - - include: language-identifiers + - include: literal-number - - match: '{{dollar_only_identifier}}' - scope: variable.type.dollar.only.js punctuation.dollar.js - - match: '{{dollar_identifier}}' - scope: variable.type.dollar.js - captures: - 1: punctuation.dollar.js - - match: '{{identifier}}' - scope: variable.type.js - pop: true + - include: well-known-identifiers + - include: language-identifiers - - include: else-pop + - match: '{{dollar_only_identifier}}' + scope: variable.type.dollar.only.js punctuation.dollar.js + - match: '{{dollar_identifier}}' + scope: variable.type.dollar.js + captures: + 1: punctuation.dollar.js + - match: '{{identifier}}' + scope: variable.type.js + pop: true + + - include: else-pop prefix-operators: - match: '~' @@ -729,12 +745,15 @@ contexts: - match: '\?' scope: keyword.operator.ternary.js set: - - - match: ':' - scope: keyword.operator.ternary.js - set: expression-no-comma - - include: else-pop + - ternary-operator-expect-colon - expression-no-comma + ternary-operator-expect-colon: + - match: ':' + scope: keyword.operator.ternary.js + set: expression-no-comma + - include: else-pop + postfix-operators: - match: '--' scope: keyword.operator.arithmetic.js @@ -843,24 +862,30 @@ contexts: function-declaration-identifiers: - match: '(?={{identifier}}\s*\.)' push: - - - match: '\.' - scope: punctuation.accessor.js - pop: true - - include: else-pop - - - match: '\bprototype\b' - scope: support.constant.prototype.js - - include: language-identifiers - - match: '{{dollar_only_identifier}}' - scope: support.class.dollar.only.js punctuation.dollar.js - - match: '{{dollar_identifier}}' - scope: support.class.dollar.js - captures: - 1: punctuation.dollar.js - - match: '{{identifier}}' - scope: support.class.js - - include: else-pop + - function-declaration-identifiers-expect-dot + - function-declaration-identifiers-expect-class - include: function-declaration-final-identifier + function-declaration-identifiers-expect-dot: + - match: '\.' + scope: punctuation.accessor.js + pop: true + - include: else-pop + + function-declaration-identifiers-expect-class: + - match: '\bprototype\b' + scope: support.constant.prototype.js + - include: language-identifiers + - match: '{{dollar_only_identifier}}' + scope: support.class.dollar.only.js punctuation.dollar.js + - match: '{{dollar_identifier}}' + scope: support.class.dollar.js + captures: + 1: punctuation.dollar.js + - match: '{{identifier}}' + scope: support.class.js + - include: else-pop + function-declaration-final-identifier: - match: '(?={{identifier}}\s*(=)\s*)' push: @@ -907,55 +932,74 @@ contexts: function-declaration: - match: '' set: - - - match: (?=\S) - set: function-block - - include: else-pop - - - meta_scope: meta.function.declaration.js - - include: immediately-pop - - - include: function-declaration-parameters - - include: else-pop - - - match: '{{identifier}}' - scope: entity.name.function.js - pop: true - - include: else-pop - - - match: \b(function)\b\s*(\*)? - captures: - 1: storage.type.function.js - 2: keyword.generator.asterisk.js - pop: true - - include: else-pop - - - match: '\basync\b' - scope: storage.type.js - pop: true - - include: else-pop + - function-declaration-expect-body + - function-declaration-meta + - function-declaration-expect-parameters + - function-declaration-expect-name + - function-declaration-expect-function-keyword + - function-declaration-expect-async + + function-declaration-expect-body: + - match: (?=\S) + set: function-block + + function-declaration-meta: + - meta_scope: meta.function.declaration.js + - include: immediately-pop + + function-declaration-expect-parameters: + - include: function-declaration-parameters + - include: else-pop + + function-declaration-expect-name: + - match: '{{identifier}}' + scope: entity.name.function.js + pop: true + - include: else-pop + + function-declaration-expect-function-keyword: + - match: \b(function)\b\s*(\*)? + captures: + 1: storage.type.function.js + 2: keyword.generator.asterisk.js + pop: true + - include: else-pop + + function-declaration-expect-async: + - match: '\basync\b' + scope: storage.type.js + pop: true + - include: else-pop arrow-function-declaration: - match: '' set: - - - meta_scope: meta.function.declaration.js - - match: (?=\{) - set: function-block - - match: (?=\S) - set: - - - meta_scope: meta.block.js - - include: immediately-pop - - - match: (?=,) - pop: true - - include: expression-statement-end - - expression-begin - - - match: '=>' - scope: storage.type.function.arrow.js - pop: true - - include: else-pop - - - match: '{{identifier}}' - scope: variable.parameter.function.js - pop: true - - include: function-declaration-parameters - - include: else-pop - - - match: '\basync\b' - scope: storage.type.js - pop: true - - include: else-pop + - arrow-function-expect-body + - function-declaration-meta + - arrow-function-expect-arrow + - arrow-function-expect-parameters + - function-declaration-expect-async + + arrow-function-expect-body: + - match: (?=\{) + set: function-block + - match: (?=\S) + set: + - block-meta + - expression-no-comma + + arrow-function-expect-arrow: + - match: '=>' + scope: storage.type.function.arrow.js + pop: true + - include: else-pop + + arrow-function-expect-parameters: + - match: '{{identifier}}' + scope: variable.parameter.function.js + pop: true + - include: function-declaration-parameters + - include: else-pop function-block: - meta_scope: meta.block.js @@ -968,6 +1012,7 @@ contexts: - match: '(?=\})' pop: true - include: statements + - include: else-pop function-declaration-parameters: - match: \( @@ -1032,15 +1077,10 @@ contexts: (?: {{func_lookahead}} | {{arrow_func_lookahead}} ) ) push: - - - include: either-function-declaration - - include: else-pop - - - meta_scope: meta.function.declaration.js - - include: immediately-pop - - - match: ':' - scope: punctuation.separator.key-value.js - - include: else-pop - - - meta_scope: meta.object-literal.key.js - - include: else-pop + - either-function-declaration + - function-declaration-meta + - object-literal-expect-colon + - object-literal-meta-key - method-name - include: method-declaration @@ -1057,8 +1097,7 @@ contexts: push: expression - match: "(?=\"|')" push: - - - meta_scope: meta.object-literal.key.js - - include: immediately-pop + - object-literal-meta-key - literal-string - match: '(\$)[$\w]*(?=\s*:)' scope: meta.object-literal.key.dollar.js @@ -1076,6 +1115,15 @@ contexts: scope: punctuation.separator.key-value.js push: expression-no-comma + object-literal-meta-key: + - meta_scope: meta.object-literal.key.js + - include: else-pop + + object-literal-expect-colon: + - match: ':' + scope: punctuation.separator.key-value.js + - include: else-pop + method-name: - match: '(\$)[_$[:alnum:]]*' scope: meta.object-literal.key.dollar.js entity.name.function.js @@ -1127,31 +1175,20 @@ contexts: | {{method_name}} \s* \( ) push: - - - match: '\{' - scope: punctuation.section.block.js - set: - - meta_scope: meta.block.js - - match: '\}' - scope: punctuation.section.block.js - pop: true - - include: statements - - include: else-pop - - - - meta_scope: meta.function.declaration.js - - include: immediately-pop - - - - include: function-declaration-parameters - - include: else-pop - + - function-declaration-expect-body + - function-declaration-meta + - function-declaration-expect-parameters - method-name - - - - match: \* - scope: keyword.generator.asterisk.js - - match: \b(get|set)\b(?!\s*\() - scope: storage.type.accessor.js - - match: \bstatic\b - scope: storage.type.js - - include: else-pop + - method-declaration-expect-prefix + + method-declaration-expect-prefix: + - match: \* + scope: keyword.generator.asterisk.js + - match: \b(get|set)\b(?!\s*\() + scope: storage.type.accessor.js + - match: \bstatic\b + scope: storage.type.js + - include: else-pop parenthesized-expression: - match: \( From 24c47557a03d3fb8fa6604d5048e2ed510e3ce1a Mon Sep 17 00:00:00 2001 From: thom Date: Wed, 8 Nov 2017 11:05:33 -0500 Subject: [PATCH 46/46] Removed redundant test. --- JavaScript/syntax_test_js.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/JavaScript/syntax_test_js.js b/JavaScript/syntax_test_js.js index cda081ba70..670f0c6bc1 100644 --- a/JavaScript/syntax_test_js.js +++ b/JavaScript/syntax_test_js.js @@ -234,9 +234,6 @@ not_a_comment; '// /* not a comment'() {}, // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} - '// /* not a comment'() {}, -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} - "// /* not a comment"() {}, // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {} // ^ - meta.function.declaration meta.function.declaration