-
Notifications
You must be signed in to change notification settings - Fork 134
Adding capability for ternary expression as a separate scope #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,45 @@ repository: | |
'1': { name: variable.ts } | ||
end: (?=$|[;,]) | ||
patterns: | ||
- 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: '#ternary-expression-type' | ||
|
||
ternary-expression-type: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you document (in comments) exactly what this is supposed to capture? For instance, why do you need types covered here? |
||
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 | ||
match: (?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default)\b | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are ternary expressions, not operators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make that change. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
('?' and ':') together are known as the ternary operator, not sure if we should call it expression or operator. Also note that we end at ':', which can be followed by an expression (since expressions can exist anywhere.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe just to end there? I know an expression can exist anywhere, but not any production can come after the ":". For example, is this now parsed as a code block (with a labeled statement) after the ":" instead of an expression:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it is not safe to end here since even in other scenarios like the following, highlighting shows no issues, though it should.
I will add a bigger scope called ternary-expression that only allows this ternary-operator followed by an expression, and see if that works. Thanks.