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