Updates to better support cppx-blue

With @hsutter
This commit is contained in:
Matt Godbolt
2021-06-25 17:23:51 -05:00
parent 58ebc8d5e8
commit 8c2bed4819
6 changed files with 109 additions and 10 deletions

View 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

View File

@@ -1,8 +1,4 @@
// Type your code here, or load an example. // Type your code here, or load an example
int square(int num) { square: (x: int) -> int = {
return num * num; return x * x;
} }
int main() {
return square(2);
}

View File

@@ -77,7 +77,7 @@ export const languages = {
}, },
cppx_blue: { cppx_blue: {
name: 'Cppx-Blue', name: 'Cppx-Blue',
monaco: 'cppp', monaco: 'cppx-blue',
extensions: ['.blue', '.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'], extensions: ['.blue', '.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'],
alias: [], alias: [],
}, },

View 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());

View File

@@ -39,6 +39,7 @@ var monacoConfig = require('../monaco-config');
var TomSelect = require('tom-select'); var TomSelect = require('tom-select');
require('../modes/cppp-mode'); require('../modes/cppp-mode');
require('../modes/cppx-gold-mode'); require('../modes/cppx-gold-mode');
require('../modes/cppx-blue-mode');
require('../modes/d-mode'); require('../modes/d-mode');
require('../modes/ispc-mode'); require('../modes/ispc-mode');
require('../modes/llvm-ir-mode'); require('../modes/llvm-ir-mode');

View File

@@ -32,17 +32,33 @@ var themes = {
id: 'default', id: 'default',
name: 'Light', name: 'Light',
'main-color': '#f2f2f2', 'main-color': '#f2f2f2',
monaco: 'vs', // Optional field monaco: 'ce',
}, },
dark: { dark: {
path: 'dark', path: 'dark',
id: 'dark', id: 'dark',
name: 'Dark', name: 'Dark',
'main-color': '#333333', '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) { function Themer(eventHub, initialSettings) {
this.currentTheme = null; this.currentTheme = null;
this.eventHub = eventHub; this.eventHub = eventHub;