OCaml: Improvements (#2179)
- Added some missing keywords - Added highlighting for modules, labels, and constructors - Split polymorphic variant types and type variables
This commit is contained in:
parent
e5678a000f
commit
2a570fd49f
|
@ -11,17 +11,31 @@ Prism.languages.ocaml = {
|
|||
}
|
||||
],
|
||||
'number': /\b(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*\.?[\d_]*(?:e[+-]?[\d_]+)?)/i,
|
||||
'type': {
|
||||
pattern: /\B['`]\w*/,
|
||||
alias: 'variable'
|
||||
},
|
||||
'directive': {
|
||||
pattern: /\B#\w+/,
|
||||
alias: 'important'
|
||||
},
|
||||
'label': {
|
||||
pattern: /\B~\w+/,
|
||||
alias: 'function'
|
||||
},
|
||||
'keyword': /\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|object|of|open|prefix|private|rec|then|sig|struct|to|try|type|val|value|virtual|where|while|with)\b/,
|
||||
'type_variable': {
|
||||
pattern: /\B'\w+/,
|
||||
alias: 'function'
|
||||
},
|
||||
'variant': {
|
||||
pattern: /`\w+/,
|
||||
alias: 'variable'
|
||||
},
|
||||
'module': {
|
||||
pattern: /\b[A-Z]\w+/,
|
||||
alias: 'variable'
|
||||
},
|
||||
// For the list of keywords and operators,
|
||||
// see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
|
||||
'keyword': /\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,
|
||||
'boolean': /\b(?:false|true)\b/,
|
||||
// Custom operators are allowed
|
||||
'operator': /:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lxor|lsl|lsr|mod|nor|or)\b/,
|
||||
'operator': /:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
|
||||
'punctuation': /[(){}\[\]|_.,:;]/
|
||||
};
|
|
@ -1 +1 @@
|
|||
Prism.languages.ocaml={comment:/\(\*[\s\S]*?\*\)/,string:[{pattern:/"(?:\\.|[^\\\r\n"])*"/,greedy:!0},{pattern:/(['`])(?:\\(?:\d+|x[\da-f]+|.)|(?!\1)[^\\\r\n])\1/i,greedy:!0}],number:/\b(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*\.?[\d_]*(?:e[+-]?[\d_]+)?)/i,type:{pattern:/\B['`]\w*/,alias:"variable"},directive:{pattern:/\B#\w+/,alias:"function"},keyword:/\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|object|of|open|prefix|private|rec|then|sig|struct|to|try|type|val|value|virtual|where|while|with)\b/,boolean:/\b(?:false|true)\b/,operator:/:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lxor|lsl|lsr|mod|nor|or)\b/,punctuation:/[(){}\[\]|_.,:;]/};
|
||||
Prism.languages.ocaml={comment:/\(\*[\s\S]*?\*\)/,string:[{pattern:/"(?:\\.|[^\\\r\n"])*"/,greedy:!0},{pattern:/(['`])(?:\\(?:\d+|x[\da-f]+|.)|(?!\1)[^\\\r\n])\1/i,greedy:!0}],number:/\b(?:0x[\da-f][\da-f_]+|(?:0[bo])?\d[\d_]*\.?[\d_]*(?:e[+-]?[\d_]+)?)/i,directive:{pattern:/\B#\w+/,alias:"important"},label:{pattern:/\B~\w+/,alias:"function"},type_variable:{pattern:/\B'\w+/,alias:"function"},variant:{pattern:/`\w+/,alias:"variable"},module:{pattern:/\b[A-Z]\w+/,alias:"variable"},keyword:/\b(?:as|assert|begin|class|constraint|do|done|downto|else|end|exception|external|for|fun|function|functor|if|in|include|inherit|initializer|lazy|let|match|method|module|mutable|new|nonrec|object|of|open|private|rec|sig|struct|then|to|try|type|val|value|virtual|when|where|while|with)\b/,boolean:/\b(?:false|true)\b/,operator:/:=|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,punctuation:/[(){}\[\]|_.,:;]/};
|
|
@ -9,7 +9,8 @@ comment *)</code></pre>
|
|||
42.
|
||||
2.4E+2
|
||||
10_452_102
|
||||
0xf4 0xff_10_41
|
||||
0xf4
|
||||
0xff_10_41
|
||||
0o427
|
||||
0b1100_1111_0000</code></pre>
|
||||
|
||||
|
@ -29,7 +30,7 @@ comment *)</code></pre>
|
|||
|
||||
(** [create low high] creates a new interval from [low] to
|
||||
[high]. If [low > high], then the interval is empty *)
|
||||
let create low high =
|
||||
let create ~low ~high =
|
||||
if Endpoint.compare low high > 0 then Empty
|
||||
else Interval (low,high)
|
||||
|
||||
|
@ -54,6 +55,6 @@ comment *)</code></pre>
|
|||
match t1,t2 with
|
||||
| Empty, _ | _, Empty -> Empty
|
||||
| Interval (l1,h1), Interval (l2,h2) ->
|
||||
create (max l1 l2) (min h1 h2)
|
||||
create ~low:(max l1 l2) ~high:(min h1 h2)
|
||||
|
||||
end ;;</code></pre>
|
||||
|
|
|
@ -26,21 +26,22 @@ method
|
|||
module
|
||||
mutable
|
||||
new
|
||||
nonrec
|
||||
object
|
||||
of
|
||||
open
|
||||
prefix
|
||||
private
|
||||
rec
|
||||
then
|
||||
sig
|
||||
struct
|
||||
then
|
||||
to
|
||||
try
|
||||
type
|
||||
val
|
||||
value
|
||||
virtual
|
||||
when
|
||||
where
|
||||
while
|
||||
with
|
||||
|
@ -76,21 +77,22 @@ with
|
|||
["keyword", "module"],
|
||||
["keyword", "mutable"],
|
||||
["keyword", "new"],
|
||||
["keyword", "nonrec"],
|
||||
["keyword", "object"],
|
||||
["keyword", "of"],
|
||||
["keyword", "open"],
|
||||
["keyword", "prefix"],
|
||||
["keyword", "private"],
|
||||
["keyword", "rec"],
|
||||
["keyword", "then"],
|
||||
["keyword", "sig"],
|
||||
["keyword", "struct"],
|
||||
["keyword", "then"],
|
||||
["keyword", "to"],
|
||||
["keyword", "try"],
|
||||
["keyword", "type"],
|
||||
["keyword", "val"],
|
||||
["keyword", "value"],
|
||||
["keyword", "virtual"],
|
||||
["keyword", "when"],
|
||||
["keyword", "where"],
|
||||
["keyword", "while"],
|
||||
["keyword", "with"]
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
~foo
|
||||
~bar_42
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["label", "~foo"],
|
||||
["label", "~bar_42"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for labels.
|
|
@ -0,0 +1,15 @@
|
|||
Foo
|
||||
Bar42
|
||||
Baz_42
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["module", "Foo"],
|
||||
["module", "Bar42"],
|
||||
["module", "Baz_42"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for modules.
|
|
@ -1,3 +1,5 @@
|
|||
1234
|
||||
32.
|
||||
0xBad_Face
|
||||
0o754_672
|
||||
0b1010_1111
|
||||
|
@ -10,6 +12,8 @@
|
|||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["number", "1234"],
|
||||
["number", "32."],
|
||||
["number", "0xBad_Face"],
|
||||
["number", "0o754_672"],
|
||||
["number", "0b1010_1111"],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
and asr land
|
||||
lor lxor lsl lsr
|
||||
mod nor or
|
||||
lor lsl lsr
|
||||
lxor mod or
|
||||
|
||||
:=
|
||||
= < > @
|
||||
|
@ -14,8 +14,8 @@ $ % ! ?
|
|||
|
||||
[
|
||||
["operator", "and"], ["operator", "asr"], ["operator", "land"],
|
||||
["operator", "lor"], ["operator", "lxor"], ["operator", "lsl"], ["operator", "lsr"],
|
||||
["operator", "mod"], ["operator", "nor"], ["operator", "or"],
|
||||
["operator", "lor"], ["operator", "lsl"], ["operator", "lsr"],
|
||||
["operator", "lxor"], ["operator", "mod"], ["operator", "or"],
|
||||
|
||||
["operator", ":="],
|
||||
["operator", "="], ["operator", "<"], ["operator", ">"], ["operator", "@"],
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
'Foo
|
||||
'bar_42
|
||||
`Foo
|
||||
`bar_42
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["type", "'Foo"],
|
||||
["type", "'bar_42"],
|
||||
["type", "`Foo"],
|
||||
["type", "`bar_42"]
|
||||
["type_variable", "'Foo"],
|
||||
["type_variable", "'bar_42"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for types.
|
||||
Checks for type variables.
|
|
@ -0,0 +1,15 @@
|
|||
`Foo
|
||||
`bar32
|
||||
`Baz_42
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["variant", "`Foo"],
|
||||
["variant", "`bar32"],
|
||||
["variant", "`Baz_42"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for polymorphic variants.
|
Loading…
Reference in New Issue