Skip to content

Commit

Permalink
Fix number patterns
Browse files Browse the repository at this point in the history
Fixes #253

Syncs number patterns with ST's core JavaScript syntax.
  • Loading branch information
deathaxe committed Sep 10, 2024
1 parent d354634 commit 008a045
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
25 changes: 20 additions & 5 deletions CoffeeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -499,26 +499,34 @@ contexts:
scope: constant.language.null.coffee

numbers:
- match: \b(0b)([01]+)\b
- match: (0b)({{bin_digit}}+)\b
scope: meta.number.integer.binary.coffee
captures:
1: constant.numeric.base.coffee
2: constant.numeric.value.coffee
- match: \b(0o)([0-7]+)\b
- match: (0o)({{oct_digit}}+)\b
scope: meta.number.integer.octal.coffee
captures:
1: constant.numeric.base.coffee
2: constant.numeric.value.coffee
- match: \b(0x)(\h+)\b
- match: (0x)({{hex_digit}}+)\b
scope: meta.number.integer.hexadecimal.coffee
captures:
1: constant.numeric.base.coffee
2: constant.numeric.value.coffee
- match: \b\d+(?:(\.)\d*(?:e[-+]?\d+)?|(?:e[-+]?\d+))\b
# floats
- match: |-
(?x:
# 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1 | 1e1, 1e-1
{{dec_integer}} (?: (\.) {{dec_digit}}* (?:{{dec_exponent}})? | {{dec_exponent}} )
# .1, .1e1, .1e-1
| (\.) {{dec_digit}}+ (?:{{dec_exponent}})?
)\b
scope: meta.number.float.decimal.coffee constant.numeric.value.coffee
captures:
1: punctuation.separator.decimal.coffee
- match: \b\d+\b
2: punctuation.separator.decimal.coffee
- match: '{{dec_integer}}\b'
scope: meta.number.integer.decimal.coffee constant.numeric.value.coffee

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

bin_digit: '[01_]'
oct_digit: '[0-7_]'
dec_digit: '[0-9_]'
hex_digit: '[\h_]'
dec_integer: (?:0|[1-9]{{dec_digit}}*)
dec_exponent: '[Ee](?:[-+]|(?![-+])){{dec_digit}}*'

identifier: '[[:alpha:]_$]\w*'

component_names: '[A-Z][[:alnum:]_.-]*'
Expand Down
7 changes: 6 additions & 1 deletion tests/syntax_test_scope.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,17 @@ class App.Router extends Snakeskin.Router

10.e5
# ^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
# ^ punctuation.separator.decimal.coffee

10.23
10.23 .23
# ^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
# ^ punctuation.separator.decimal.coffee
# ^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
# ^ punctuation.separator.decimal.coffee

10.23e-5
# ^^^^^^^^ meta.number.float.decimal.coffee constant.numeric.value.coffee
# ^ punctuation.separator.decimal.coffee

52
# ^^ meta.number.integer.decimal.coffee constant.numeric.value.coffee
Expand Down

0 comments on commit 008a045

Please sign in to comment.