Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pakut2/w-format

Repository files navigation

W Format

Warning

This software has no use.

Transpile Javascript to Whitespace. Format Javascript/Typescript files according to the generated Whitespace, combining two different programs into a single source file.

Requirements

  • Go ver. 1.24.4 or newer

Quickstart

make run-example

After running, a new file will be generated under ./examples/output.ts. The result takes the source Javascript file and transpiles it to Whitespace. Afterwards, the target file is formatted to include the generated Whitespace instructions, creating the final output file.

This results in a single source file, running the same program while interpreted as different programming languages.

Typescript result can be executed with:

node --experimental-strip-types examples/output.ts

Whitespace can be executed using an online Whitespace interpreter.

Options

Display available options:

go run cmd/jsWhitespaceFormatter/main.go -h

Print transpiled Whitespace to standard output:

go run cmd/jsWhitespaceFormatter/main.go -source-file=<js-file-path>

Save transpiled Whitespace to file:

go run cmd/jsWhitespaceFormatter/main.go -source-file=<js-file-path> -output-file=<output-file-path>

Format file with transpiled Whitespace, print result to standard output:

go run cmd/jsWhitespaceFormatter/main.go -source-file=<js-file-path> -format-file<format-file-path>

Save file formatted with transpiled Whitespace:

go run cmd/jsWhitespaceFormatter/main.go -source-file=<js-file-path> -format-file<format-file-path> -output-file=<output-file-path>

Supported syntax

Not all Javascript instructions are supported by the transpiler. The covered subset includes:

  • Literal types:

    • Number: integers only
    • String
    • Boolean
  • Variable declarations using let:

let a = 42;
let b = "Hello World";
let c = true;
  • Number and Boolean variable reassignments:
let a = 42;
a = 69;
  • Printing to standard output with console.log:
console.log(42, "Hello World", true);
  • Arithmetic/logic operations:
    • +
    • -
    • *
    • /
    • %
    • ++
    • --
    • &&
    • ||
    • !
    • ===
    • !==
    • <
    • <=
    • >
    • >=
console.log(2 + 2 * 2);
  • String concatenation:
console.log("Hello" + "World");
  • if / if/else statements:
if (2 > 1) {
    console.log(true);
}
  • C-style for loops:
for (let i = 0; i < 10; i++) {
    if (i === 8) {
        break;
    }
  
    if (i % 2 === 0) {
        continue;
    }
    
    console.log(i);
}

About

JS -> Whitespace transpiler & formatter

Resources

Stars

Watchers

Forks