Interact with Compiler Explorer links using inline code directives.
Base'd on Matt Godbolt's code which can be found at here.
const {parseCode, displayURL} = require('compiler-explorer-directives');
const info = parseCode(`
///compiler=g83
///options+=-O0
#include <iostream>
int main() {
std::cout << "Hello CE!";
}`, cpp);
const url = displayURL(info);
parseCode(code, language, config)
Parses code according to directives and generates an info object which can then be passed to displayUrl
and compile
.
language
should be one of CE's support languages.
config
is optional, and should be an object with fields listed under Configuration.
displayUrl(info)
Generates a URL which opens CE with the code parsed by parseCode
.
compile(info)
Calls CE's Rest API to compile the code parsed by parseCode
.
Returns output from compiling and running the code (if enabled) on success, otherwise throws CompileError
with code
being the exit code and message
being the compiler's error message.
Use ///
directives to configure a specific code snippet. Every line starting with ///
, which is not mapped to one of the supported directives, is ignored.
Override default compiler.
Override default options.
Add to default options.
Use libraries in snippet.
Run the compiled output.
Disable execution in case runMain
is set, this snippet contains a main
function but execution is not wanted.
Always open on godbolt.com
even if useLocal
is set.
To configure the plugin pass a compilerExplorer
object to Reveal.initialize
with any of the following options:
Compiler to use when there's no compiler
directive. Defaults to g102
.
Compiler options to pass when there's no options
directive. Defaults to -O2 -march=haswell -Wall -Wextra -pedantic -Wno-unused-variable -Wno-unused-parameter
.
Whether to always run code with main
functions. Defaults to false
.
Whether to use a local running instance of Compiler Explorer (might speed up processing).
Port of local running Compiler Explorer, in case useLocal
is true
. Defaults to 10240
.
User defined directives. Needs to be an array of [regex, action]
pairs where action
is a function accepting matches
and info
with the regex
's matches and current info instance, respectively.