There may be two possible uses of Symbolverse regarding its installation: Javascript API access or command line access. In this document we cover both use cases.
Symbolverse may expose its functionality through javascript API (Application Programming Interface), both in browser and in Node.js.
To access the API from Node.js, install this package: npm i @tearflake/symbolverse
, and include the following line in your code:
const Rewriter = require('@tearflake/symbolverse');
To access the API from browser, clone this repository from GitHub: git clone https://github.com/tearflake/symbolverse
, and include the following line in your code:
<script src="path-to-symbolverse-package/symbolverse.js"></script>
Below, regardless of accessing from Node.js or browser, use the API as:
var strRules = `
(
REWRITE
(
RULE
(READ (EXP (\\hello \\machine)))
(WRITE (EXP (\\hello \\world) ))
)
)
`;
var arrRules = await Rewriter.compile (strRules);
if (!arrRules.err) {
var strInput = `
(hello machine)
`;
var arrOutput = Rewriter.rewrite (arrRules, strInput);
if (!arrOutput.err) {
console.log (Rewriter.stringify (arrOutput));
}
}
Along with Rewriter.compile (...)
function, we also have Rewriter.compileFile (...)
function available. The only difference is that compileFile
reads a file from a server, and it enables possible use of file fetching system within the code files.
Symbolverse functions as a standalone executable operating on files. To build the executables from source code, do the following:
sudo npm install -g pkg
on Linux, or npm install -g pkg
on Windowsgit clone https://github.com/tearflake/symbolverse
cd symbolverse
pkg . --out-path bin/
./bin/
directoryExecutables run from command prompt, and take three parameters: rules-file, input-file, and output-file. Rules-file and input-file are mandatory, but if we omit the output-file parameter, output is then redirected to the terminal.