Files
compiler-explorer/static/modes/cppp-mode.ts
T

54 lines
2.9 KiB
TypeScript

// Copyright (c) 2021, Compiler Explorer Authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import * as monaco from 'monaco-editor';
import { conf as cppConfig, language as cppMode, CppModeProps } from 'monaco-editor/esm/vs/basic-languages/cpp/cpp';
import { LanguageConfigProducer, LanguageDefinitionProducer } from './modes.interfaces';
import {createLanguageMode} from './modes';
const KEYWORDS_TO_REMOVE = ['abstract', 'amp', 'array', 'cpu', 'delegate', 'each', 'event', 'finally', 'gcnew',
'generic', 'in', 'initonly', 'interface', 'interior_ptr', 'internal', 'literal', 'partial', 'pascal',
'pin_ptr', 'property', 'ref', 'restrict', 'safe_cast', 'sealed', 'title_static', 'where'];
const KEYWORDS_TO_ADD = ['alignas', 'alignof', 'and', 'and_eq', 'asm', 'bitand', 'bitor', 'char8_t', 'char16_t',
'char32_t', 'compl', 'concept', 'consteval', 'constinit', 'co_await', 'co_return', 'co_yield', 'not', 'not_eq',
'or', 'or_eq', 'requires', 'xor', 'xor_eq'];
export interface CpppModeProps extends CppModeProps {}
// We need to create a new definition for cpp so we can remove invalid keywords
export const createCpppMode: LanguageDefinitionProducer<CpppModeProps> = createLanguageMode(() => cppMode, (cpp) => ({
...cpp,
keywords: cpp.keywords
.filter((keyword) => !KEYWORDS_TO_REMOVE.includes(keyword))
.concat(KEYWORDS_TO_ADD),
}));
export const createCpppConfig: LanguageConfigProducer = () => cppConfig;
monaco.languages.register({id: 'cppp'});
monaco.languages.setLanguageConfiguration('cppp', createCpppConfig());
monaco.languages.setMonarchTokensProvider('cppp', createCpppMode());