[d24f17c] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | module.exports = ocaml
|
---|
| 4 | ocaml.displayName = 'ocaml'
|
---|
| 5 | ocaml.aliases = []
|
---|
| 6 | function ocaml(Prism) {
|
---|
| 7 | // https://ocaml.org/manual/lex.html
|
---|
| 8 | Prism.languages.ocaml = {
|
---|
| 9 | comment: {
|
---|
| 10 | pattern: /\(\*[\s\S]*?\*\)/,
|
---|
| 11 | greedy: true
|
---|
| 12 | },
|
---|
| 13 | char: {
|
---|
| 14 | pattern: /'(?:[^\\\r\n']|\\(?:.|[ox]?[0-9a-f]{1,3}))'/i,
|
---|
| 15 | greedy: true
|
---|
| 16 | },
|
---|
| 17 | string: [
|
---|
| 18 | {
|
---|
| 19 | pattern: /"(?:\\(?:[\s\S]|\r\n)|[^\\\r\n"])*"/,
|
---|
| 20 | greedy: true
|
---|
| 21 | },
|
---|
| 22 | {
|
---|
| 23 | pattern: /\{([a-z_]*)\|[\s\S]*?\|\1\}/,
|
---|
| 24 | greedy: true
|
---|
| 25 | }
|
---|
| 26 | ],
|
---|
| 27 | number: [
|
---|
| 28 | // binary and octal
|
---|
| 29 | /\b(?:0b[01][01_]*|0o[0-7][0-7_]*)\b/i, // hexadecimal
|
---|
| 30 | /\b0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]*)?(?:p[+-]?\d[\d_]*)?(?!\w)/i, // decimal
|
---|
| 31 | /\b\d[\d_]*(?:\.[\d_]*)?(?:e[+-]?\d[\d_]*)?(?!\w)/i
|
---|
| 32 | ],
|
---|
| 33 | directive: {
|
---|
| 34 | pattern: /\B#\w+/,
|
---|
| 35 | alias: 'property'
|
---|
| 36 | },
|
---|
| 37 | label: {
|
---|
| 38 | pattern: /\B~\w+/,
|
---|
| 39 | alias: 'property'
|
---|
| 40 | },
|
---|
| 41 | 'type-variable': {
|
---|
| 42 | pattern: /\B'\w+/,
|
---|
| 43 | alias: 'function'
|
---|
| 44 | },
|
---|
| 45 | variant: {
|
---|
| 46 | pattern: /`\w+/,
|
---|
| 47 | alias: 'symbol'
|
---|
| 48 | },
|
---|
| 49 | // For the list of keywords and operators,
|
---|
| 50 | // see: http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sec84
|
---|
| 51 | keyword:
|
---|
| 52 | /\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/,
|
---|
| 53 | boolean: /\b(?:false|true)\b/,
|
---|
| 54 | 'operator-like-punctuation': {
|
---|
| 55 | pattern: /\[[<>|]|[>|]\]|\{<|>\}/,
|
---|
| 56 | alias: 'punctuation'
|
---|
| 57 | },
|
---|
| 58 | // Custom operators are allowed
|
---|
| 59 | operator:
|
---|
| 60 | /\.[.~]|:[=>]|[=<>@^|&+\-*\/$%!?~][!$%&*+\-.\/:<=>?@^|~]*|\b(?:and|asr|land|lor|lsl|lsr|lxor|mod|or)\b/,
|
---|
| 61 | punctuation: /;;|::|[(){}\[\].,:;#]|\b_\b/
|
---|
| 62 | }
|
---|
| 63 | }
|
---|