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

Add support for ternary and null coalescing operators #285

Merged
merged 8 commits into from Oct 24, 2017

Conversation

Projects
None yet
3 participants
@dsifford
Contributor

dsifford commented Oct 5, 2017

This PR adds scopes for ternaries and the new (as of php7.0) null-coalescing operator.

Description of the Change

Currently, this is how the above items are scoped:

// ternary expression
  $foo = $bar ? $bar : 'baz';
//            ^text.html.php meta.embedded.block.php source.php
//                   ^text.html.php meta.embedded.block.php source.php

// ternary shorthand
  $foo = $bar ?: 'baz';
//            ^^text.html.php meta.embedded.block.php source.php

// null coalescing operator
  $foo = $bar ?? 'baz';
//            ^^text.html.php meta.embedded.block.php source.php

And here's how it is after the changes I made:

// ternary expression
  $foo = $bar ? $bar : 'baz';
//            ^text.html.php meta.embedded.block.php source.php keyword.operator.ternary.php
//                   ^text.html.php meta.embedded.block.php source.php keyword.operator.ternary.php

// ternary shorthand
  $foo = $bar ?: 'baz';
//            ^^text.html.php meta.embedded.block.php source.php keyword.operator.ternary.php

// null coalescing operator
  $foo = $bar ?? 'baz';
//            ^^text.html.php meta.embedded.block.php source.php keyword.operator.null-coalescing.php

Alternate Designs

It would be possible to expand the specificity of the ternary expression scope (e.g. (expr) : (val_if_true) ? (val_if_false)) by wrapping the entire expression in meta.expression.ternary.php (or something along those lines), but I chose not to do that because it doesn't seem like it would add any value.

Benefits

  • Increased scope specificity.
  • Allows theme maintainers to colorize ternary and null coalescing operators the same as the other existing operators.

Possible Drawbacks

None to my knowledge.

Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated spec/php-spec.coffee Outdated

@50Wliu 50Wliu added the under-review label Oct 16, 2017

@@ -2041,6 +2041,15 @@
'match': ','
'name': 'punctuation.separator.delimiter.php'
}
{

This comment has been minimized.

@Ingramz

Ingramz Oct 16, 2017

Contributor

Is there any particular reason for the includes? Could those simply be just inlined?

@Ingramz

Ingramz Oct 16, 2017

Contributor

Is there any particular reason for the includes? Could those simply be just inlined?

This comment has been minimized.

@dsifford

dsifford Oct 16, 2017

Contributor

Personal preference. Never know when they might be needed to compose some larger expression in the future. Ran into that problem a couple times with inlined matches in language-css.

@dsifford

dsifford Oct 16, 2017

Contributor

Personal preference. Never know when they might be needed to compose some larger expression in the future. Ran into that problem a couple times with inlined matches in language-css.

@50Wliu 50Wliu self-assigned this Oct 16, 2017

Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated grammars/php.cson Outdated
Show outdated Hide outdated spec/php-spec.coffee Outdated

dsifford and others added some commits Oct 16, 2017

@50Wliu 50Wliu merged commit 4993090 into atom:master Oct 24, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment