Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 1 | // Copyright (c) 2021, Compiler Explorer Authors |
| 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. |
| 24 | |
Mats Larsen | 1f5fbe0 | 2022-08-07 11:58:16 +0200 | [diff] [blame] | 25 | import $ from 'jquery'; |
| 26 | |
Rubén Rincón Blanco | 42c7b2b | 2022-02-03 18:04:50 +0100 | [diff] [blame] | 27 | const monaco = require('monaco-editor'); |
| 28 | const cpp = require('monaco-editor/esm/vs/basic-languages/cpp/cpp'); |
| 29 | const cppp = require('./cppp-mode'); |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 30 | |
Matt Godbolt | 8172d95 | 2021-07-25 21:40:45 -0500 | [diff] [blame] | 31 | // circle is c++ with a few extra '@'-prefixed keywords. |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 32 | |
| 33 | function definition() { |
Rubén Rincón Blanco | 42c7b2b | 2022-02-03 18:04:50 +0100 | [diff] [blame] | 34 | const cppcircle = $.extend(true, {}, cppp); // deep copy |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 35 | |
| 36 | function addKeywords(keywords) { |
| 37 | // (Ruben) Done one by one as if you just push them all, Monaco complains that they're not strings, but as |
| 38 | // far as I can tell, they indeed are all strings. This somehow fixes it. If you know how to fix it, plz go |
Rubén Rincón Blanco | 42c7b2b | 2022-02-03 18:04:50 +0100 | [diff] [blame] | 39 | for (let i = 0; i < keywords.length; ++i) { |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 40 | cppcircle.keywords.push(keywords[i]); |
| 41 | } |
| 42 | } |
| 43 | |
Mats Larsen | 4f9a34c | 2022-04-24 19:11:48 +0200 | [diff] [blame] | 44 | addKeywords([ |
| 45 | '@array', |
| 46 | '@attribute', |
| 47 | '@base_count', |
| 48 | '@base_offset', |
| 49 | '@base_offsets', |
| 50 | '@base_type', |
| 51 | '@base_type_string', |
| 52 | '@base_type_strings', |
| 53 | '@base_types', |
| 54 | '@base_value', |
| 55 | '@base_values', |
| 56 | '@codegen', |
| 57 | '@data', |
| 58 | '@decl_string', |
| 59 | '@dynamic_type', |
| 60 | '@embed', |
| 61 | '@emit', |
| 62 | '@enum_attribute', |
| 63 | '@enum_attributes', |
| 64 | '@enum_count', |
| 65 | '@enum_decl_string', |
| 66 | '@enum_decl_strings', |
| 67 | '@enum_has_attribute', |
| 68 | '@enum_name', |
| 69 | '@enum_names', |
| 70 | '@enum_type', |
| 71 | '@enum_type_string', |
| 72 | '@enum_type_strings', |
| 73 | '@enum_types', |
| 74 | '@enum_value', |
| 75 | '@enum_values', |
| 76 | '@expand_params', |
| 77 | '@expression', |
| 78 | '@files', |
| 79 | '@func_decl', |
| 80 | '@has_attribute', |
| 81 | '@include', |
| 82 | '@is_class_template', |
| 83 | '@macro', |
| 84 | '@match', |
| 85 | '@mauto', |
| 86 | '@member', |
| 87 | '@member_count', |
| 88 | '@member_decl_string', |
| 89 | '@member_decl_strings', |
| 90 | '@member_default', |
| 91 | '@member_has_attribute', |
| 92 | '@member_has_default', |
| 93 | '@member_name', |
| 94 | '@member_names', |
| 95 | '@member_offset', |
| 96 | '@member_offsets', |
| 97 | '@member_ptr', |
| 98 | '@member_ptrs', |
| 99 | '@member_type', |
| 100 | '@member_type_string', |
| 101 | '@member_type_strings', |
| 102 | '@member_types', |
| 103 | '@member_value', |
| 104 | '@member_values', |
| 105 | '@meta', |
| 106 | '@method_count', |
| 107 | '@method_name', |
| 108 | '@method_params', |
| 109 | '@method_type', |
| 110 | '@mtype', |
| 111 | '@mtypes', |
| 112 | '@mvoid', |
| 113 | '@op', |
| 114 | '@pack_nontype', |
| 115 | '@pack_type', |
| 116 | '@parse_expression', |
| 117 | '@puts', |
| 118 | '@range', |
| 119 | '@sfinae', |
| 120 | '@statements', |
| 121 | '@static_type', |
| 122 | '@string', |
| 123 | '@tattribute', |
| 124 | '@type_enum', |
| 125 | '@type_id', |
| 126 | '@type_name', |
| 127 | '@type_string', |
| 128 | ]); |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 129 | |
| 130 | // Hack to put `@...` keywords in place |
Mats Larsen | 4f9a34c | 2022-04-24 19:11:48 +0200 | [diff] [blame] | 131 | cppcircle.tokenizer.root.unshift([/@\w+/, {cases: {'@keywords': {token: 'keyword.$0'}}}]); |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 132 | |
| 133 | return cppcircle; |
| 134 | } |
| 135 | |
Mats Larsen | 4f9a34c | 2022-04-24 19:11:48 +0200 | [diff] [blame] | 136 | monaco.languages.register({id: 'cppcircle'}); |
Michał Cichoń | 3bce751 | 2021-07-26 04:26:00 +0200 | [diff] [blame] | 137 | monaco.languages.setLanguageConfiguration('cppcircle', cpp.conf); |
| 138 | monaco.languages.setMonarchTokensProvider('cppcircle', definition()); |
Mats Larsen | 9904a6e | 2021-10-12 16:11:56 +0200 | [diff] [blame] | 139 | |
| 140 | export {}; |