Tagscript
Parsers

Parsers

Parsers are used to parse a tag and return a value based on the tag. You can use builtin parsers or write your own parser.

	import { Interpreter, RandomParser, RangeParser, FiftyFiftyParser, IfStatementParser, SliceParser } from 'tagscript';
	const ts = new Interpreter(new SliceParser(), new FiftyFiftyParser(), new RandomParser(), new IfStatementParser());

Builtin Parsers

Following is the list of builtin parsers:

Custom Parser

You can write your own parsers by implementing IParser interface.

	import { BaseParser, type Context, type IParser } from 'tagscript';
 
	export class FetchParser extends BaseParser implements IParser {
		public constructor() {
			super(['fetch'], false, true);
		}
 
		public parse(ctx: Context) {
			return fetch(ctx.tag.payload!.trim()).then((res) => res.text());
		}
	}