mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
Add basic support for Hook programming language (#4075)
* Add basic support for Hook programming language
This commit is contained in:
committed by
GitHub
parent
9391f0aa44
commit
c2e9aabfd7
4
.github/labeler.yml
vendored
4
.github/labeler.yml
vendored
@@ -75,6 +75,10 @@ lang-hlsl:
|
||||
- lib/compilers/hlsl.js
|
||||
- etc/config/hlsl.*.properties
|
||||
- static/modes/hlsl-mode.ts
|
||||
lang-hook:
|
||||
- lib/compilers/hook.ts
|
||||
- etc/config/hook.*.properties
|
||||
- static/modes/hook-mode.ts
|
||||
lang-jakt:
|
||||
- lib/compilers/jakt.ts
|
||||
- etc/config/jakt.*.properties
|
||||
|
||||
@@ -122,3 +122,4 @@ From oldest to newest contributor, we would like to thank:
|
||||
- [Ross Smyth](https://github.com/RossSmyth)
|
||||
- [Mike Urbach](https://github.com/mikeurbach)
|
||||
- [J. Ryan Stinnett](https://github.com/jryans)
|
||||
- [Fábio S. V. Medeiros](https://github.com/fabiosvm)
|
||||
|
||||
21
etc/config/hook.amazon.properties
Normal file
21
etc/config/hook.amazon.properties
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
interpreted=true
|
||||
supportsBinary=false
|
||||
supportsExecute=true
|
||||
versionFlag=--version
|
||||
needsMulti=false
|
||||
|
||||
compilerType=hook
|
||||
compilers=&hook
|
||||
defaultCompiler=hook010
|
||||
|
||||
group.hook.compilers=hook010
|
||||
group.hook.groupName=Hook
|
||||
group.hook.isSemVer=true
|
||||
group.hook.baseName=Hook
|
||||
group.hook.licenseName=MIT
|
||||
group.hook.licenseLink=https://github.com/fabiosvm/hook-lang/blob/main/LICENSE
|
||||
|
||||
compiler.hook010.exe=/opt/compiler-explorer/hook-0.1.0/bin/hook
|
||||
compiler.hook010.semver=0.1.0
|
||||
|
||||
20
etc/config/hook.defaults.properties
Normal file
20
etc/config/hook.defaults.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
interpreted=true
|
||||
supportsBinary=false
|
||||
supportsExecute=true
|
||||
versionFlag=--version
|
||||
needsMulti=false
|
||||
|
||||
compilerType=hook
|
||||
compilers=&hook
|
||||
defaultCompiler=hook010def
|
||||
|
||||
group.hook.compilers=hook010def
|
||||
group.hook.groupName=Hook
|
||||
group.hook.isSemVer=true
|
||||
group.hook.baseName=Hook
|
||||
group.hook.licenseName=MIT
|
||||
group.hook.licenseLink=https://github.com/fabiosvm/hook-lang/blob/main/LICENSE
|
||||
|
||||
compiler.hook010def.exe=hook
|
||||
compiler.hook010def.semver=0.1.0
|
||||
3
examples/hook/default.hk
Normal file
3
examples/hook/default.hk
Normal file
@@ -0,0 +1,3 @@
|
||||
fn square(num) {
|
||||
return num * num;
|
||||
}
|
||||
@@ -58,6 +58,7 @@ export {GCCRSCompiler} from './gccrs';
|
||||
export {GolangCompiler} from './golang';
|
||||
export {HaskellCompiler} from './haskell';
|
||||
export {HLSLCompiler} from './hlsl';
|
||||
export {HookCompiler} from './hook';
|
||||
export {ISPCCompiler} from './ispc';
|
||||
export {JaktCompiler} from './jakt';
|
||||
export {JavaCompiler} from './java';
|
||||
|
||||
55
lib/compilers/hook.ts
Normal file
55
lib/compilers/hook.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2022, 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 path from 'path';
|
||||
|
||||
import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces';
|
||||
import {ParseFilters} from '../../types/features/filters.interfaces';
|
||||
import {BaseCompiler} from '../base-compiler';
|
||||
|
||||
export class HookCompiler extends BaseCompiler {
|
||||
static get key(): string {
|
||||
return 'hook';
|
||||
}
|
||||
|
||||
override optionsForFilter(filters: ParseFilters): string[] {
|
||||
return ['--dump'];
|
||||
}
|
||||
|
||||
override getOutputFilename(dirPath: string): string {
|
||||
return path.join(dirPath, 'example.out');
|
||||
}
|
||||
|
||||
override async runCompiler(
|
||||
compiler: string,
|
||||
options: string[],
|
||||
inputFilename: string,
|
||||
execOptions: ExecutionOptions,
|
||||
): Promise<CompilationResult> {
|
||||
const dirPath = path.dirname(inputFilename);
|
||||
const outputFilename = this.getOutputFilename(dirPath);
|
||||
options.push(outputFilename);
|
||||
return super.runCompiler(compiler, options, inputFilename, execOptions);
|
||||
}
|
||||
}
|
||||
@@ -350,6 +350,17 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
|
||||
previewFilter: null,
|
||||
monacoDisassembly: null,
|
||||
},
|
||||
hook: {
|
||||
name: 'Hook',
|
||||
monaco: 'hook',
|
||||
extensions: ['.hk', '.hook'],
|
||||
alias: [],
|
||||
logoUrl: null,
|
||||
logoUrlDark: null,
|
||||
formatter: null,
|
||||
previewFilter: null,
|
||||
monacoDisassembly: null,
|
||||
},
|
||||
ispc: {
|
||||
name: 'ispc',
|
||||
monaco: 'ispc',
|
||||
|
||||
@@ -43,6 +43,7 @@ import './fortran-mode';
|
||||
import './gccdump-rtl-gimple-mode';
|
||||
import './haskell-mode';
|
||||
import './hlsl-mode';
|
||||
import './hook-mode';
|
||||
import './ispc-mode';
|
||||
import './jakt-mode';
|
||||
import './llvm-ir-mode';
|
||||
|
||||
182
static/modes/hook-mode.ts
Normal file
182
static/modes/hook-mode.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
// Copyright (c) 2022, 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.
|
||||
|
||||
const monaco = require('monaco-editor');
|
||||
|
||||
function definition() {
|
||||
return {
|
||||
defaultToken: 'invalid',
|
||||
|
||||
keywords: [
|
||||
'as',
|
||||
'break',
|
||||
'continue',
|
||||
'del',
|
||||
'do',
|
||||
'else',
|
||||
'false',
|
||||
'fn',
|
||||
'for',
|
||||
'from',
|
||||
'if',
|
||||
'if!',
|
||||
'loop',
|
||||
'match',
|
||||
'mut',
|
||||
'nil',
|
||||
'return',
|
||||
'struct',
|
||||
'true',
|
||||
'use',
|
||||
'val',
|
||||
'while',
|
||||
'while!',
|
||||
],
|
||||
typeKeywords: [],
|
||||
operators: [
|
||||
'..',
|
||||
'.',
|
||||
'|=',
|
||||
'||',
|
||||
'|',
|
||||
'^=',
|
||||
'^',
|
||||
'&=',
|
||||
'&&',
|
||||
'&',
|
||||
'=>',
|
||||
'==',
|
||||
'=',
|
||||
'!=',
|
||||
'!',
|
||||
'>=',
|
||||
'>>=',
|
||||
'>>',
|
||||
'>',
|
||||
'<=',
|
||||
'<<=',
|
||||
'<<',
|
||||
'<',
|
||||
'+=',
|
||||
'++',
|
||||
'+',
|
||||
'-=',
|
||||
'--',
|
||||
'-',
|
||||
'*=',
|
||||
'*',
|
||||
'/=',
|
||||
'/',
|
||||
'~/=',
|
||||
'~/',
|
||||
'~',
|
||||
'%=',
|
||||
'%',
|
||||
],
|
||||
|
||||
symbols: /[=><!~?:&|+\-*/^%]+/,
|
||||
|
||||
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
||||
|
||||
tokenizer: {
|
||||
root: [
|
||||
// identifiers and keywords
|
||||
[
|
||||
/[a-z_$][\w$]*/,
|
||||
{
|
||||
cases: {
|
||||
'@typeKeywords': 'keyword',
|
||||
'@keywords': 'keyword',
|
||||
'@default': 'identifier',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
[/[A-Z][\w$]*/, 'type.identifier'], // to show class names nicely
|
||||
|
||||
// whitespace
|
||||
{include: '@whitespace'},
|
||||
|
||||
// delimiters and operators
|
||||
[/[{}()[\]]/, '@brackets'],
|
||||
[/[<>](?!@symbols)/, '@brackets'],
|
||||
[
|
||||
/@symbols/,
|
||||
{
|
||||
cases: {
|
||||
'@operators': 'operator',
|
||||
'@default': '',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
// numbers
|
||||
[/\d*\.\d+([eE][-+]?\d+)?[fFdD]?/, 'number.float'],
|
||||
[/0[xX][0-9a-fA-F_]*[0-9a-fA-F][Ll]?/, 'number.hex'],
|
||||
[/0o[0-7_]*[0-7][Ll]?/, 'number.octal'],
|
||||
[/0[bB][0-1_]*[0-1][Ll]?/, 'number.binary'],
|
||||
[/\d+/, 'number'],
|
||||
|
||||
// delimiter: after number because of .\d floats
|
||||
[/[;,.]/, 'delimiter'],
|
||||
|
||||
// strings
|
||||
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/c?\\\\.*$/, 'string'],
|
||||
[/c?"/, 'string', '@string'],
|
||||
|
||||
// characters
|
||||
[/'[^\\']'/, 'string'],
|
||||
[/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
|
||||
[/'/, 'string.invalid'],
|
||||
],
|
||||
|
||||
whitespace: [
|
||||
[/[ \r\n]+/, 'white'],
|
||||
[/\/\*/, 'comment', '@comment'],
|
||||
[/\/\+/, 'comment', '@comment'],
|
||||
[/\/\/.*$/, 'comment'],
|
||||
[/\t/, 'comment.invalid'],
|
||||
],
|
||||
|
||||
comment: [
|
||||
[/[^/*]+/, 'comment'],
|
||||
[/\/\*/, 'comment.invalid'],
|
||||
[/[/*]/, 'comment'],
|
||||
],
|
||||
|
||||
string: [
|
||||
[/[^\\"]+/, 'string'],
|
||||
[/@escapes/, 'string.escape'],
|
||||
[/\\./, 'string.escape.invalid'],
|
||||
[/"/, 'string', '@pop'],
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
monaco.languages.register({id: 'hook'});
|
||||
monaco.languages.setMonarchTokensProvider('hook', definition());
|
||||
|
||||
export {};
|
||||
@@ -49,6 +49,7 @@ export type LanguageKey =
|
||||
| 'go'
|
||||
| 'haskell'
|
||||
| 'hlsl'
|
||||
| 'hook'
|
||||
| 'ispc'
|
||||
| 'jakt'
|
||||
| 'java'
|
||||
|
||||
Reference in New Issue
Block a user