Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/node_modules
/.pnp
.pnp.js
/src/util/diproche/diprocheProgram
/diproche_source

# testing
/coverage
Expand Down
4 changes: 4 additions & 0 deletions package-lock.json

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

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@types/react-router-dom": "^4.3.4",
"@types/shortid": "0.0.29",
"bootstrap": "^4.3.1",
"diproche": "git+https://github.com/TimothyGillespie/Diproche-Prolog.git",
"jquery": "^3.4.1",
"lodash": "^4.17.15",
"node-sass": "^4.12.0",
Expand All @@ -20,11 +21,12 @@
"typescript": "3.4.2"
},
"scripts": {
"start": "react-scripts start",
"start": "npm run copy-diproche && react-scripts start",
"lint": "tslint --project .",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"build": "npm run copy-diproche && react-scripts build",
"test": "npm run copy-diproche && react-scripts test",
"eject": "react-scripts eject",
"copy-diproche": "shx cp -r ./node_modules/diproche/*.pl ./diproche_source"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
91 changes: 0 additions & 91 deletions src/util/prolog/builtInPredicates.ts

This file was deleted.

15 changes: 13 additions & 2 deletions src/util/prolog/fubar.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import "../../../swipl-wasm/swipl-web";
import { loadingFinishedPromise, query } from "./fubar";
import { loadingFinishedPromise, query, result } from "./fubar";

describe("Fubar", () => {
test("Tests bob is a man", async () => {
await loadingFinishedPromise;
query("man(bob).");
console.log("Inside the test");
console.log(result);
});

test("Tests frank is not a man", async () => {
await loadingFinishedPromise;
query("man(frank).");
query("diproche_fo([[wir,zeigen,[a,and,b],<->,[b,and,a]],[=>],[angenommen,a,and,b],[dann,a],[ferner,gilt,b],[damit,folgt,b,and,a],[qed],[abs],[<=],[nehmen,wir,jetzt,an,dass,b,and,a],[dann,folgt,a],[ausserdem,folgt,b],[also,gilt,nun,a,and,b],[qed],[damit,gilt,[a,and,b],<->,[c,and,a]]], X).");
console.log("Inside the test");
console.log(result);
});

test("Gets X", async () => {
await loadingFinishedPromise;
query("man(X).");
console.log("Inside the test");
console.log(result);
});
});
26 changes: 23 additions & 3 deletions src/util/prolog/fubar.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import fs from "fs";
import path from "path";
import { FS } from "../../../swipl-wasm/swipl-web";

// tslint:disable-next-line:prefer-const
let bindings: any = null;
let stdin = "";
let stdinPosition = 0;

const basePathDiproche: string = path.resolve(__dirname, "../../../diproche_source");
const diprocheFiles: string[] = fs.readdirSync(basePathDiproche);
const diprocheMap: Map<string, string> = new Map();
diprocheFiles.forEach((fileName: string) => {
const filePath: string = path.resolve(basePathDiproche, "./" + fileName);
diprocheMap.set(fileName.replace(".pl", ""), fs.readFileSync(filePath, "utf8"));
});

// var to make this variable global
// tslint:disable-next-line:no-var-keyword
export var result: string[] = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var is not making the variable global. export is.


// We use this to provide data into
// the SWI stdin.
const setStdin = (s: string) => {
Expand Down Expand Up @@ -98,6 +111,10 @@ function initialise(initBindings: any, initModule: any) {
);
}

function pushToResultArray(value: string): void {
result.push(value);
}

const swiplWasm = fs.readFileSync("swipl-wasm/swipl-web.wasm");
const swiplWasmData = fs.readFileSync("swipl-wasm/swipl-web.data").buffer;

Expand All @@ -106,7 +123,7 @@ const swiplWasmData = fs.readFileSync("swipl-wasm/swipl-web.data").buffer;
export const Module = {
noInitialRun: true,
locateFile: (url: string) => `swipl-wasm/${url}`,
print: console.log,
print: pushToResultArray,
printErr: console.error,
wasmBinary: swiplWasm,
preRun: [() => FS.init(readStdin)], // sets up stdin
Expand All @@ -118,8 +135,11 @@ export const Module = {
// Initialise SWI-Prolog.
initialise(bindings, Module);

FS.writeFile("/file.pl", "man(bob).");
query("consult('/file.pl').");
diprocheMap.forEach((programCode: string, fileName: string) => {
FS.writeFile("/" + fileName + ".pl", programCode);
});

query("consult('/diproche.pl').");

loadingFinished();
},
Expand Down
Loading