Skip to content

Latest commit

Β 

History

History
99 lines (72 loc) Β· 2.02 KB

README.md

File metadata and controls

99 lines (72 loc) Β· 2.02 KB

πŸ“‘ Ikigai

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.

Built With

Installation

Might upload to NPM sometime later. Clone this repo and compile it yourself for now :D

Usage

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;
	}
}

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Name: Alexis Vielma
Email: [email protected]
Website: https://alexis.kr

Project Link: https://github.com/aelxxs/ikigai

Acknowledgements