summaryrefslogtreecommitdiff
path: root/src/interpreter/parser.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-03 14:20:36 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-03 14:22:51 -0700
commite2e74df94fcdd2f3165e035fc00c98573f0b40d8 (patch)
tree362943ba180b3ba0298473855e2622f7560c84aa /src/interpreter/parser.ts
parent4233aca561b5650924f3cc4232cfd294d706c863 (diff)
downloadthe-abstraction-engine-e2e74df94fcdd2f3165e035fc00c98573f0b40d8.tar.gz
the-abstraction-engine-e2e74df94fcdd2f3165e035fc00c98573f0b40d8.zip
add parser
Diffstat (limited to 'src/interpreter/parser.ts')
-rw-r--r--src/interpreter/parser.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/interpreter/parser.ts b/src/interpreter/parser.ts
new file mode 100644
index 0000000..ea07796
--- /dev/null
+++ b/src/interpreter/parser.ts
@@ -0,0 +1,35 @@
+import peggyParser from "./PeggyParser.js";
+
+export type Application = {
+ application: {
+ left: LambdaTerm;
+ args: Array<LambdaTerm>;
+ };
+};
+
+export type Abstraction = {
+ abstraction: {
+ param: Variable;
+ body: LambdaTerm;
+ };
+};
+
+export type Variable = string;
+
+export type LambdaTerm = Application | Abstraction | Variable;
+
+export const isApplication = (term: LambdaTerm): term is Application => {
+ return (term as Application).application !== undefined;
+};
+
+export const isAbstraction = (term: LambdaTerm): term is Abstraction => {
+ return (term as Abstraction).abstraction !== undefined;
+};
+
+export const isVariable = (term: LambdaTerm): term is Variable => {
+ return typeof term === "string";
+};
+
+export const parse = (term: string) => {
+ return peggyParser.parse(term, { library: true });
+};