1
0
forked from GitHub/gf-core

Move everything to javascript dir. Add jspgf API, test files for both Node and web.

This commit is contained in:
John J. Camilleri
2022-08-01 14:11:45 +02:00
parent 63828de0c2
commit 3d272ac053
10 changed files with 206 additions and 15 deletions

View File

@@ -0,0 +1,33 @@
const Module = require('./.libs/pgf.js');
const JSPGF = require('./jspgf.js')(Module);
const fs = require('fs');
const path = require('path');
Module.onRuntimeInitialized = () => {
// Read PGF path from args
if (process.argv.length > 2) {
const pgfPathHost = process.argv[2];
// Copy file into filesystem
const pgfPathFS = '/tmp/' + path.basename(pgfPathHost);
const rawPgf = fs.readFileSync(pgfPathHost);
Module.FS.writeFile(pgfPathFS, rawPgf);
// Read PGF
const pgf = JSPGF.readPGF(pgfPathFS);
// Print its name
console.log(JSPGF.abstractName(pgf));
}
// Parse expression
const expr = JSPGF.readExpr("Pred (Another (x f))");
// Show it
console.log(JSPGF.showExpr(expr));
// Print its arity
console.log('arity', JSPGF.arity(expr));
}