| Crates.io | tiscript |
| lib.rs | tiscript |
| version | 0.0.3 |
| created_at | 2024-07-27 12:55:13.309502+00 |
| updated_at | 2024-08-09 01:47:05.319459+00 |
| description | Turing-Incomplete TypeScript as a Configuration Language |
| homepage | |
| repository | https://github.com/gfx/tiscript |
| max_upload_size | |
| id | 1317270 |
| size | 213,859 |
TiScript is a configuration language designed to be intuitive and easy for humans and machines. It draws inspiration from TypeScript and JSON, offering the benefits of both:
TiScript is intentionally designed to be Turing incomplete. This means it focuses on defining configurations and is not intended for general programming tasks. However, since it's a subset of TypeScript, you can still leverage the TypeScript development toolkit for features like language services.
This is a work in progress. The current implementation is MVP and not intended to be used in production.
TiScript definition (it's strict subset of TypeScript):
// editor_config.ts
const LF = "\x0A";
export const tabSize = 4;
export const trimTrailingWhitespace = true;
export const endOfLine = LF;
export const encoding = "utf-8";
Currently, the only interface is a command called tiscript(1) (or cargo run on development).
$ cargo run ./editor_config.ts
the output is:
{
"tabSize": 4,
"trimTrailingWhitespace": true,
"endOfLine": "\n",
"encoding": "utf-8"
}
This library implements serde's Deserializer.
From a file:
use serde::{Deserialize, Serialize};
use tiscript::from_file;
// integrated to Serde
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct EditorConfig {
tabSize: i32,
trimTrailingWhitespace: bool,
endOfLine: String,
encoding: String,
}
fn main() {
let editorConfig: EditorConfig = from_file("./editor_config.ts").unwrap();
// or from_file_with_timeout(f, d) for untrusted code
println!("{:?}", editorConfig);
}
From an inline code:
use serde::{Deserialize, Serialize};
use tiscript::from_str;
// integrated to Serde
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct EditorConfig {
tabSize: i32,
trimTrailingWhitespace: bool,
endOfLine: String,
encoding: String,
}
fn main() {
let editorConfig: EditorConfig = from_str(r#"
const LF = "\x0A";
export const tabSize = 4;
export const trimTrailingWhitespace = true;
export const endOfLine = LF;
export const encoding = "utf-8";
"#).unwrap();
// or from_str_with_timeout(f, d) for untrusted code
println!("{:?}", editorConfig);
}
TBD
This is a list of features in ECMA-262 that are planned or implemented ("[x]" does not necessarily mean it's 100% compatible with TypeScript and ECMA-262):
exportexport defaultletconstif and elseundefined literalsnull literalsboolean literalsnumber literalsstring literalsstring literalsstring literalsbigint literals (actually 64-bit int)[0] and .["foo"]).foo)typeof operator+, -, *, /, %, **)~, &, |, ^, <<, >>, >>>)=, +=, -=, *=, /=, %=, **=, <<=, >>=, >>>=, &=, |=, ^=)==, !=, ===, !==, <, >, <=, >=)++, --)cond ? t : f)&&, ||, !)??)?.)class statementfor-of loopfor (with restrictions)while loop (with restrictions)do-while loop (with restrictions)Error, try-catch-finally, throw and so on)function keywordfunction*)importimportMath class methodsMath class propertiesString class methodsString instance methodsNumber class methodsNumber instance methodsTextEncoderIntl / ECMA-402atob and btoaThis is a list of features in TypeScript that are planned or implemented:
import type statement (but it does nothing so far)anyunknownneveras type assertionsatisfies type operatorinterface type statementtype type statementtypeof operator in type expressions!)This is a list of features that won't be implemented:
var declarationeval functionnew Function()RegExp and regular expression operatorsfor-in loopasync and awaitsymbolenumconst enumnamespaceNote that any features TiScript recognizes, but TypeScript compiler does not are invalid, but not vice versa. This is because TiScript is a strict subset of TypeScript.
If you'd like to develop this project, run UPDATE=1 cargo test to automatically generates *.stdout or *.stderr files in spec/.
This project is ensured to be built with --target=wasm32-wasi in CI. There's no test for WebAssembly though.
FUJI, Goro (gfx).
This project a fork of https://github.com/msakuta/ruscal, and thus much of the code comes from it.
This project is licensed under the ISC License - see the LICENSE file for details.