blob: 60561d6edd163dafc999d911c6fc5258c38a4720 [file] [log] [blame] [raw]
Michał Cichoń3bce7512021-07-26 04:26:00 +02001// 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 Larsen1f5fbe02022-08-07 11:58:16 +020025import $ from 'jquery';
26
Rubén Rincón Blanco42c7b2b2022-02-03 18:04:50 +010027const monaco = require('monaco-editor');
28const cpp = require('monaco-editor/esm/vs/basic-languages/cpp/cpp');
29const cppp = require('./cppp-mode');
Michał Cichoń3bce7512021-07-26 04:26:00 +020030
Matt Godbolt8172d952021-07-25 21:40:45 -050031// circle is c++ with a few extra '@'-prefixed keywords.
Michał Cichoń3bce7512021-07-26 04:26:00 +020032
33function definition() {
Rubén Rincón Blanco42c7b2b2022-02-03 18:04:50 +010034 const cppcircle = $.extend(true, {}, cppp); // deep copy
Michał Cichoń3bce7512021-07-26 04:26:00 +020035
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 Blanco42c7b2b2022-02-03 18:04:50 +010039 for (let i = 0; i < keywords.length; ++i) {
Michał Cichoń3bce7512021-07-26 04:26:00 +020040 cppcircle.keywords.push(keywords[i]);
41 }
42 }
43
Mats Larsen4f9a34c2022-04-24 19:11:48 +020044 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ń3bce7512021-07-26 04:26:00 +0200129
130 // Hack to put `@...` keywords in place
Mats Larsen4f9a34c2022-04-24 19:11:48 +0200131 cppcircle.tokenizer.root.unshift([/@\w+/, {cases: {'@keywords': {token: 'keyword.$0'}}}]);
Michał Cichoń3bce7512021-07-26 04:26:00 +0200132
133 return cppcircle;
134}
135
Mats Larsen4f9a34c2022-04-24 19:11:48 +0200136monaco.languages.register({id: 'cppcircle'});
Michał Cichoń3bce7512021-07-26 04:26:00 +0200137monaco.languages.setLanguageConfiguration('cppcircle', cpp.conf);
138monaco.languages.setMonarchTokensProvider('cppcircle', definition());
Mats Larsen9904a6e2021-10-12 16:11:56 +0200139
140export {};