Skip to content
/ ikigai Public

πŸ“‘ – A simple parser with many possibilities

License

Notifications You must be signed in to change notification settings

aelxxs/ikigai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

82 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‘ 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: hello@alexis.kr
Website: https://alexis.kr

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

Acknowledgements

About

πŸ“‘ – A simple parser with many possibilities

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •