Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ruby] Meta Numbers #2462

Merged
merged 3 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 81 additions & 64 deletions Ruby/Ruby.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ first_line_match: |-
)
scope: source.ruby
variables:
bdigits: (?:[01]+(?:_[01]+)*)
ddigits: (?:\d+(?:_\d+)*)
hdigits: (?:\h+(?:_\h+)*)
odigits: (?:[0-7]+(?:_[0-7]+)*)
exponent: (?:[Ee][-+]?{{ddigits}})
bin_digits: (?:[01]+(?:_[01]+)*)
dec_digits: (?:\d+(?:_\d+)*)
hex_digits: (?:\h+(?:_\h+)*)
oct_digits: (?:[0-7]+(?:_[0-7]+)*)
dec_exponent: (?:[Ee][-+]?{{dec_digits}})
heredoc_type_css: (?:[[:upper:]_]_)?CSS\b
heredoc_type_html: (?:[[:upper:]_]_)?HTML\b
heredoc_type_js: (?:[[:upper:]_]_)?(?:JS|JAVASCRIPT)\b
Expand Down Expand Up @@ -206,97 +206,114 @@ contexts:
- match: '\b(__(FILE|LINE|ENCODING)__|self)\b(?![?!])'
scope: variable.language.ruby
# hexadecimal imaginary numbers: 0xAi, 0xAri
- match: '\b(0[xX]){{hdigits}}(r?i)(r)?\b'
scope: constant.numeric.imaginary.hexadecimal.ruby
- match: '\b(0[xX])({{hex_digits}})(r?i(r)?)\b'
scope: meta.number.imaginary.hexadecimal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: storage.type.numeric.ruby
3: invalid.illegal.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.suffix.ruby
4: invalid.illegal.numeric.ruby
# octal imaginary numbers: 0o1i, 0o1ri, 01i, 01ri
- match: '\b(0[oO]?){{odigits}}(r?i)(r)?\b'
scope: constant.numeric.imaginary.octal.ruby
- match: '\b(0[oO]?)({{oct_digits}})(r?i(r)?)\b'
scope: meta.number.imaginary.octal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: storage.type.numeric.ruby
3: invalid.illegal.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.suffix.ruby
4: invalid.illegal.numeric.ruby
# binary imaginary numbers: 0b1i, 0b1ri
- match: '\b(0[bB]){{bdigits}}(r?i)(r)?\b'
scope: constant.numeric.imaginary.binary.ruby
- match: '\b(0[bB])({{bin_digits}})(r?i(r)?)\b'
scope: meta.number.imaginary.binary.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: storage.type.numeric.ruby
3: invalid.illegal.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.suffix.ruby
4: invalid.illegal.numeric.ruby
# decimal imaginary numbers: 0d1i, 0d1ri, 1i, 1ri, 1.1i, 1.1ri, 1e1i, 1.1e1i
- match: |-
\b(?x:
(?:
# 0d1i, 0d1ri, 1i, 1ri | 1.1i, 1.1ri
(?: (0[dD])? {{ddigits}} | {{ddigits}} (\.) {{ddigits}} ) (r?i)
(?: (0[dD])? ({{dec_digits}}) | ({{dec_digits}} (\.) {{dec_digits}}) ) (r?i)
# 1e1i, 1.1e1i
| {{ddigits}} (?: (\.) {{ddigits}} )? {{exponent}} (r)? (i)
| ({{dec_digits}} (?: (\.) {{dec_digits}} )? {{dec_exponent}}) (r)?(i)
) (r)?
)\b
scope: constant.numeric.imaginary.decimal.ruby
scope: meta.number.imaginary.decimal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: punctuation.separator.decimal.ruby
3: storage.type.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.value.ruby
4: punctuation.separator.decimal.ruby
5: invalid.illegal.numeric.ruby
6: storage.type.numeric.ruby
7: invalid.illegal.numeric.ruby
5: constant.numeric.suffix.ruby
6: constant.numeric.value.ruby
7: punctuation.separator.decimal.ruby
8: constant.numeric.suffix.ruby invalid.illegal.numeric.ruby
9: constant.numeric.suffix.ruby
10: constant.numeric.suffix.ruby invalid.illegal.numeric.ruby
# hexadecimal rational numbers: 0xAr
- match: '\b(0[xX]){{hdigits}}(r)\b'
scope: constant.numeric.rational.hexadecimal.ruby
- match: '\b(0[xX])({{hex_digits}})(r)\b'
scope: meta.number.rational.hexadecimal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: storage.type.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.suffix.ruby
# octal rational numbers: 0o1r, 01r
- match: '\b(0[oO]?){{odigits}}(r)\b'
scope: constant.numeric.rational.octal.ruby
- match: '\b(0[oO]?)({{oct_digits}})(r)\b'
scope: meta.number.rational.octal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: storage.type.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.suffix.ruby
# binary rational numbers: 0b1r
- match: '\b(0[bB]){{bdigits}}(r)\b'
scope: constant.numeric.rational.binary.ruby
- match: '\b(0[bB])({{bin_digits}})(r)\b'
scope: meta.number.rational.binary.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: storage.type.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: constant.numeric.suffix.ruby
# decimal rational numbers: 0d1r, 1r, 1.1r
- match: '\b(?:(0[dD])?{{ddigits}}|{{ddigits}}(\.){{ddigits}})(r)\b'
scope: constant.numeric.rational.decimal.ruby
- match: '\b(0[dD])?({{dec_digits}}|{{dec_digits}}(\.){{dec_digits}})(r)\b'
scope: meta.number.rational.decimal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
2: punctuation.separator.decimal.ruby
3: storage.type.numeric.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
3: punctuation.separator.decimal.ruby
4: constant.numeric.suffix.ruby
# decimal floating point numbers: 1.1, 1e1, 1.1e1
- match: '\b{{ddigits}}(?:(\.){{ddigits}}|(?:(\.){{ddigits}})?{{exponent}}(r)?)\b'
scope: constant.numeric.float.decimal.ruby
- match: '\b({{dec_digits}})(?:((\.){{dec_digits}})|((?:(\.){{dec_digits}})?{{dec_exponent}})(r)?)\b'
scope: meta.number.float.decimal.ruby
captures:
1: punctuation.separator.decimal.ruby
2: punctuation.separator.decimal.ruby
3: invalid.illegal.numeric.rational.ruby
1: constant.numeric.value.ruby
2: constant.numeric.value.ruby
3: punctuation.separator.decimal.ruby
4: constant.numeric.value.ruby
5: punctuation.separator.decimal.ruby
6: constant.numeric.suffix.ruby invalid.illegal.numeric.rational.ruby
# hexadecimal integer numbers: 0xA
- match: '\b(0[xX]){{hdigits}}\b'
scope: constant.numeric.integer.hexadecimal.ruby
- match: '\b(0[xX])({{hex_digits}})\b'
scope: meta.number.integer.hexadecimal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
# octal integer numbers: 0o1, 01
- match: '\b(0[oO]?){{odigits}}\b'
scope: constant.numeric.integer.octal.ruby
- match: '\b(0[oO]?)({{oct_digits}})\b'
scope: meta.number.integer.octal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
# binary integer numbers: 0b1
- match: '\b(0[bB]){{bdigits}}\b'
scope: constant.numeric.integer.binary.ruby
- match: '\b(0[bB])({{bin_digits}})\b'
scope: meta.number.integer.binary.ruby
captures:
1: punctuation.definition.numeric.base.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
# decimal integer numbers: 0d1, 1
- match: '\b(0[dD])?{{ddigits}}\b'
scope: constant.numeric.integer.decimal.ruby
- match: '\b(0[dD])?({{dec_digits}})\b'
scope: meta.number.integer.decimal.ruby
captures:
1: punctuation.definition.numeric.base.ruby
1: constant.numeric.base.ruby
2: constant.numeric.value.ruby
# Quoted symbols
- match: ":'"
scope: punctuation.definition.constant.ruby
Expand Down Expand Up @@ -350,7 +367,7 @@ contexts:
scope: meta.braces.ruby punctuation.section.braces.end.ruby
pop: true
- match: \h{0,6}
scope: constant.numeric.integer.hexadecimal.ruby
scope: meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby
- match: \S
scope: invalid.illegal.escape.ruby
- match: |-
Expand Down
Loading