mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
Updates to better support cppx-blue
With @hsutter
This commit is contained in:
40
examples/cppx_blue/Declarations.blue
Normal file
40
examples/cppx_blue/Declarations.blue
Normal file
@@ -0,0 +1,40 @@
|
||||
// Every declaration of a variable, function, or type is of the following form:
|
||||
// name : kind = definition
|
||||
// where the components mean (and most are optional):
|
||||
// name is the name being declared
|
||||
// kind is the kind of entity being declared
|
||||
// definition can be any expression, including a block expression
|
||||
|
||||
// For example, these are declaration statements (and definitions):
|
||||
|
||||
widget: type = int; // define a type
|
||||
|
||||
x: widget = 42; // a named variable
|
||||
|
||||
shape: type = { x: int; y: int; } // a named type
|
||||
|
||||
add: (x:_, y:_) = { return x+y; } // a named generic function
|
||||
|
||||
// add: (x, y) = x+y; // same, using defaults
|
||||
|
||||
// In expression scope, omit name to declare an unnamed entity. For example, these are declaration expressions:
|
||||
:widget = 42; // an unnamed (temporary) object expression
|
||||
|
||||
:type = { x: int; y: int; } // an unnamed type expression
|
||||
|
||||
//:(x, y) = x+y // an unnamed (lambda) function expression
|
||||
|
||||
// Note These : expressions have very low precedence, so a trailing ; is not needed when lambdas are passed as arguments.
|
||||
// A local variable declaration statement may omit kind or definition.
|
||||
// If kind is omitted, it is deduced as if specified _.
|
||||
// If = definition is omitted, name must be defined by initialization before use (see §3.4.1). For example:
|
||||
|
||||
y : int = 42; // y is an int with initial value 42
|
||||
|
||||
z : = 42; // z, the same, “_” is implicit default
|
||||
|
||||
w := 42; // same, stylistic convenience
|
||||
|
||||
// s: string; // declares s, unconstructed
|
||||
|
||||
// t = f(); // constructs t, definite first use
|
||||
@@ -1,8 +1,4 @@
|
||||
// Type your code here, or load an example.
|
||||
int square(int num) {
|
||||
return num * num;
|
||||
// Type your code here, or load an example
|
||||
square: (x: int) -> int = {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return square(2);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ export const languages = {
|
||||
},
|
||||
cppx_blue: {
|
||||
name: 'Cppx-Blue',
|
||||
monaco: 'cppp',
|
||||
monaco: 'cppx-blue',
|
||||
extensions: ['.blue', '.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'],
|
||||
alias: [],
|
||||
},
|
||||
|
||||
46
static/modes/cppx-blue-mode.js
Normal file
46
static/modes/cppx-blue-mode.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2018, 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.
|
||||
|
||||
'use strict';
|
||||
var $ = require('jquery');
|
||||
var monaco = require('monaco-editor');
|
||||
var cpp = require('monaco-editor/esm/vs/basic-languages/cpp/cpp');
|
||||
var cppp = require('./cppp-mode');
|
||||
|
||||
function definition() {
|
||||
var cppx_blue = $.extend(true, {}, cppp); // deep copy
|
||||
cppx_blue.tokenPostfix = '.cppx-blue';
|
||||
|
||||
// add the 'type' keyword
|
||||
cppx_blue.keywords.push('type');
|
||||
|
||||
// pick up 'identifier:' as a definition.
|
||||
cppx_blue.tokenizer.root.unshift([/[a-zA-Z_]\w*\s*:/, 'identifier.definition']);
|
||||
|
||||
return cppx_blue;
|
||||
}
|
||||
|
||||
monaco.languages.register({id: 'cppx-blue'});
|
||||
monaco.languages.setLanguageConfiguration('cppx-blue', cpp.conf);
|
||||
monaco.languages.setMonarchTokensProvider('cppx-blue', definition());
|
||||
@@ -39,6 +39,7 @@ var monacoConfig = require('../monaco-config');
|
||||
var TomSelect = require('tom-select');
|
||||
require('../modes/cppp-mode');
|
||||
require('../modes/cppx-gold-mode');
|
||||
require('../modes/cppx-blue-mode');
|
||||
require('../modes/d-mode');
|
||||
require('../modes/ispc-mode');
|
||||
require('../modes/llvm-ir-mode');
|
||||
|
||||
@@ -32,17 +32,33 @@ var themes = {
|
||||
id: 'default',
|
||||
name: 'Light',
|
||||
'main-color': '#f2f2f2',
|
||||
monaco: 'vs', // Optional field
|
||||
monaco: 'ce',
|
||||
},
|
||||
dark: {
|
||||
path: 'dark',
|
||||
id: 'dark',
|
||||
name: 'Dark',
|
||||
'main-color': '#333333',
|
||||
monaco: 'vs-dark',
|
||||
monaco: 'ce-dark',
|
||||
},
|
||||
};
|
||||
|
||||
monaco.editor.defineTheme('ce', {
|
||||
base: 'vs',
|
||||
inherit: true,
|
||||
rules: [
|
||||
{ token: 'identifier.definition.cppx-blue', foreground: '004400', fontStyle: 'bold' },
|
||||
],
|
||||
});
|
||||
|
||||
monaco.editor.defineTheme('ce-dark', {
|
||||
base: 'vs-dark',
|
||||
inherit: true,
|
||||
rules: [
|
||||
{ token: 'identifier.definition.cppx-blue', foreground: 'bbccbb', fontStyle: 'bold' },
|
||||
],
|
||||
});
|
||||
|
||||
function Themer(eventHub, initialSettings) {
|
||||
this.currentTheme = null;
|
||||
this.eventHub = eventHub;
|
||||
|
||||
Reference in New Issue
Block a user