From 9360c2595f58c9ac2a4326dd6f47b1d977ab3f75 Mon Sep 17 00:00:00 2001 From: Anubha Mathur Date: Thu, 17 Mar 2016 10:49:23 -0700 Subject: [PATCH 1/2] Adding capability for ternary operator --- TypeScript.YAML-tmLanguage | 7 +++++++ TypeScript.tmLanguage | 18 ++++++++++++++++++ TypeScriptReact.YAML-tmLanguage | 7 +++++++ TypeScriptReact.tmLanguage | 18 ++++++++++++++++++ tests/baselines/Issue124.txt | 27 +++++++++++++++++++++++++++ tests/cases/Issue124.ts | 16 ++++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 tests/baselines/Issue124.txt create mode 100644 tests/cases/Issue124.ts diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 118b91f4..4ea4334f 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -26,11 +26,18 @@ repository: '1': { name: variable.ts } end: (?=$|[;,]) patterns: + - include: '#ternary-operator' - include: '#type-annotation' - include: '#string' - include: '#comment' - include: '#expression' + ternary-operator: + begin: (\?) + end: (:) + patterns: + - include: '#expression' + control-statement: name: keyword.control.ts match: (? + ternary-operator + + begin + (\?) + end + (:) + patterns + + + include + #expression + + + this-literal match @@ -1839,6 +1853,10 @@ meta.var-single-variable.expr.ts patterns + + include + #ternary-operator + include #type-annotation diff --git a/TypeScriptReact.YAML-tmLanguage b/TypeScriptReact.YAML-tmLanguage index 5f0e895f..7c939f4f 100644 --- a/TypeScriptReact.YAML-tmLanguage +++ b/TypeScriptReact.YAML-tmLanguage @@ -28,11 +28,18 @@ repository: '1': { name: variable.tsx } end: (?=$|[;,]) patterns: + - include: '#ternary-operator' - include: '#type-annotation' - include: '#string' - include: '#comment' - include: '#expression' + ternary-operator: + begin: (\?) + end: (:) + patterns: + - include: '#expression' + control-statement: name: keyword.control.tsx match: (? + ternary-operator + + begin + (\?) + end + (:) + patterns + + + include + #expression + + + this-literal match @@ -2205,6 +2219,10 @@ meta.var-single-variable.expr.tsx patterns + + include + #ternary-operator + include #type-annotation diff --git a/tests/baselines/Issue124.txt b/tests/baselines/Issue124.txt new file mode 100644 index 00000000..e01630c5 --- /dev/null +++ b/tests/baselines/Issue124.txt @@ -0,0 +1,27 @@ +[6, 9]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[6, 16]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[6, 23]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[7, 9]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[7, 16]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[7, 23]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts string.template.ts +[7, 24]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts string.template.ts +[7, 32]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts template.element.ts keyword.others.ts +[8, 9]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[8, 16]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts string.template.ts +[8, 17]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts string.template.ts +[8, 26]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts string.template.ts +[8, 27]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.template.ts string.template.ts +[10, 5]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts variable.ts +[10, 14]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts +[10, 16]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts +[10, 18]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.brace.paren.ts +[10, 35]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts constant.language.boolean.ts +[12, 5]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts variable.ts +[12, 15]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts +[12, 20]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts keyword.operator.comparison.ts +[12, 24]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts string.single.ts +[12, 30]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts +[12, 32]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts string.single.ts +[12, 40]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts +[12, 42]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts string.single.ts +[15, 2]: source.ts comment.block.ts \ No newline at end of file diff --git a/tests/cases/Issue124.ts b/tests/cases/Issue124.ts new file mode 100644 index 00000000..d685a988 --- /dev/null +++ b/tests/cases/Issue124.ts @@ -0,0 +1,16 @@ +/* + Solving Issue #124, #80, #81 + Adding capability of ternary strings. +*/ + +let a = ^^true ? ^^true : ^^true; +let b = ^^true ? ^^true : ^^`^^this is ^^${} highlighted` +let c = ^^true ? ^^`^^hello` : ^^`^^this ${DEPENDENCY_SEPARATOR}${moduleName} is highlighted`; + +var ^^newVar = ^^a ^^? ^^(b == `hello`) : ^^true; + +var ^^debArch = ^^arch ^^=== ^^'x64' ^^? ^^'amd64' ^^: ^^'i386'; + +/* + ^^Comment +*/ \ No newline at end of file From 79bf69c3f4f4b7789ee9e5924b9318014cf5742d Mon Sep 17 00:00:00 2001 From: Anubha Mathur Date: Wed, 27 Apr 2016 09:36:09 -0700 Subject: [PATCH 2/2] Adding a safe expression list for expressions in ternary operator. --- TypeScript.YAML-tmLanguage | 31 ++++++++++- TypeScript.tmLanguage | 94 ++++++++++++++++++++++++++++++++- TypeScriptReact.YAML-tmLanguage | 31 ++++++++++- TypeScriptReact.tmLanguage | 94 ++++++++++++++++++++++++++++++++- 4 files changed, 242 insertions(+), 8 deletions(-) diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 9d8c2202..7037986a 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -26,17 +26,44 @@ repository: '1': { name: variable.ts } end: (?=$|[;,]) patterns: - - include: '#ternary-operator' + - include: '#ternary-expression' - include: '#type-annotation' - include: '#string' - include: '#comment' - include: '#expression' + ternary-expression: + begin: (?=\?) + end: (?=$|[;,]) + patterns: + - include: '#ternary-operator' + - include: '#ternary-expression-type' + ternary-operator: begin: (\?) end: (:) patterns: - - include: '#expression' + - include: '#ternary-expression-type' + + ternary-expression-type: + name: meta.expression.ts + patterns: + - include: '#string' + - include: '#regex' + - include: '#template' + - include: '#comment' + - include: '#literal' + - include: '#paren-expression' + - include: '#ternary-expression' + - include: '#import-operator' + - include: '#expression-operator' + - include: '#imply-operator' + - include: '#relational-operator' + - include: '#arithmetic-operator' + - include: '#logic-operator' + - include: '#assignment-operator' + - include: '#type-primitive' + - include: '#function-call' control-statement: name: keyword.control.ts diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index c4bb2382..d56f19f9 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -1448,6 +1448,96 @@ + ternary-expression + + begin + (?=\?) + end + (?=$|[;,]) + patterns + + + include + #ternary-operator + + + include + #ternary-expression-type + + + + ternary-expression-type + + name + meta.expression.ts + patterns + + + include + #string + + + include + #regex + + + include + #template + + + include + #comment + + + include + #literal + + + include + #paren-expression + + + include + #ternary-expression + + + include + #import-operator + + + include + #expression-operator + + + include + #imply-operator + + + include + #relational-operator + + + include + #arithmetic-operator + + + include + #logic-operator + + + include + #assignment-operator + + + include + #type-primitive + + + include + #function-call + + + ternary-operator begin @@ -1458,7 +1548,7 @@ include - #expression + #ternary-expression-type @@ -1855,7 +1945,7 @@ include - #ternary-operator + #ternary-expression include diff --git a/TypeScriptReact.YAML-tmLanguage b/TypeScriptReact.YAML-tmLanguage index f145191c..5f3ef296 100644 --- a/TypeScriptReact.YAML-tmLanguage +++ b/TypeScriptReact.YAML-tmLanguage @@ -28,17 +28,44 @@ repository: '1': { name: variable.tsx } end: (?=$|[;,]) patterns: - - include: '#ternary-operator' + - include: '#ternary-expression' - include: '#type-annotation' - include: '#string' - include: '#comment' - include: '#expression' + ternary-expression: + begin: (?=\?) + end: (?=$|[;,]) + patterns: + - include: '#ternary-operator' + - include: '#ternary-expression-type' + ternary-operator: begin: (\?) end: (:) patterns: - - include: '#expression' + - include: '#ternary-expression-type' + + ternary-expression-type: + name: meta.expression.tsx + patterns: + - include: '#string' + - include: '#regex' + - include: '#template' + - include: '#comment' + - include: '#literal' + - include: '#paren-expression' + - include: '#ternary-expression' + - include: '#import-operator' + - include: '#expression-operator' + - include: '#imply-operator' + - include: '#relational-operator' + - include: '#arithmetic-operator' + - include: '#logic-operator' + - include: '#assignment-operator' + - include: '#type-primitive' + - include: '#function-call' control-statement: name: keyword.control.tsx diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 5ca8395f..1d0e888b 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -1814,6 +1814,96 @@ + ternary-expression + + begin + (?=\?) + end + (?=$|[;,]) + patterns + + + include + #ternary-operator + + + include + #ternary-expression-type + + + + ternary-expression-type + + name + meta.expression.tsx + patterns + + + include + #string + + + include + #regex + + + include + #template + + + include + #comment + + + include + #literal + + + include + #paren-expression + + + include + #ternary-expression + + + include + #import-operator + + + include + #expression-operator + + + include + #imply-operator + + + include + #relational-operator + + + include + #arithmetic-operator + + + include + #logic-operator + + + include + #assignment-operator + + + include + #type-primitive + + + include + #function-call + + + ternary-operator begin @@ -1824,7 +1914,7 @@ include - #expression + #ternary-expression-type @@ -2221,7 +2311,7 @@ include - #ternary-operator + #ternary-expression include