Ikigai is a fast and simple text parser - based off of JagTags's tag structure.
- UTF-16 Character Encoding Support
O(n)
Time Complexity Lexer- Uses 0 Regex
Strongly based off of Skya Bot's implementation. See Acknowledgements
for more information.
Might upload to NPM sometime later. Clone this repo and compile it yourself for now :D
import { parse } from '...';
const nodes = parse('Hello {user.name} {choose:π|π|π}!');
console.dir(nodes, { depth: null });
// Parser AST Output
// 0: Literal | 1: Variable | 2: Function | 3: Argument
[
{ type: 0, value: 'Hello ' },
{ type: 1, name: 'user.name' },
{ type: 0, value: ' ' },
{
type: 2,
name: 'choose',
args: [
{ type: 3, stems: [{ type: 0, value: 'π' }] },
{ type: 3, stems: [{ type: 0, value: 'π' }] },
{ type: 3, stems: [{ type: 0, value: 'π' }] },
],
},
{ type: 0, value: '!' },
];
ASTNode Interpretation is up to you to implement. Here's an example of what you could do:
import { ASTNode, ASTNodeType } from '...';
export function interpret(node: ASTNode | ASTNode[]): string {
if (Array.isArray(node)) {
let output = '';
for (const stem of node) {
output += interpret(stem);
}
return output;
}
switch (node.type) {
case ASTNodeType.Literal:
// π£
break;
case ASTNodeType.Argument:
// π
break;
case ASTNodeType.Function:
// π‘
break;
case ASTNodeType.Variable:
// π
break;
}
}
Distributed under the MIT License. See LICENSE
for more information.
Name: Alexis Vielma
Email: [email protected]
Website: https://alexis.kr
Project Link: https://github.com/aelxxs/ikigai