Matt Godbolt | 895bfd5 | 2019-05-30 16:33:07 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018, Compiler Explorer Authors |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer in the |
| 11 | // documentation and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | // POSSIBILITY OF SUCH DAMAGE. |
Austin Morton | de85aec | 2020-09-27 00:20:19 -0400 | [diff] [blame] | 24 | |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 25 | 'use strict'; |
RabsRincon | 8015e5f | 2019-07-22 15:15:58 +0200 | [diff] [blame] | 26 | var monaco = require('monaco-editor'); |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 27 | |
| 28 | function definition() { |
| 29 | return { |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 30 | keywords: [ |
Partouf | d700dfb | 2018-10-06 23:13:03 +0200 | [diff] [blame] | 31 | 'module', 'import', 'Start', 'where', 'otherwise', |
Partouf | 6e335bd | 2018-10-07 03:37:53 +0200 | [diff] [blame] | 32 | 'definition', 'implementation', 'from', 'class', 'instance', 'abort', |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 33 | 'infix', 'infixl', 'infixr', 'if', 'True', 'False', |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 34 | ], |
| 35 | |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 36 | builtintypes: [ |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 37 | 'Int', 'Real', 'String', 'Char', 'Complex', 'Bool', |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 38 | ], |
| 39 | |
| 40 | operators: [ |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 41 | '=', '==', '>=', '<=', '+', '-', '*', '/', '::', ':==', '->', '=:', '=>', '|', '\\\\', |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 42 | ], |
| 43 | |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 44 | numbers: /-?[0-9.]/, |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 45 | |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 46 | tokenizer: { |
| 47 | root: [ |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 48 | { include: '@whitespace' }, |
| 49 | |
| 50 | [/->/, 'operators'], |
| 51 | |
| 52 | [/\|/, 'operators'], |
| 53 | |
| 54 | [/(\w*)(\s?)(::)/, ['keyword', 'white', 'operators']], |
| 55 | |
Partouf | a6becd2 | 2018-10-07 00:13:47 +0200 | [diff] [blame] | 56 | [/[+\-*/=<>\\]/, 'operators'], |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 57 | |
| 58 | [/[a-zA-Z_][a-zA-Z0-9_]*/, { |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 59 | cases: { |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 60 | '@builtintypes': 'type', |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 61 | '@keywords': 'keyword', |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 62 | '@default': '', |
| 63 | }, |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 64 | }], |
| 65 | |
Partouf | d700dfb | 2018-10-06 23:13:03 +0200 | [diff] [blame] | 66 | [/[()[\],:]/, 'delimiter'], |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 67 | |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 68 | [/@numbers/, 'number'], |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 69 | |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 70 | [/(")(.*)(")/, ['string', 'string', 'string']], |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 71 | ], |
| 72 | |
| 73 | comment: [ |
| 74 | [/[^/*]+/, 'comment'], |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 75 | [/\*\//, 'comment', '@pop'], |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 76 | [/[/*]/, 'comment'], |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 77 | ], |
| 78 | |
| 79 | whitespace: [ |
| 80 | [/[ \t\r\n]+/, 'white'], |
| 81 | [/\/\*/, 'comment', '@comment'], |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 82 | [/\/\/.*$/, 'comment'], |
| 83 | ], |
| 84 | }, |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 85 | }; |
| 86 | } |
| 87 | |
Partouf | 0f5a89f | 2018-10-06 22:39:46 +0200 | [diff] [blame] | 88 | monaco.languages.register({ id: 'clean' }); |
Partouf | 706f408 | 2018-10-06 18:05:45 +0200 | [diff] [blame] | 89 | monaco.languages.setMonarchTokensProvider('clean', definition()); |