Skip to content

Comments

Add support for binary numbers (C-like)#1272

Closed
isc30 wants to merge 2 commits intoPrismJS:gh-pagesfrom
isc30:patch-2
Closed

Add support for binary numbers (C-like)#1272
isc30 wants to merge 2 commits intoPrismJS:gh-pagesfrom
isc30:patch-2

Conversation

@isc30
Copy link
Contributor

@isc30 isc30 commented Jan 27, 2018

0b0101001

@isc30 isc30 changed the title Add support for binary numbers Add support for binary numbers (C-like) Jan 27, 2018
@isc30
Copy link
Contributor Author

isc30 commented Jan 28, 2018

ready

@Golmote
Copy link
Contributor

Golmote commented Jan 28, 2018

Thanks again for contributing.
I'm a bit worried though when it comes to making changes to the c-like component, since it's used by many other components.
So I did a thorough check of each language using it, to see whether or not they support binary literals. The first thing that surprised me is that Standard C does not seem to support binary literals. AFAICT, although they are supported in GCC, they were only added in C++14. Therefore, I think they should be added to the cpp component instead of the c component.

Here follow the results of the current support state for binary literals in C-like languages in Prism.

Component Support for binary literals Redefinition of number Justification for redefinition Highlighting support in Prism
JavaScript Yes Yes Binary literals, NaN, Infinity Yes
JavaScript > ActionScript Yes No Yes
JavaScript > CoffeeScript Yes No Yes
JavaScript > Flow Yes No Yes
JavaScript > N4JS Yes No Yes
JavaScript > Pug Yes No Yes
JavaScript > React JSX Yes No Yes
JavaScript > TypeScript Yes No Yes
C No Yes /[ful]/ suffix No
C > Bison No No No
C > C++ Yes No No
C > C++ > Arduino Yes No No
C > Objective-C No No No
C > OpenCL No No No
C# Yes Yes Adds f suffix, drops e notation support (?). Should support optional underscores. No
D Yes Yes Binary literals, /[ulfi]/ suffix Yes
Dart No No No
F# Yes Yes Binary literals, `/y uy
GLSL No Yes /[ulf]/ suffix No
Go No Yes i suffix No
Groovy Yes Yes Binary literals, underscores, /[glidf]/ suffix Yes
Haxe No No No
Java Yes Yes Binary literals, floating-point hexadecimal, /[df]/ suffix Yes
Java > Scala No Yes Adds /[dfl]/ suffix, drops binary literals No
Jolie No Yes Restricts to decimal numbers No
Kotlin Yes Yes Binary literals, /[fFL]/ suffix Yes
nginx Yes ? No Yes
PHP Yes No No
Processing No No No
Protocol Buffers No No No
Qore Yes Yes Binary literals, floating-point hexadecimal, /[df]/ suffix Yes
Reason No No No
Ruby Yes No No
Ruby > Crystal Yes Yes Underscores, `/[uif](8 16
Ruby > Haml Yes No No
Swift Yes Yes Binary literals, underscores Yes

So, as you can (hopefully) see from this table, there is a number of languages that do not have support for binary literals and do not override the definition of the numbers pattern inherited from the c-like component. This means adding support for binary literals in the c-like component would add unwanted support for them in those languages, and I don't think we want this to happen.

I'm closing this PR. If you want, feel free to create a new one to add support for binary literals in the cpp component instead (by redefining the numbers pattern entirely).

@Golmote Golmote closed this Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants