blob: ddc691c2d060576db85c13fb02162696a640542a [file] [log] [blame] [raw]
Matt Godbolt895bfd52019-05-30 16:33:07 -05001// Copyright (c) 2018, Compiler Explorer Authors
Partouf706f4082018-10-06 18:05:45 +02002// 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 Mortonde85aec2020-09-27 00:20:19 -040024
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020025'use strict';
RabsRincon8015e5f2019-07-22 15:15:58 +020026var monaco = require('monaco-editor');
Partouf706f4082018-10-06 18:05:45 +020027
28function definition() {
29 return {
Partouf706f4082018-10-06 18:05:45 +020030 keywords: [
Partoufd700dfb2018-10-06 23:13:03 +020031 'module', 'import', 'Start', 'where', 'otherwise',
Partouf6e335bd2018-10-07 03:37:53 +020032 'definition', 'implementation', 'from', 'class', 'instance', 'abort',
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020033 'infix', 'infixl', 'infixr', 'if', 'True', 'False',
Partouf706f4082018-10-06 18:05:45 +020034 ],
35
Partouf0f5a89f2018-10-06 22:39:46 +020036 builtintypes: [
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020037 'Int', 'Real', 'String', 'Char', 'Complex', 'Bool',
Partouf706f4082018-10-06 18:05:45 +020038 ],
39
40 operators: [
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020041 '=', '==', '>=', '<=', '+', '-', '*', '/', '::', ':==', '->', '=:', '=>', '|', '\\\\',
Partouf706f4082018-10-06 18:05:45 +020042 ],
43
Partouf0f5a89f2018-10-06 22:39:46 +020044 numbers: /-?[0-9.]/,
Partouf706f4082018-10-06 18:05:45 +020045
Partouf706f4082018-10-06 18:05:45 +020046 tokenizer: {
47 root: [
Partouf0f5a89f2018-10-06 22:39:46 +020048 { include: '@whitespace' },
49
50 [/->/, 'operators'],
51
52 [/\|/, 'operators'],
53
54 [/(\w*)(\s?)(::)/, ['keyword', 'white', 'operators']],
55
Partoufa6becd22018-10-07 00:13:47 +020056 [/[+\-*/=<>\\]/, 'operators'],
Partouf0f5a89f2018-10-06 22:39:46 +020057
58 [/[a-zA-Z_][a-zA-Z0-9_]*/, {
Partouf706f4082018-10-06 18:05:45 +020059 cases: {
Partouf0f5a89f2018-10-06 22:39:46 +020060 '@builtintypes': 'type',
Partouf706f4082018-10-06 18:05:45 +020061 '@keywords': 'keyword',
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020062 '@default': '',
63 },
Partouf706f4082018-10-06 18:05:45 +020064 }],
65
Partoufd700dfb2018-10-06 23:13:03 +020066 [/[()[\],:]/, 'delimiter'],
Partouf706f4082018-10-06 18:05:45 +020067
Partouf0f5a89f2018-10-06 22:39:46 +020068 [/@numbers/, 'number'],
Partouf706f4082018-10-06 18:05:45 +020069
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020070 [/(")(.*)(")/, ['string', 'string', 'string']],
Partouf706f4082018-10-06 18:05:45 +020071 ],
72
73 comment: [
74 [/[^/*]+/, 'comment'],
Partouf0f5a89f2018-10-06 22:39:46 +020075 [/\*\//, 'comment', '@pop'],
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020076 [/[/*]/, 'comment'],
Partouf706f4082018-10-06 18:05:45 +020077 ],
78
79 whitespace: [
80 [/[ \t\r\n]+/, 'white'],
81 [/\/\*/, 'comment', '@comment'],
Rubén Rincón Blancoccff4b92020-08-04 22:39:02 +020082 [/\/\/.*$/, 'comment'],
83 ],
84 },
Partouf706f4082018-10-06 18:05:45 +020085 };
86}
87
Partouf0f5a89f2018-10-06 22:39:46 +020088monaco.languages.register({ id: 'clean' });
Partouf706f4082018-10-06 18:05:45 +020089monaco.languages.setMonarchTokensProvider('clean', definition());