Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Specy committed Nov 7, 2024
1 parent 5ee6afe commit 318c449
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 53 deletions.
25 changes: 16 additions & 9 deletions bindings/typescript/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ import { execSync } from "child_process";
import fs from "fs/promises";

async function init() {
console.log("Starting build...")
await fs.unlink("./src/pkg/dotlr_bg.wasm.d.ts").catch(() => console.warn("No dotlr_bg.wasm.d.ts found"));
execSync('tsc', {stdio: 'inherit'});
await fs.cp("./src/pkg", "./dist/pkg", {recursive: true});
await fs.unlink("./dist/pkg/package.json").catch(() => console.warn("No package.json found"));
await fs.unlink("./dist/pkg/README.md").catch(() => console.warn("No README.md found"));
await fs.unlink("./dist/pkg/.gitignore").catch(() => console.warn("No .gitignore found"));
console.log("Build complete")

console.log("Starting build...");
await fs
.unlink("./src/pkg/dotlr_bg.wasm.d.ts")
.catch(() => console.warn("No dotlr_bg.wasm.d.ts found"));
execSync("tsc", { stdio: "inherit" });
await fs.cp("./src/pkg", "./dist/pkg", { recursive: true });
await fs
.unlink("./dist/pkg/package.json")
.catch(() => console.warn("No package.json found"));
await fs
.unlink("./dist/pkg/README.md")
.catch(() => console.warn("No README.md found"));
await fs
.unlink("./dist/pkg/.gitignore")
.catch(() => console.warn("No .gitignore found"));
console.log("Build complete");
}

init();
8 changes: 4 additions & 4 deletions bindings/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bindings/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "module",
"name": "dotlr",
"name": "@specy/dotlr",
"description": "An LR(1) parser generator and visualizer created for educational purposes.",
"keywords": [
"educational",
Expand All @@ -9,7 +9,7 @@
"parser-generator"
],
"license": "MIT OR Apache-2.0",
"version": "0.3.0",
"version": "0.3.15",
"main": "dist/index.js",
"exports": {
".": "./dist/index.js",
Expand Down
39 changes: 22 additions & 17 deletions bindings/typescript/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import type {
} from "./types";

export function stringifyToken(token: Token, noApostrophes = false) {
if (token.type === 'Eof') return "$"
if (token.type === 'Empty') return 'ε'
if (token.type === "Regex") return `%${token.value}`
if (token.type === "Constant") return noApostrophes ? token.value : `'${token.value}'`
return ""
if (token.type === "Eof") return "$";
if (token.type === "Empty") return "ε";
if (token.type === "Regex") return `%${token.value}`;
if (token.type === "Constant")
return noApostrophes ? token.value : `'${token.value}'`;
return "";
}

export function stringifyAtom(atom: AtomicPattern, noApostrophes = false) {
Expand Down Expand Up @@ -76,18 +77,22 @@ export function stringifyTreeStack(
});
}

export function stringifyTree(tree: Tree, indent: string = '', isLast: boolean = true): string {
const linePrefix = isLast ? '└─ ' : '├─ ';
let result = '';

if (tree.type === 'Terminal') {
const {token, slice} = tree.value;
if (token.type !== 'Eof' && token.type !== 'Empty') {
result += `${indent}${linePrefix}${token.value} [${slice}]\n`;
}
} else {
const {symbol, pattern} = tree.value;
result += `${indent}${linePrefix}${symbol}\n`;
export function stringifyTree(
tree: Tree,
indent: string = "",
isLast: boolean = true,
): string {
const linePrefix = isLast ? "└─ " : "├─ ";
let result = "";

if (tree.type === "Terminal") {
const { token, slice } = tree.value;
if (token.type !== "Eof" && token.type !== "Empty") {
result += `${indent}${linePrefix}${token.value} [${slice}]\n`;
}
} else {
const { symbol, pattern } = tree.value;
result += `${indent}${linePrefix}${symbol}\n`;

const newIndent = indent + (isLast ? " " : "│ ");
pattern.forEach((child, index) => {
Expand Down
25 changes: 4 additions & 21 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ impl Parser {
parser.check_conflicts_internal()
}
}
#[cfg(feature = "wasm")]
#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl Parser {
pub fn new_wasm(grammar: Grammar) -> Result<Parser, WasmParserError> {
Parser::lr(grammar).map_err(WasmParserError::new)
}
pub fn new_lalr_wasm(grammar: Grammar) -> Result<Parser, WasmParserError> {
Parser::lalr(grammar).map_err(WasmParserError::new)
}
}


impl Parser {
Expand Down Expand Up @@ -600,18 +590,11 @@ impl Parser {
#[cfg(feature = "wasm")]
#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl Parser {
pub fn new_wasm(grammar: Grammar) -> Result<Parser, JsValue> {
match Parser::lr(grammar) {
Ok(parser) => Ok(parser),
Err(error) => Err(serde_wasm_bindgen::to_value(&error)?),
}
pub fn new_wasm(grammar: Grammar) -> Result<Parser, WasmParserError> {
Parser::lr(grammar).map_err(WasmParserError::new)
}

pub fn new_lalr_wasm(grammar: Grammar) -> Result<Parser, JsValue> {
match Parser::lalr(grammar) {
Ok(parser) => Ok(parser),
Err(error) => Err(serde_wasm_bindgen::to_value(&error)?),
}
pub fn new_lalr_wasm(grammar: Grammar) -> Result<Parser, WasmParserError> {
Parser::lalr(grammar).map_err(WasmParserError::new)
}
}

Expand Down

0 comments on commit 318c449

Please sign in to comment.