Skip to content

Commit

Permalink
[OCaml] Add meta.number (sublimehq#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminSchaaf authored and mitranim committed Mar 20, 2022
1 parent 7813385 commit 29bc1d9
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 66 deletions.
64 changes: 38 additions & 26 deletions OCaml/OCaml.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -414,53 +414,65 @@ contexts:

# http://caml.inria.fr/pub/docs/manual-ocaml/lex.html
# hexadecimal floats
- match: ({{sign}})(0[xX])(_*){{hex_integer}}(?:(\.){{hex_digit}}*{{hex_exponent}}?|{{hex_exponent}})
scope: constant.numeric.float.hexadecimal.ocaml
- match: ({{sign}})(0[xX])(_*)({{hex_integer}})(?:(\.)({{hex_digit}}*)({{hex_exponent}})?|({{hex_exponent}}))
scope: meta.number.float.hexadecimal.ocaml
captures:
1: punctuation.definition.numeric.sign.ocaml
2: punctuation.definition.numeric.base.ocaml
2: constant.numeric.base.ocaml
3: invalid.illegal.numeric.ocaml
4: punctuation.separator.decimal.ocaml
5: invalid.illegal.numeric.ocaml
6: invalid.illegal.numeric.ocaml
4: constant.numeric.value.ocaml
5: punctuation.separator.decimal.ocaml
6: constant.numeric.value.ocaml
7: constant.numeric.value.exponent.ocaml
8: invalid.illegal.numeric.ocaml
9: constant.numeric.value.exponent.ocaml
10: invalid.illegal.numeric.ocaml
# decimal floats
- match: ({{sign}}){{dec_integer}}(?:(\.){{dec_digit}}*{{dec_exponent}}?|{{dec_exponent}})
scope: constant.numeric.float.decimal.ocaml
- match: ({{sign}})({{dec_integer}})(?:(\.)({{dec_digit}}*)({{dec_exponent}})?|({{dec_exponent}}))
scope: meta.number.float.decimal.ocaml
captures:
1: punctuation.definition.numeric.sign.ocaml
2: punctuation.separator.decimal.ocaml
3: invalid.illegal.numeric.ocaml
4: invalid.illegal.numeric.ocaml
2: constant.numeric.value.ocaml
3: punctuation.separator.decimal.ocaml
4: constant.numeric.value.ocaml
5: constant.numeric.value.exponent.ocaml
6: invalid.illegal.numeric.ocaml
7: constant.numeric.value.exponent.ocaml
8: invalid.illegal.numeric.ocaml
# hexadecimal integers
- match: ({{sign}})(0[xX])(_*){{hex_integer}}*({{suffix}})
scope: constant.numeric.integer.hexadecimal.ocaml
- match: ({{sign}})(0[xX])(_*)({{hex_integer}}*)({{suffix}})
scope: meta.number.integer.hexadecimal.ocaml
captures:
1: punctuation.definition.numeric.sign.ocaml
2: punctuation.definition.numeric.base.ocaml
2: constant.numeric.base.ocaml
3: invalid.illegal.numeric.ocaml
4: storage.type.numeric.ocaml
4: constant.numeric.value.ocaml
5: constant.numeric.suffix.ocaml
# octal integers
- match: ({{sign}})(0[oO])(_*){{oct_integer}}*({{suffix}})
scope: constant.numeric.integer.octal.ocaml
- match: ({{sign}})(0[oO])(_*)({{oct_integer}}*)({{suffix}})
scope: meta.number.integer.octal.ocaml
captures:
1: punctuation.definition.numeric.sign.ocaml
2: punctuation.definition.numeric.base.ocaml
2: constant.numeric.base.ocaml
3: invalid.illegal.numeric.ocaml
4: storage.type.numeric.ocaml
4: constant.numeric.value.ocaml
5: constant.numeric.suffix.ocaml
# binary integers
- match: ({{sign}})(0[bB])(_*){{bin_integer}}*({{suffix}})
scope: constant.numeric.integer.binary.ocaml
- match: ({{sign}})(0[bB])(_*)({{bin_integer}}*)({{suffix}})
scope: meta.number.integer.binary.ocaml
captures:
1: punctuation.definition.numeric.sign.ocaml
2: punctuation.definition.numeric.base.ocaml
2: constant.numeric.base.ocaml
3: invalid.illegal.numeric.ocaml
4: storage.type.numeric.ocaml
4: constant.numeric.value.ocaml
5: constant.numeric.suffix.ocaml
# decimal integers
- match: ({{sign}}){{dec_integer}}({{suffix}})
scope: constant.numeric.integer.decimal.ocaml
- match: ({{sign}})({{dec_integer}})({{suffix}})
scope: meta.number.integer.decimal.ocaml
captures:
1: punctuation.definition.numeric.sign.ocaml
2: storage.type.numeric.ocaml
2: constant.numeric.value.ocaml
3: constant.numeric.suffix.ocaml
# invalid numbers
- match: '{{sign}}\d+.*\b'
scope: invalid.illegal.numeric.ocaml
Expand Down
111 changes: 71 additions & 40 deletions OCaml/syntax_test_ml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,79 +29,102 @@
(* Integers *)

123_456_789_0n
(* ^^^^^^^^^^^^^^ constant.numeric.integer.decimal *)
(* ^ storage.type.numeric *)
(* ^^^^^^^^^^^^^^ meta.number.integer.decimal.ocaml *)
(* ^^^^^^^^^^^^^ constant.numeric.value.ocaml *)
(* ^ constant.numeric.suffix.ocaml *)

0
(* ^ constant.numeric.integer.decimal *)
(* ^ meta.number.integer.decimal.ocaml constant.numeric.value.ocaml *)

123 .foo
(* ^^^ constant.numeric.integer.decimal *)
(* ^^^^^^ - constant *)
(* ^^^ meta.number.integer.decimal.ocaml constant.numeric.value.ocaml *)
(* ^^^^^^ - meta.number *)

+123 + 123
(* ^ keyword.operator *)
(* ^^^ constant.numeric.integer.decimal - keyword *)
(* ^^^ meta.number.integer.decimal.ocaml constant.numeric.value.ocaml - keyword.ocaml *)
(* ^ keyword.operator *)
(* ^^^ constant.numeric.integer.decimal - keyword *)
(* ^^^ meta.number.integer.decimal.ocaml constant.numeric.value.ocaml - keyword.ocaml *)

-123
(* ^^^^ constant.numeric.integer.decimal - keyword *)
(* ^^^^ meta.number.integer.decimal.ocaml - keyword.ocaml *)
(* ^ punctuation.definition.numeric.sign *)
(* ^^^ constant.numeric.value.ocaml *)

0123456789
(* ^^^^^^^^^^ constant.numeric.integer.decimal *)
(* ^^^^^^^^^^ meta.number.integer.decimal.ocaml constant.numeric.value.ocaml *)

123xyz
(* ^^^^^^ invalid.illegal.numeric *)

0b0110_1001_1001_0110n 0b_10_01
(* ^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.integer.binary *)
(* ^^ punctuation.definition.numeric.base *)
(* ^ storage.type.numeric *)
(* ^^^^^^^^ constant.numeric.integer.binary *)
(* ^^ punctuation.definition.numeric.base *)
(* ^^^^^^^^^^^^^^^^^^^^^^ meta.number.integer.binary.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^^^^^^^^^^^^^^^^^^^ constant.numeric.value.ocaml *)
(* ^ constant.numeric.suffix.ocaml *)
(* ^^^^^^^^ meta.number.integer.binary.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ invalid.illegal.numeric *)
(* ^^^^^ constant.numeric.value.ocaml *)

0o0123_4567n 0O_127
(* ^^^^^^^^^^^^ constant.numeric.integer.octal *)
(* ^^ punctuation.definition.numeric *)
(* ^ storage.type.numeric *)
(* ^^^^^^ constant.numeric.integer.octal *)
(* ^^ punctuation.definition.numeric *)
(* ^^^^^^^^^^^^ meta.number.integer.octal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^^^^^^^^^ constant.numeric.value.ocaml *)
(* ^ constant.numeric.suffix.ocaml *)
(* ^^^^^^ meta.number.integer.octal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ invalid.illegal.numeric *)
(* ^^^ constant.numeric.value.ocaml *)

0x01_23_45_67_89_ab_CD_efn 0X_01l
(* ^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.integer.hexadecimal *)
(* ^^ punctuation.definition.numeric.base *)
(* ^ storage.type.numeric *)
(* ^^^^^^ constant.numeric.integer.hexadecimal *)
(* ^^ punctuation.definition.numeric.base *)
(* ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.number.integer.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.value.ocaml *)
(* ^ constant.numeric.suffix.ocaml *)
(* ^^^^^^ meta.number.integer.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ invalid.illegal.numeric *)
(* ^ storage.type.numeric *)
(* ^^ constant.numeric.value.ocaml *)
(* ^ constant.numeric.suffix.ocaml *)

0b
(* ^^ constant.numeric.integer.binary punctuation.definition.numeric.base *)
(* ^^ meta.number.integer.binary.ocaml constant.numeric.base.ocaml *)

0B0 0O0 0X0
(* ^^^ constant.numeric.integer.binary *)
(* ^^^ constant.numeric.integer.octal *)
(* ^^^ constant.numeric.integer.hexadecimal *)
(* ^^^ meta.number.integer.binary.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ constant.numeric.value.ocaml *)
(* ^^^ meta.number.integer.octal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^^^ meta.number.integer.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ constant.numeric.value.ocaml *)

0xa. 0xa.b 0xa.ep1 0xa.ep-_1
(* ^^^^ constant.numeric.float.hexadecimal *)
(* ^^ punctuation.definition.numeric.base *)
(* ^^^^ meta.number.float.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ constant.numeric.value.ocaml *)
(* ^ punctuation.separator.decimal *)
(* ^^^^^ constant.numeric.float.hexadecimal *)
(* ^^ punctuation.definition.numeric.base *)
(* ^^^^^ meta.number.float.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ constant.numeric.value.ocaml *)
(* ^ punctuation.separator.decimal *)
(* ^^^^^^^ constant.numeric.float.hexadecimal *)
(* ^^ punctuation.definition.numeric.base *)
(* ^ constant.numeric.value.ocaml *)
(* ^^^^^^^ meta.number.float.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ constant.numeric.value.ocaml *)
(* ^ punctuation.separator.decimal *)
(* ^^^^^^^^^ constant.numeric.float.hexadecimal *)
(* ^^ punctuation.definition.numeric.base *)
(* ^ constant.numeric.value.ocaml *)
(* ^^ constant.numeric.value.exponent.ocaml *)
(* ^^^^^^^^^ meta.number.float.hexadecimal.ocaml *)
(* ^^ constant.numeric.base.ocaml *)
(* ^ constant.numeric.value.ocaml *)
(* ^ punctuation.separator.decimal *)
(* ^ constant.numeric.value.ocaml *)
(* ^^ constant.numeric.value.exponent.ocaml *)
(* ^ invalid.illegal.numeric *)
(* ^ constant.numeric.value.exponent.ocaml *)

0b1.foo
(* ^^^^^^^ invalid.illegal.numeric *)
Expand All @@ -116,11 +139,19 @@
(* Floats *)

1_234_567_890.123_456_789_0
(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.float.decimal *)
(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.number.float.decimal.ocaml *)
(* ^^^^^^^^^^^^^ constant.numeric.value.ocaml *)
(* ^ punctuation.separator.decimal.ocaml *)
(* ^^^^^^^^^^^^^ constant.numeric.value.ocaml *)

12345e6_7_8
(* ^^^^^^^^^^^ constant.numeric.float.decimal *)
(* ^^^^^^^^^^^ meta.number.float.decimal.ocaml *)
(* ^^^^^ constant.numeric.value.ocaml *)
(* ^^^^^^ constant.numeric.value.exponent.ocaml *)

123.456e+789
(* ^^^^^^^^^^^^ constant.numeric.float.decimal *)
(* ^^^^^^^^^^^^ meta.number.float.decimal.ocaml *)
(* ^^^ constant.numeric.value.ocaml *)
(* ^ punctuation.separator.decimal *)
(* ^^^ constant.numeric.value.ocaml *)
(* ^^^^^ constant.numeric.value.exponent.ocaml *)

0 comments on commit 29bc1d9

Please sign in to comment.