Parser
Parser class allows for parsing Fincontract descriptions, using
math.js
as its back-end.
Example:
import Parser from './fincontract-parser';
try {
const p = new Parser();
const expression = 'And(Give(Scale(11,One(USD))),Scale(10,One(EUR)))';
const desc = await p.parse(expression);
} catch (err) {
console.log(err);
}
Static Member Summary
Static Public Members | ||
public static get |
Time tolerance for |
|
public static get |
Expiration time for Fincontracts. |
Method Summary
Public Methods | ||
public |
Parses the Fincontract description expression and creates a FincNode description tree. |
|
public |
parseAddress(node: Object): String Parses address from an AST node. |
|
public |
parseScale(node: Object): String Parses scale from an AST node. |
|
public |
Traverses the Abstract Syntax Tree, that was output from |
Static Public Members
Public Methods
public parse(expression: String): FincNode source
Parses the Fincontract description expression and creates
a FincNode description tree. The expression has to be well-defined
meaning it cannot contain white characters, it has to have balanced
parentheses and contain only valid primitives (keywords) as described in
the paper. Keywords At
, Before
and After
are also supported.
https://orbilu.uni.lu/bitstream/10993/30975/1/Findel_2017-03-08-CR.pdf
Params:
Name | Type | Attribute | Description |
expression | String | well-defined Fincontract description |
public parseAddress(node: Object): String source
Parses address from an AST node. Address in form 0x....
has to be
processed further since math.js
interprets 0x...
as multiplication.
Params:
Name | Type | Attribute | Description |
node | Object | current AST node containing address |
public parseScale(node: Object): String source
Parses scale from an AST node. Negative scales have to be
processed further since math.js
interprets e.g. -4
as operation.
Params:
Name | Type | Attribute | Description |
node | Object | current AST node containing an integer scale factor |