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

https://github.com/testingrequired/reqlang-expr-tspl

A toy transpiler to convert reqlang-expr expressions to Typescript.
https://github.com/testingrequired/reqlang-expr-tspl

transpiler

Last synced: 6 months ago
JSON representation

A toy transpiler to convert reqlang-expr expressions to Typescript.

Awesome Lists containing this project

README

          

# reqlang-expr-tspl

A toy transpiler to convert [reqlang-expr](https://github.com/testingrequired/reqlang-expr) expressions to Typescript.

This is not a serious project.

## Example

```
(id `foo`)
```

transpiles to

```typescript
// This file was generated by reqlang-expr-tspl
import * as ReqlangExpr from "@reqlang-expr-tspl/runtime";

const expression: ReqlangExpr.Expression = (ctx) => {
return ctx.builtins.id("foo");
};

const args = ReqlangExpr.getArgs();

const env = new ReqlangExpr.Env(
args.vars,
args.prompts,
args.secrets,
args.client
);

const context = {
env,
builtins: ReqlangExpr.builtinFns,
};

const value = expression(context);

console.log(JSON.stringify(value));
```

See: [@reqlang-expr-tspl/runtime](./src/index.ts)

## Running Transpiled Files

```bash
reqlang-expr-tspl spec/greeting_name.expr > spec/greeting_name.expr.ts

npx tsx spec/greeting_name.expr.ts \
--var 'greeting=Hello' \
--prompt 'name=World'

# "Hello World"
```

## Development

- [Rust](https://www.rust-lang.org/)
- [Node](https://nodejs.org/)
- [just](https://just.systems/)

## Running CLI

The `reqlang-expr-tspl.sh` script helps run the latest development version of the CLI.

```bash
./reqlang-expr-tspl.sh spec/greeting_name.expr > spec/greeting_name.expr.ts

npx tsx spec/greeting_name.expr.ts \
--var 'greeting=Hello' \
--prompt 'name=World'

# "Hello World"
```

### Tests

[![Verify](https://github.com/testingrequired/reqlang-expr-tspl/actions/workflows/verify.yml/badge.svg)](https://github.com/testingrequired/reqlang-expr-tspl/actions/workflows/verify.yml)

The [spec](./spec/) directory has several input `*.expr` with corrosponding `*.expr.ts` expected generated code.

- `cargo test` Transpiles the `*.expr` files and checks the `*.expr.ts` files for equality.
- `npm run test` Runs the `*.expr.ts` files using `npx tsx` and compares results against `*.expr.ts.interpreted` files
- `npm run check` Typechecks the `*.expr.ts` files
- `just test` Runs all tests