Skip to content

Commit 008a045

Browse files
author
deathaxe
committed
Fix number patterns
Fixes #253 Syncs number patterns with ST's core JavaScript syntax.
1 parent d354634 commit 008a045

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CoffeeScript.sublime-syntax

+20-5
Original file line numberDiff line numberDiff line change
@@ -499,26 +499,34 @@ contexts:
499499
scope: constant.language.null.coffee
500500

501501
numbers:
502-
- match: \b(0b)([01]+)\b
502+
- match: (0b)({{bin_digit}}+)\b
503503
scope: meta.number.integer.binary.coffee
504504
captures:
505505
1: constant.numeric.base.coffee
506506
2: constant.numeric.value.coffee
507-
- match: \b(0o)([0-7]+)\b
507+
- match: (0o)({{oct_digit}}+)\b
508508
scope: meta.number.integer.octal.coffee
509509
captures:
510510
1: constant.numeric.base.coffee
511511
2: constant.numeric.value.coffee
512-
- match: \b(0x)(\h+)\b
512+
- match: (0x)({{hex_digit}}+)\b
513513
scope: meta.number.integer.hexadecimal.coffee
514514
captures:
515515
1: constant.numeric.base.coffee
516516
2: constant.numeric.value.coffee
517-
- match: \b\d+(?:(\.)\d*(?:e[-+]?\d+)?|(?:e[-+]?\d+))\b
517+
# floats
518+
- match: |-
519+
(?x:
520+
# 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1 | 1e1, 1e-1
521+
{{dec_integer}} (?: (\.) {{dec_digit}}* (?:{{dec_exponent}})? | {{dec_exponent}} )
522+
# .1, .1e1, .1e-1
523+
| (\.) {{dec_digit}}+ (?:{{dec_exponent}})?
524+
)\b
518525
scope: meta.number.float.decimal.coffee constant.numeric.value.coffee
519526
captures:
520527
1: punctuation.separator.decimal.coffee
521-
- match: \b\d+\b
528+
2: punctuation.separator.decimal.coffee
529+
- match: '{{dec_integer}}\b'
522530
scope: meta.number.integer.decimal.coffee constant.numeric.value.coffee
523531

524532
triple-double-quoted-strings:
@@ -865,6 +873,13 @@ variables:
865873
# in embed...escape statements.
866874
no_escape_behind: (?<![^\\]\\)(?<![\\]{3})
867875

876+
bin_digit: '[01_]'
877+
oct_digit: '[0-7_]'
878+
dec_digit: '[0-9_]'
879+
hex_digit: '[\h_]'
880+
dec_integer: (?:0|[1-9]{{dec_digit}}*)
881+
dec_exponent: '[Ee](?:[-+]|(?![-+])){{dec_digit}}*'
882+
868883
identifier: '[[:alpha:]_$]\w*'
869884

870885
component_names: '[A-Z][[:alnum:]_.-]*'

tests/syntax_test_scope.coffee

+6-1
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,17 @@ class App.Router extends Snakeskin.Router
547547

548548
10.e5
549549
# ^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
550+
# ^ punctuation.separator.decimal.coffee
550551

551-
10.23
552+
10.23 .23
552553
# ^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
554+
# ^ punctuation.separator.decimal.coffee
555+
# ^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
556+
# ^ punctuation.separator.decimal.coffee
553557

554558
10.23e-5
555559
# ^^^^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
560+
# ^ punctuation.separator.decimal.coffee
556561

557562
52
558563
# ^^ meta.number.integer.decimal.coffee constant.numeric.value.coffee

0 commit comments

Comments
 (0)