FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't scope decimal mark to allow ligatures to work by MaximSokolov · Pull Request #365 · atom/language-javascript · GitHub

This repository was archived by the owner on Dec 15, 2022. It is now read-only.
/ language-javascript Public archive
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .coffee  (1) .cson  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
35 changes: 11 additions & 24 deletions grammars/javascript.cson
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
Expand Up @@ -1052,32 +1052,19 @@
}
{
'match': '''(?x)
(?<!\\$)(?:
(?:\\b[0-9]+(\\.)[0-9]+[eE][+-]?[0-9]+\\b)| # 1.1E+3
(?:\\b[0-9]+(\\.)[eE][+-]?[0-9]+\\b)| # 1.E+3
(?:\\B(\\.)[0-9]+[eE][+-]?[0-9]+\\b)| # .1E+3
(?:\\b[0-9]+[eE][+-]?[0-9]+\\b)| # 1E+3
(?:\\b[0-9]+(\\.)[0-9]+\\b)| # 1.1
(?:\\b[0-9]+(\\.)\\B)| # 1.
(?:\\B(\\.)[0-9]+\\b)| # .1
(?:\\b[0-9]+\\b(?!\\.)) # 1
# Don't scope the decimal mark to allow ligatures to work
(?<!\\$)(
(\\b[0-9]+\\.[0-9]+[eE][+-]?[0-9]+\\b)| # 1.1E+3
(\\b[0-9]+\\.[eE][+-]?[0-9]+\\b)| # 1.E+3
(\\B\\.[0-9]+[eE][+-]?[0-9]+\\b)| # .1E+3
(\\b[0-9]+[eE][+-]?[0-9]+\\b)| # 1E+3
(\\b[0-9]+\\.[0-9]+\\b)| # 1.1
(\\b[0-9]+\\.\\B)| # 1.
(\\B\\.[0-9]+\\b)| # .1
(\\b[0-9]+\\b(?!\\.)) # 1
)(?!\\$)
'''
'captures':
'0':
'name': 'constant.numeric.decimal.js'
'1':
'name': 'meta.delimiter.decimal.period.js'
'2':
'name': 'meta.delimiter.decimal.period.js'
'3':
'name': 'meta.delimiter.decimal.period.js'
'4':
'name': 'meta.delimiter.decimal.period.js'
'5':
'name': 'meta.delimiter.decimal.period.js'
'6':
'name': 'meta.delimiter.decimal.period.js'
'name': 'constant.numeric.decimal.js'
}
]
'operators':
Expand Down
33 changes: 3 additions & 30 deletions spec/javascript-spec.coffee
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
Expand Up @@ -211,36 +211,9 @@ describe "Javascript grammar", ->
expect(tokens[0]).toEqual value: '0010', scopes: ['source.js', 'constant.numeric.octal.js']

it "tokenizes decimals", ->
{tokens} = grammar.tokenizeLine('1234')
expect(tokens[0]).toEqual value: '1234', scopes: ['source.js', 'constant.numeric.decimal.js']

{tokens} = grammar.tokenizeLine('5e-10')
expect(tokens[0]).toEqual value: '5e-10', scopes: ['source.js', 'constant.numeric.decimal.js']

{tokens} = grammar.tokenizeLine('5E+5')
expect(tokens[0]).toEqual value: '5E+5', scopes: ['source.js', 'constant.numeric.decimal.js']

{tokens} = grammar.tokenizeLine('9.')
expect(tokens[0]).toEqual value: '9', scopes: ['source.js', 'constant.numeric.decimal.js']
expect(tokens[1]).toEqual value: '.', scopes: ['source.js', 'constant.numeric.decimal.js', 'meta.delimiter.decimal.period.js']

{tokens} = grammar.tokenizeLine('.9')
expect(tokens[0]).toEqual value: '.', scopes: ['source.js', 'constant.numeric.decimal.js', 'meta.delimiter.decimal.period.js']
expect(tokens[1]).toEqual value: '9', scopes: ['source.js', 'constant.numeric.decimal.js']

{tokens} = grammar.tokenizeLine('9.9')
expect(tokens[0]).toEqual value: '9', scopes: ['source.js', 'constant.numeric.decimal.js']
expect(tokens[1]).toEqual value: '.', scopes: ['source.js', 'constant.numeric.decimal.js', 'meta.delimiter.decimal.period.js']
expect(tokens[2]).toEqual value: '9', scopes: ['source.js', 'constant.numeric.decimal.js']

{tokens} = grammar.tokenizeLine('.1e-23')
expect(tokens[0]).toEqual value: '.', scopes: ['source.js', 'constant.numeric.decimal.js', 'meta.delimiter.decimal.period.js']
expect(tokens[1]).toEqual value: '1e-23', scopes: ['source.js', 'constant.numeric.decimal.js']

{tokens} = grammar.tokenizeLine('1.E3')
expect(tokens[0]).toEqual value: '1', scopes: ['source.js', 'constant.numeric.decimal.js']
expect(tokens[1]).toEqual value: '.', scopes: ['source.js', 'constant.numeric.decimal.js', 'meta.delimiter.decimal.period.js']
expect(tokens[2]).toEqual value: 'E3', scopes: ['source.js', 'constant.numeric.decimal.js']
for token in ['1234', '.9', '9.', '9.9', '5E+5', '5e-10', '.1e-23', '1.E+3', '1.E3', '1.1E+3']
{tokens} = grammar.tokenizeLine(token)
expect(tokens[0]).toEqual value: token, scopes: ['source.js', 'constant.numeric.decimal.js']

it "does not tokenize numbers that are part of a variable", ->
{tokens} = grammar.tokenizeLine('hi$1')
Expand Down

Back | FazBrowse Home | New Git URL