From f61677bbc3ae32cc460014cffe4d9ae9264291c5 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 20 Aug 2023 11:29:07 +0530 Subject: feat: function declaration --- src/eval.ts | 4 +++- src/parser.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/eval.ts b/src/eval.ts index 26b3df0..e421d7a 100644 --- a/src/eval.ts +++ b/src/eval.ts @@ -245,7 +245,9 @@ const getFunctions = ( return EvalValue.Void() }, - _: () => Promise.reject(new Error('not supposed to be here')), + func: async () => EvalValue.Lazy(args), + + _: () => Promise.reject(new Error(`Not implemented: ${name}`)), }) } diff --git a/src/parser.ts b/src/parser.ts index 732e32a..eeb9acf 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -108,6 +108,18 @@ const exprParser: P.Parser = P.or([ identifierExprParser, ]) +export const parseExpr = (input: string): Expr => { + return match(exprParser(input), { + Ok: ({ value, input }) => { + if (input) throw new Error(`Aaaaaa. Input left: ${input}`) + return value + }, + Err: e => { + throw e + }, + }) +} + const declarationParser = P.or([callExprParser, selectorExprParser]) const multiDeclarationParser = P.sepBy(declarationParser, whitespace) -- cgit v1.3.1