Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
csharp: add support for binary literals and _ as separator
Browse files Browse the repository at this point in the history
Note that proper `_` usage is not enforced; this matches vscode behavior.
  • Loading branch information
sandyarmstrong committed May 2, 2017
1 parent eb82671 commit de35151
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ export var language = <ILanguage> {
[/\$"/, { token: 'string.quote', next: '@interpolatedstring' } ],

// numbers
[/\d*\.\d+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
[/0[xX][0-9a-fA-F]+/, 'number.hex'],
[/\d+/, 'number'],
[/[0-9_]*\.[0-9_]+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
[/0[xX][0-9a-fA-F_]+/, 'number.hex'],
[/0[bB][01_]+/, 'number.hex'], // binary: use same theme style as hex
[/[0-9_]+/, 'number'],

// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
Expand Down
55 changes: 55 additions & 0 deletions test/csharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,25 +525,62 @@ testTokenization('csharp', [
{ startIndex: 0, type: 'number.cs' }
]}],

[{
line: '123_456',
tokens: [
{ startIndex: 0, type: 'number.cs' }
]}],

[{
line: '0x',
tokens: [
{ startIndex: 0, type: 'number.cs' },
{ startIndex: 1, type: 'identifier.cs' }
]}],

[{
line: '0b',
tokens: [
{ startIndex: 0, type: 'number.cs' },
{ startIndex: 1, type: 'identifier.cs' }
]}],

[{
line: '0x123',
tokens: [
{ startIndex: 0, type: 'number.hex.cs' }
]}],

[{
line: '0x123_456',
tokens: [
{ startIndex: 0, type: 'number.hex.cs' }
]}],

[{
line: '0b101',
tokens: [
{ startIndex: 0, type: 'number.hex.cs' }
]}],

[{
line: '0b1010_0001',
tokens: [
{ startIndex: 0, type: 'number.hex.cs' }
]}],

[{
line: '23.5',
tokens: [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '1_23.5',
tokens: [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '23.5e3',
tokens: [
Expand All @@ -568,6 +605,12 @@ testTokenization('csharp', [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '2_3.5f',
tokens: [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '1.72E3F',
tokens: [
Expand Down Expand Up @@ -598,6 +641,12 @@ testTokenization('csharp', [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '456_123.5D',
tokens: [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '23.5d',
tokens: [
Expand All @@ -616,6 +665,12 @@ testTokenization('csharp', [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '1.720_123E3d',
tokens: [
{ startIndex: 0, type: 'number.float.cs' }
]}],

[{
line: '1.72e3D',
tokens: [
Expand Down

0 comments on commit de35151

Please sign in to comment.