Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nathsou/explang

Generic React component to explore any programming language
https://github.com/nathsou/explang

Last synced: about 2 months ago
JSON representation

Generic React component to explore any programming language

Awesome Lists containing this project

README

        

# ExpLang

A generic React component to create playgrounds to explore any programming language.

## Usage

Add the following peer dependencies to your `package.json`'s devDependencies :

```json
"@geoffcox/react-splitter": "^2.1.0",
"ace-builds": "^1.4.12",
"react-ace": "^9.4.0"
```

```typescript
import { Playground, ButtonActions, Samples } from 'explang';

// create as many actions as needed, they will be turned into buttons in the top bar
// here we create two buttons to run and disassemble a piece of code
const actions: ButtonActions = {
Run: async (code, setOutput) => {
setOutput('running...');
const res = await compile(code);

if (res.isSuccess) {
setOutput(await run(res.output));
} else {
setOutput(`Error: ${res.error}`);
}
},
Disassemble: async (code, setOutput) => {
setOutput(await disassemble(code));
},
};

const samples: Samples = {
'Fibonacci': `fn fib(n: usize) { ... }`,
'Factorial': `fn fact(n: usize) { ... }`,
};

export const App = () => (

);
```

## Screenshot

![res/yolang-playground.png](res/yolang-playground.png)