Skip to content

Commit

Permalink
feat: asynchornous loading of diagon module
Browse files Browse the repository at this point in the history
  • Loading branch information
elmouradiaminedev committed Feb 12, 2024
1 parent ae56fe0 commit 9d4cd37
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 374 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- name: "Checkout repository"
- name: Checkout repository
uses: actions/checkout@v4

- name: "Setup C++ Environment"
- name: Setup C++ Environment
uses: aminya/setup-cpp@v1
with:
compiler: llvm
Expand All @@ -28,24 +25,21 @@ jobs:
gcovr: "5.0"
opencppcoverage: false

- name: "Setup Java"
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
check-latest: true

- name: "Setup Emscripten"
- name: Setup Emscripten
uses: mymindstorm/setup-emsdk@v14

- name: "Install Linux Dependencies"
- name: Install Linux Dependencies
run: sudo apt install libboost-graph-dev uuid-dev

- name: "Setup Node.js"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install npm dependencies
run: npm install
Expand Down Expand Up @@ -86,9 +80,6 @@ jobs:

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm

- name: Install npm dependencies
run: npm install
Expand Down
Empty file removed docs/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion scripts/diagon/build-diagon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build_diagon_source() {
-DCMAKE_BUILD_TYPE:STRING=Release \
-DDIAGON_BUILD_TESTS:BOOL=OFF \
-DDIAGON_BUILD_TESTS_FUZZER:BOOL=OFF \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -Dmain=Noop -s WASM_ASYNC_COMPILATION=0"
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -Dmain=Noop -s MODULARIZE=1 -s SINGLE_FILE=1"
cmake --build "$BUILD_DIR"
}

Expand Down
236 changes: 23 additions & 213 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,221 +1,29 @@
import { TranslationTool } from "./lib/internal";
import { DiagonType, init } from "./translators";
import { FrameTranslationOptions } from "./translators/frame";
import {
GrammarTranslationOptions,
GrammarTranslationInputs,
GrammarTranslationOutputs,
GRAMMAR_TRANSLATION_INPUTS,
GRAMMAR_TRANSLATION_OUTPUTS,
} from "./translators/grammar";
import {
math,
MATH_TRANSLATION_STYLES,
MathTranslationOptions,
MathTranslationStyle,
MATH_TRANSLATION_STYLES,
} from "./translators/math";
import { sequence, SequenceTranslationOptions } from "./translators/sequence";
import {
tree,
TreeTranslationOptions,
TreeTranslationStyle,
TREE_TRANSLATION_STYLES,
} from "./translators/tree";
import { SequenceTranslationOptions } from "./translators/sequence";
import {
TABLE_TRANSLATION_STYLES,
TableTranslationOptions,
TableTranslationStyle,
TABLE_TRANSLATION_STYLES,
table,
} from "./translators/table";
import { TranslationTool } from "./lib/internal";
import {
GRAMMAR_TRANSLATION_INPUTS,
GRAMMAR_TRANSLATION_OUTPUTS,
GrammarTranslationInputs,
GrammarTranslationOptions,
GrammarTranslationOutputs,
grammar,
} from "./translators/grammar";
import { FrameTranslationOptions, frame } from "./translators/frame";
import { graphDAG } from "./translators/graph-dag";

type Translator = {
/**
* Translation function for mathematical expressions.
*
* @param expression - The expression to be translated.
* @param options - Options for translation.
* @returns The translated expression.
* @example
* const translatedMathExpression = translate.math("f(x) = 1 + x / (1 + x)", { style: "Unicode" });
* console.log(translatedMathExpression)
* // x
* // f(x) = 1 + ─────
* // 1 + x
*/
math: (expression: string, options?: MathTranslationOptions) => string;
/**
* Translation function for sequence expressions.
*
* @param expression - The expression to be translated.
* @param options - Options for translation.
* @returns The translated expression.
* @example
* const translatedSequenceExpression = translate.sequence("Alice -> Bob: Hello Bob!\nAlice <- Bob: Hello Alice!", { "asciiOnly": false })
* console.log(translatedSequenceExpression)
* // ┌─────┐ ┌───┐
* // │Alice│ │Bob│
* // └──┬──┘ └─┬─┘
* // │ │
* // │ Hello Bob! │
* // │───────────>│
* // │ │
* // │Hello Alice!│
* // │<───────────│
* // ┌──┴──┐ ┌─┴─┐
* // │Alice│ │Bob│
* // └─────┘ └───┘
*/
sequence: (
expression: string,
options?: SequenceTranslationOptions,
) => string;
/**
* Translation function for Tree expressions.
*
* @param expression - The tree expression to be translated.
* @param options - Options for tree translation.
* @returns The translated tree expression.
* @example
* const translatedTreeExpression = tree("Linux\n Android\n Debian\n Ubuntu\n Lubuntu\n Kubuntu\n Xubuntu\n Xubuntu\n Mint\n Centos\n Fedora", { style: "Unicode 2" });
* console.log(translatedTreeExpression)
* // Linux
* // ├──Android
* // ├──Debian
* // │ ├──Ubuntu
* // │ │ ├──Lubuntu
* // │ │ ├──Kubuntu
* // │ │ ├──Xubuntu
* // │ │ └──Xubuntu
* // │ └──Mint
* // ├──Centos
* // └──Fedora
*/
tree: (expression: string, options?: TreeTranslationOptions) => string;
/**
* Translation function for Table expressions.
*
* @param expression - The table expression to be translated.
* @param options - Options for table translation.
* @returns The translated table expression.
* @example
* const translatedTableExpression = tree("Column 1,Column 2,Column 3\nC++,Web,Assembly\nJavascript,CSS,HTML", { style: "Unicode double" });
* console.log(translatedTableExpression)
* // ╔══════════╦════════╦════════╗
* // ║Column 1 ║Column 2║Column 3║
* // ╠══════════╬════════╬════════╣
* // ║C++ ║Web ║Assembly║
* // ╠══════════╬════════╬════════╣
* // ║Javascript║CSS ║HTML ║
* // ╚══════════╩════════╩════════╝
*/
table: (expression: string, options?: TableTranslationOptions) => string;
/**
* Translation function for Grammar expressions.
*
* @param expression - The grammar expression to be translated.
* @param options - Options for grammar translation.
* @returns The translated grammar expression.
* @example
* const translatedGrammarExpression = grammar(`\nURL = domain [path] [attributes] [fragment]\n\ndomain = scheme "://" [credential] host [port] \n\nscheme = "http" / "https"\n\ncredential = username [":" password]"@"\n\nhost = 1*(subdomain ".") domain\n\nport = ":" number\n\npath = "/" \n\nattributes = "?" attribute-key-value *("&" attribute-key-value)\n\nattribute-key-pair = key ["=" value]\n`, { input: "abnf", output: "unicode" });
* console.log(translatedGrammarExpression)
* // URL:
* // ╭────>─────╮ ╭───────>────────╮ ╭──────>───────╮
* // │ │ │ │ │ │
* // │├── domain ──╯── path ──╰──╯── attributes ──╰──╯── fragment ──╰──┤│
* //
* // domain:
* // ╭───────>────────╮ ╭────>─────╮
* // │ │ │ │
* // │├── scheme ── "://" ──╯── credential ──╰── host ──╯── port ──╰──┤│
* //
* // scheme:
* // │├──╮── "http"/i ───╭──┤│
* // │ │
* // ╰── "https"/i ──╯
* //
* // credential:
* // ╭──────────>──────────╮
* // │ │
* // │├── username ──╯── ":" ── password ──╰── "@" ──┤│
* //
* // host:
* // │├──╭── subdomain ── "." ──╮── domain ──┤│
* // │ │
* // ╰──────────<───────────╯
* //
* // port:
* // │├── ":" ── number ──┤│
* //
* // path:
* // │├── "/" ──┤│
* //
* // attributes:
* // │├── "?" ──╭── attribute-key-value ──╮──┤│
* // │ │
* // ╰────────── "&" ──────────╯
* //
* // attribute-key-pair:
* // ╭────────>─────────╮
* // │ │
* // │├── key ──╯── "=" ── value ──╰──┤│
*/
grammar: (expression: string, options?: GrammarTranslationOptions) => string;
/**
* Translation function for Frame expressions.
*
* @param expression - The Frame expression to be translated.
* @param options - Options for frame translation.
* @returns The translated frame expression.
* @example
* const translatedFrameExpression = frame("#include <iostream>\nusing namespace std;\n\nint main() \n{\n cout << \"Hello, World!\";\n return 0;\n}", { asciiOnly: false, lineNumber: true });
* console.log(translatedFrameExpression)
* // ┌─┬────────────────────────────┐
* // │1│#include <iostream> │
* // │2│using namespace std; │
* // │3│ │
* // │4│int main() │
* // │5│{ │
* // │6│ cout << "Hello, World!";│
* // │7│ return 0; │
* // │8│} │
* // └─┴────────────────────────────┘
*/
frame: (expression: string, options?: FrameTranslationOptions) => string;
/**
* Translation function for DAG expressions.
*
* @param expression - The DAG expression to be translated.
* @param options - Options for DAG translation.
* @returns The translated DAG expression.
* @example
* const translatedDAGExpression = tree("socks -> shoes\nunderwear -> shoes\nunderwear -> pants\npants -> shoes\npants -> belt\nbelt -> jacket\nshirt -> belt\nshirt -> tie\ntie -> jacket\n" });
* console.log(translatedDAGExpression)
* // ┌─────┐┌─────────┐┌─────┐
* // │socks││underwear││shirt│
* // └┬────┘└┬─┬──────┘└┬─┬──┘
* // │ │┌▽─────┐ │┌▽───────┐
* // │ ││pants │ ││tie │
* // │ │└┬──┬──┘ │└┬───────┘
* // ┌▽──────▽─▽┐┌▽─────▽┐│
* // │shoes ││belt ││
* // └──────────┘└┬──────┘│
* // ┌────────────▽───────▽┐
* // │jacket │
* // └─────────────────────┘
*/
graphDAG: (expression: string) => string;
};

export const translate: Translator = {
math,
sequence,
table,
tree,
grammar,
frame,
graphDAG,
};
TREE_TRANSLATION_STYLES,
TreeTranslationOptions,
TreeTranslationStyle,
} from "./translators/tree";

export type {
MathTranslationOptions,
Expand All @@ -229,17 +37,19 @@ export type {
GrammarTranslationInputs,
GrammarTranslationOutputs,
FrameTranslationOptions,
DiagonType,
TranslationTool,
};

export {
MATH_TRANSLATION_STYLES,
TREE_TRANSLATION_STYLES,
TABLE_TRANSLATION_STYLES,
GRAMMAR_TRANSLATION_INPUTS,
GRAMMAR_TRANSLATION_OUTPUTS,
MATH_TRANSLATION_STYLES,
TABLE_TRANSLATION_STYLES,
TREE_TRANSLATION_STYLES,
};

export { init } from "./translators";
export default {
translate,
init,
};
Loading

0 comments on commit 9d4cd37

Please sign in to comment.